ommlds 0.0.0.dev463__py3-none-any.whl → 0.0.0.dev465__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ommlds might be problematic. Click here for more details.
- ommlds/.omlish-manifests.json +2 -2
- ommlds/cli/inject.py +14 -32
- ommlds/cli/main.py +34 -59
- ommlds/cli/sessions/{chat2 → chat}/backends/catalog.py +5 -5
- ommlds/cli/sessions/chat/backends/inject.py +37 -0
- ommlds/cli/sessions/chat/backends/injection.py +16 -0
- ommlds/cli/sessions/{chat2 → chat}/backends/types.py +3 -3
- ommlds/cli/sessions/chat/chat/ai/inject.py +78 -0
- ommlds/cli/sessions/chat/chat/ai/injection.py +14 -0
- ommlds/cli/sessions/{chat2 → chat}/chat/ai/rendering.py +13 -10
- ommlds/cli/sessions/chat/chat/ai/services.py +81 -0
- ommlds/cli/sessions/chat/chat/ai/tools.py +44 -0
- ommlds/cli/sessions/{chat2 → chat}/chat/ai/types.py +5 -5
- ommlds/cli/sessions/chat/chat/state/inject.py +40 -0
- ommlds/cli/sessions/{chat2 → chat}/chat/state/inmemory.py +1 -1
- ommlds/cli/sessions/{chat2 → chat}/chat/state/storage.py +2 -2
- ommlds/cli/sessions/{chat2 → chat}/chat/state/types.py +1 -1
- ommlds/cli/sessions/chat/chat/user/inject.py +61 -0
- ommlds/cli/sessions/{chat2 → chat}/chat/user/interactive.py +1 -1
- ommlds/cli/sessions/{chat2 → chat}/chat/user/oneshot.py +1 -1
- ommlds/cli/sessions/{chat2 → chat}/chat/user/types.py +1 -1
- ommlds/cli/sessions/{chat2 → chat}/configs.py +4 -1
- ommlds/cli/sessions/{chat2 → chat}/content/messages.py +6 -2
- ommlds/cli/sessions/{chat2 → chat}/content/strings.py +2 -2
- ommlds/cli/sessions/{chat2 → chat}/driver.py +2 -2
- ommlds/cli/sessions/chat/inject.py +47 -63
- ommlds/cli/sessions/chat/phases/inject.py +27 -0
- ommlds/cli/sessions/chat/phases/injection.py +14 -0
- ommlds/cli/sessions/{chat2/phases.py → chat/phases/manager.py} +2 -28
- ommlds/cli/sessions/chat/phases/types.py +29 -0
- ommlds/cli/sessions/chat/rendering/inject.py +32 -0
- ommlds/cli/sessions/{chat2 → chat}/rendering/markdown.py +2 -2
- ommlds/cli/sessions/{chat2 → chat}/rendering/raw.py +6 -6
- ommlds/cli/sessions/{chat2 → chat}/rendering/types.py +1 -1
- ommlds/cli/sessions/{chat2 → chat}/session.py +1 -1
- ommlds/cli/sessions/{chat2 → chat}/tools/confirmation.py +4 -4
- ommlds/cli/sessions/{chat2 → chat}/tools/execution.py +18 -5
- ommlds/cli/sessions/chat/tools/inject.py +145 -0
- ommlds/cli/sessions/chat/tools/injection.py +29 -0
- ommlds/cli/sessions/chat/tools/rendering.py +58 -0
- ommlds/cli/{tools → sessions/chat/tools}/weather.py +1 -1
- ommlds/cli/sessions/completion/configs.py +21 -0
- ommlds/cli/sessions/completion/inject.py +28 -0
- ommlds/cli/sessions/completion/{completion.py → session.py} +4 -9
- ommlds/cli/sessions/embedding/configs.py +21 -0
- ommlds/cli/sessions/embedding/inject.py +28 -0
- ommlds/cli/sessions/embedding/{embedding.py → session.py} +4 -9
- ommlds/cli/sessions/inject.py +27 -15
- ommlds/cli/state/inject.py +28 -0
- ommlds/minichain/backends/impls/anthropic/chat.py +4 -61
- ommlds/minichain/backends/impls/anthropic/protocol.py +109 -0
- ommlds/minichain/backends/impls/anthropic/stream.py +17 -17
- {ommlds-0.0.0.dev463.dist-info → ommlds-0.0.0.dev465.dist-info}/METADATA +3 -3
- {ommlds-0.0.0.dev463.dist-info → ommlds-0.0.0.dev465.dist-info}/RECORD +69 -60
- ommlds/cli/sessions/chat/base.py +0 -42
- ommlds/cli/sessions/chat/code.py +0 -125
- ommlds/cli/sessions/chat/interactive.py +0 -70
- ommlds/cli/sessions/chat/printing.py +0 -126
- ommlds/cli/sessions/chat/prompt.py +0 -161
- ommlds/cli/sessions/chat/state.py +0 -110
- ommlds/cli/sessions/chat/tools.py +0 -97
- ommlds/cli/sessions/chat2/_inject.py +0 -105
- ommlds/cli/sessions/chat2/chat/ai/services.py +0 -70
- ommlds/cli/sessions/chat2/inject.py +0 -143
- ommlds/cli/tools/config.py +0 -14
- ommlds/cli/tools/inject.py +0 -75
- /ommlds/cli/sessions/{chat2 → chat/backends}/__init__.py +0 -0
- /ommlds/cli/sessions/{chat2/backends → chat/chat}/__init__.py +0 -0
- /ommlds/cli/sessions/{chat2/chat → chat/chat/ai}/__init__.py +0 -0
- /ommlds/cli/sessions/{chat2/chat/ai → chat/chat/state}/__init__.py +0 -0
- /ommlds/cli/sessions/{chat2/chat/state → chat/chat/user}/__init__.py +0 -0
- /ommlds/cli/sessions/{chat2/chat/user → chat/content}/__init__.py +0 -0
- /ommlds/cli/sessions/{chat2/content → chat/phases}/__init__.py +0 -0
- /ommlds/cli/sessions/{chat2 → chat}/rendering/__init__.py +0 -0
- /ommlds/cli/sessions/{chat2 → chat}/tools/__init__.py +0 -0
- /ommlds/cli/{tools → state}/__init__.py +0 -0
- /ommlds/cli/{state.py → state/storage.py} +0 -0
- {ommlds-0.0.0.dev463.dist-info → ommlds-0.0.0.dev465.dist-info}/WHEEL +0 -0
- {ommlds-0.0.0.dev463.dist-info → ommlds-0.0.0.dev465.dist-info}/entry_points.txt +0 -0
- {ommlds-0.0.0.dev463.dist-info → ommlds-0.0.0.dev465.dist-info}/licenses/LICENSE +0 -0
- {ommlds-0.0.0.dev463.dist-info → ommlds-0.0.0.dev465.dist-info}/top_level.txt +0 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import typing as ta
|
|
2
2
|
|
|
3
3
|
from omlish import check
|
|
4
|
-
from omlish import lang
|
|
5
4
|
from omlish import marshal as msh
|
|
6
5
|
from omlish import typedvalues as tv
|
|
7
6
|
from omlish.formats import json
|
|
@@ -9,15 +8,16 @@ from omlish.http import all as http
|
|
|
9
8
|
from omlish.http import sse
|
|
10
9
|
from omlish.io.buffers import DelimitingBuffer
|
|
11
10
|
|
|
11
|
+
from .....backends.anthropic.protocol import types as pt
|
|
12
12
|
from .....backends.anthropic.protocol.sse.events import AnthropicSseDecoderEvents
|
|
13
13
|
from ....chat.choices.services import ChatChoicesOutputs
|
|
14
|
-
from ....chat.messages import SystemMessage
|
|
15
14
|
from ....chat.stream.services import ChatChoicesStreamRequest
|
|
16
15
|
from ....chat.stream.services import ChatChoicesStreamResponse
|
|
17
16
|
from ....chat.stream.services import static_check_is_chat_choices_stream_service
|
|
18
17
|
from ....chat.stream.types import AiChoiceDeltas
|
|
19
18
|
from ....chat.stream.types import AiChoicesDeltas
|
|
20
19
|
from ....chat.stream.types import ContentAiChoiceDelta
|
|
20
|
+
from ....chat.tools.types import Tool
|
|
21
21
|
from ....configs import Config
|
|
22
22
|
from ....resources import UseResources
|
|
23
23
|
from ....standard import ApiKey
|
|
@@ -25,6 +25,8 @@ from ....stream.services import StreamResponseSink
|
|
|
25
25
|
from ....stream.services import new_stream_response
|
|
26
26
|
from .chat import AnthropicChatChoicesService
|
|
27
27
|
from .names import MODEL_NAMES
|
|
28
|
+
from .protocol import build_protocol_chat_messages
|
|
29
|
+
from .protocol import build_protocol_tool
|
|
28
30
|
|
|
29
31
|
|
|
30
32
|
##
|
|
@@ -51,27 +53,25 @@ class AnthropicChatChoicesStreamService:
|
|
|
51
53
|
*,
|
|
52
54
|
max_tokens: int = 4096, # FIXME: ChatOption
|
|
53
55
|
) -> ChatChoicesStreamResponse:
|
|
54
|
-
messages =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
role=AnthropicChatChoicesService.ROLES_MAP[type(m)], # noqa
|
|
64
|
-
content=check.isinstance(AnthropicChatChoicesService._get_msg_content(m), str), # noqa
|
|
65
|
-
))
|
|
66
|
-
|
|
67
|
-
raw_request = dict(
|
|
56
|
+
messages, system = build_protocol_chat_messages(request.v)
|
|
57
|
+
|
|
58
|
+
tools: list[pt.ToolSpec] = []
|
|
59
|
+
with tv.TypedValues(*request.options).consume() as oc:
|
|
60
|
+
t: Tool
|
|
61
|
+
for t in oc.pop(Tool, []):
|
|
62
|
+
tools.append(build_protocol_tool(t))
|
|
63
|
+
|
|
64
|
+
a_req = pt.MessagesRequest(
|
|
68
65
|
model=MODEL_NAMES.resolve(self._model_name.v),
|
|
69
|
-
|
|
66
|
+
system=system,
|
|
70
67
|
messages=messages,
|
|
68
|
+
tools=tools or None,
|
|
71
69
|
max_tokens=max_tokens,
|
|
72
70
|
stream=True,
|
|
73
71
|
)
|
|
74
72
|
|
|
73
|
+
raw_request = msh.marshal(a_req)
|
|
74
|
+
|
|
75
75
|
http_request = http.HttpRequest(
|
|
76
76
|
'https://api.anthropic.com/v1/messages',
|
|
77
77
|
headers={
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ommlds
|
|
3
|
-
Version: 0.0.0.
|
|
3
|
+
Version: 0.0.0.dev465
|
|
4
4
|
Summary: ommlds
|
|
5
5
|
Author: wrmsr
|
|
6
6
|
License-Expression: BSD-3-Clause
|
|
@@ -14,8 +14,8 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
14
14
|
Requires-Python: >=3.13
|
|
15
15
|
Description-Content-Type: text/markdown
|
|
16
16
|
License-File: LICENSE
|
|
17
|
-
Requires-Dist: omdev==0.0.0.
|
|
18
|
-
Requires-Dist: omlish==0.0.0.
|
|
17
|
+
Requires-Dist: omdev==0.0.0.dev465
|
|
18
|
+
Requires-Dist: omlish==0.0.0.dev465
|
|
19
19
|
Provides-Extra: all
|
|
20
20
|
Requires-Dist: llama-cpp-python~=0.3; extra == "all"
|
|
21
21
|
Requires-Dist: mlx~=0.29; extra == "all"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
ommlds/.omlish-manifests.json,sha256=
|
|
1
|
+
ommlds/.omlish-manifests.json,sha256=5HdEXx21B_B9DSFeEoQ1teSsanB_NOU5F2o5yjrAtKI,17930
|
|
2
2
|
ommlds/__about__.py,sha256=uAJgr2I_m_oZPlV5P8XLFeYpBlEM-DdzeyF6O5OK_qs,1759
|
|
3
3
|
ommlds/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
ommlds/huggingface.py,sha256=JfEyfKOxU3-SY_ojtXBJFNeD-NIuKjvMe3GL3e93wNA,1175
|
|
@@ -77,65 +77,73 @@ ommlds/backends/torch/devices.py,sha256=KWkeyArPdUwVqckQTJPkN-4GQdv39cpOgCMv_Xfk
|
|
|
77
77
|
ommlds/backends/torch/purge.py,sha256=sp6XUxNLoVCepxIPKw3tevHn-cQqgorILvIQzixauiI,1834
|
|
78
78
|
ommlds/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
79
79
|
ommlds/cli/__main__.py,sha256=1ffCb0fcUOJMzxROJmJRXQ8PSOVYv7KrcuBtT95cf0c,140
|
|
80
|
-
ommlds/cli/inject.py,sha256=
|
|
81
|
-
ommlds/cli/main.py,sha256=
|
|
82
|
-
ommlds/cli/state.py,sha256=tRPmgCANRrw7A5Qr700OaH58F6S96O37I8Ivrbo7_gI,3001
|
|
80
|
+
ommlds/cli/inject.py,sha256=WhTDabJz9b1NRRHVH-UyVN5nj6UncvIeTvgkGrcE9vc,666
|
|
81
|
+
ommlds/cli/main.py,sha256=rOsdlBHHiF5ZjMBXSNojXFyiWin7pN6RJMZUwGEyXVs,5608
|
|
83
82
|
ommlds/cli/backends/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
84
83
|
ommlds/cli/backends/inject.py,sha256=OVstNsoeVnprM9PBL_zP0N46KkoDg3_Wz90BWcQ7km4,1734
|
|
85
84
|
ommlds/cli/backends/standard.py,sha256=HnammWyAXJHeqXJrAMBdarcT4Nyt2CxudZdD2fW_Y9M,631
|
|
86
85
|
ommlds/cli/sessions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
87
86
|
ommlds/cli/sessions/base.py,sha256=oTqsqZ9jhBWFblANpVWLLIzmRfP8HO9QYtPnZ-GZxS0,452
|
|
88
|
-
ommlds/cli/sessions/inject.py,sha256=
|
|
87
|
+
ommlds/cli/sessions/inject.py,sha256=9SrtsozIhqok3jZtepKTJwpOxHkU7FrqKw6pc78mEO4,926
|
|
89
88
|
ommlds/cli/sessions/chat/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
90
|
-
ommlds/cli/sessions/chat/
|
|
91
|
-
ommlds/cli/sessions/chat/
|
|
92
|
-
ommlds/cli/sessions/chat/inject.py,sha256=
|
|
93
|
-
ommlds/cli/sessions/chat/
|
|
94
|
-
ommlds/cli/sessions/chat/
|
|
95
|
-
ommlds/cli/sessions/chat/
|
|
96
|
-
ommlds/cli/sessions/chat/
|
|
97
|
-
ommlds/cli/sessions/chat/
|
|
98
|
-
ommlds/cli/sessions/
|
|
99
|
-
ommlds/cli/sessions/
|
|
100
|
-
ommlds/cli/sessions/
|
|
101
|
-
ommlds/cli/sessions/
|
|
102
|
-
ommlds/cli/sessions/
|
|
103
|
-
ommlds/cli/sessions/
|
|
104
|
-
ommlds/cli/sessions/
|
|
105
|
-
ommlds/cli/sessions/
|
|
106
|
-
ommlds/cli/sessions/
|
|
107
|
-
ommlds/cli/sessions/
|
|
108
|
-
ommlds/cli/sessions/
|
|
109
|
-
ommlds/cli/sessions/
|
|
110
|
-
ommlds/cli/sessions/
|
|
111
|
-
ommlds/cli/sessions/
|
|
112
|
-
ommlds/cli/sessions/
|
|
113
|
-
ommlds/cli/sessions/
|
|
114
|
-
ommlds/cli/sessions/
|
|
115
|
-
ommlds/cli/sessions/
|
|
116
|
-
ommlds/cli/sessions/
|
|
117
|
-
ommlds/cli/sessions/
|
|
118
|
-
ommlds/cli/sessions/
|
|
119
|
-
ommlds/cli/sessions/
|
|
120
|
-
ommlds/cli/sessions/
|
|
121
|
-
ommlds/cli/sessions/
|
|
122
|
-
ommlds/cli/sessions/
|
|
123
|
-
ommlds/cli/sessions/
|
|
124
|
-
ommlds/cli/sessions/
|
|
125
|
-
ommlds/cli/sessions/
|
|
126
|
-
ommlds/cli/sessions/
|
|
127
|
-
ommlds/cli/sessions/
|
|
128
|
-
ommlds/cli/sessions/
|
|
129
|
-
ommlds/cli/sessions/
|
|
130
|
-
ommlds/cli/sessions/
|
|
89
|
+
ommlds/cli/sessions/chat/configs.py,sha256=7NtpOaSyjABKLuJ1jAbp1lCT1tPjvPVJ_vakbzvuk8g,692
|
|
90
|
+
ommlds/cli/sessions/chat/driver.py,sha256=ddnCYTKqWiPxV8U4UbFwb7E3yi81ItjZ9j3AJd3a3Mk,1395
|
|
91
|
+
ommlds/cli/sessions/chat/inject.py,sha256=7Yg6wUs2Oej4UjNZCAWCJCEsDJZWvT4G8XvkvVUMC7U,1928
|
|
92
|
+
ommlds/cli/sessions/chat/session.py,sha256=eqwelLE74JFC-fBpk_hdwMD2nP4pLv3ZPwUn99200B8,521
|
|
93
|
+
ommlds/cli/sessions/chat/backends/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
94
|
+
ommlds/cli/sessions/chat/backends/catalog.py,sha256=GroogxBQf_zlrhEEwTSq18v13HWsuXOP276VcuphPic,1756
|
|
95
|
+
ommlds/cli/sessions/chat/backends/inject.py,sha256=VbZ-Fb679kTItRpAhIYCqSM8vXUFeRDQWssUfrFgGi8,882
|
|
96
|
+
ommlds/cli/sessions/chat/backends/injection.py,sha256=GCn5OvNIEowgB70kQVuU84z3i8lLA4vOVkTZlQG8s0o,327
|
|
97
|
+
ommlds/cli/sessions/chat/backends/types.py,sha256=5eImYHXLKqbC5MDrN443eMGamP9snCmV1n7LtAsqgPk,696
|
|
98
|
+
ommlds/cli/sessions/chat/chat/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
99
|
+
ommlds/cli/sessions/chat/chat/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
100
|
+
ommlds/cli/sessions/chat/chat/ai/inject.py,sha256=FCq-E8auVJ-gnK18NoKiINGBHgDllroZRG7z5ZY63L8,2514
|
|
101
|
+
ommlds/cli/sessions/chat/chat/ai/injection.py,sha256=2O_ELMusxQsYaB2oqvzjYpZQzjshocJup7Z5unzoUIY,404
|
|
102
|
+
ommlds/cli/sessions/chat/chat/ai/rendering.py,sha256=cicA6NwkM9UJb1dgsakhkhIMWGzBsArPFvYoINBmuec,2285
|
|
103
|
+
ommlds/cli/sessions/chat/chat/ai/services.py,sha256=RNO3emXEFPr0M04wThRQo332x0n5R3n8aQFctcePCHQ,2629
|
|
104
|
+
ommlds/cli/sessions/chat/chat/ai/tools.py,sha256=en94LLM8y73N11xhQPlkSLfbzAmYVwKU-4nz2i0CK0E,1094
|
|
105
|
+
ommlds/cli/sessions/chat/chat/ai/types.py,sha256=QH6Cn6DrdxBi0Tnura7Fq-WtGUm0FdsazZSgki6nf0A,750
|
|
106
|
+
ommlds/cli/sessions/chat/chat/state/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
107
|
+
ommlds/cli/sessions/chat/chat/state/inject.py,sha256=usHhiE1fKtttJvxgVN-LuwIsfyau_0n17-99bDuPNnw,1131
|
|
108
|
+
ommlds/cli/sessions/chat/chat/state/inmemory.py,sha256=2lSCWnNEH_vj9RJUVzM8huAHAXBJ6Go02og2nzew1hk,861
|
|
109
|
+
ommlds/cli/sessions/chat/chat/state/storage.py,sha256=Q7OOjZKjvkRbiEWIVFKG66xxrxHqFFzx0IcL5cNJrG4,1436
|
|
110
|
+
ommlds/cli/sessions/chat/chat/state/types.py,sha256=iMovPXnRvZJ8ieM5gPnTBi1X7j-9GUtziiPBZJJf034,794
|
|
111
|
+
ommlds/cli/sessions/chat/chat/user/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
112
|
+
ommlds/cli/sessions/chat/chat/user/inject.py,sha256=x0DV0kMxEiHVTjQwsQlW4wKHfACu0Nlnhbsc4Uum_wI,2164
|
|
113
|
+
ommlds/cli/sessions/chat/chat/user/interactive.py,sha256=AZ8v5uGscnNk4KJdGisOA2LND8m7473fY5Whks7M_tI,688
|
|
114
|
+
ommlds/cli/sessions/chat/chat/user/oneshot.py,sha256=jPrZBBuf-olBfPF7CPTYK7-Dr7EvSriU7L0nORHfbv4,588
|
|
115
|
+
ommlds/cli/sessions/chat/chat/user/types.py,sha256=MNlhMxlLtxVod9rUZlSPvRaippPAXEdX_GHh73QLeSg,262
|
|
116
|
+
ommlds/cli/sessions/chat/content/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
117
|
+
ommlds/cli/sessions/chat/content/messages.py,sha256=DhGIBdPXXiQdKcQkPKFJPmhdL2CBHvyoVWhSKBRVMY0,939
|
|
118
|
+
ommlds/cli/sessions/chat/content/strings.py,sha256=PyaHeUnAAuhOyJr7F7G4xupUOQLs7_iOd74wFNHTkfg,1055
|
|
119
|
+
ommlds/cli/sessions/chat/phases/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
120
|
+
ommlds/cli/sessions/chat/phases/inject.py,sha256=m9GcCVcp1GnNKN1qwDSgTkfp3e107wXgPeEHDLbfG8s,448
|
|
121
|
+
ommlds/cli/sessions/chat/phases/injection.py,sha256=ZUFRRLp3HNhKaPBW6aiw5XFEGNkqTj8WVSlXM0kg0y0,326
|
|
122
|
+
ommlds/cli/sessions/chat/phases/manager.py,sha256=_wfc0FfL5h_5L-6hnYb3U3kiRmkGDkJu7wGj5Cgz7_Y,727
|
|
123
|
+
ommlds/cli/sessions/chat/phases/types.py,sha256=w1pAEydJYaHzSzdlqygCwKxvVZnfo_R_xJqq8wBzZsQ,512
|
|
124
|
+
ommlds/cli/sessions/chat/rendering/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
125
|
+
ommlds/cli/sessions/chat/rendering/inject.py,sha256=Yo_BDxDNbTge8UtEp31uTKhsFdaeVf-4CFs3rdu8l0I,885
|
|
126
|
+
ommlds/cli/sessions/chat/rendering/markdown.py,sha256=C4z9Rs0ivVTrBmu7lFnybNOq1j9hEZb58Gc_R8rmcUI,1803
|
|
127
|
+
ommlds/cli/sessions/chat/rendering/raw.py,sha256=L7RIY77dycZRTspWJC4Vj4fP9I-vdqo_0qe_8bj-0QQ,2432
|
|
128
|
+
ommlds/cli/sessions/chat/rendering/types.py,sha256=6wzYeitDGVufrf0W-R2cuwcBscPf9yPl0HtiCd7am2Q,449
|
|
129
|
+
ommlds/cli/sessions/chat/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
130
|
+
ommlds/cli/sessions/chat/tools/confirmation.py,sha256=I_nYBIIoeprCShUaVpN4v01YOAdY6iJEM5-ybc0p8VA,1072
|
|
131
|
+
ommlds/cli/sessions/chat/tools/execution.py,sha256=4sRuZWZjNBo852hhLZjqTqEZpgu9KPXHEawiICIMUdc,1576
|
|
132
|
+
ommlds/cli/sessions/chat/tools/inject.py,sha256=iKBvMrgmFCkgjD0MWtIQFuoiijfRwmhfFW1l6q5Fnd0,3845
|
|
133
|
+
ommlds/cli/sessions/chat/tools/injection.py,sha256=xsVbJAKsDIP-2LbzDXZ3LBJgeY0FJ66UuCK0OYB1uw0,837
|
|
134
|
+
ommlds/cli/sessions/chat/tools/rendering.py,sha256=a9gIhxuGF9tfXGlkGXpdweSz4dacIsxoqJNKpRSvUN4,1402
|
|
135
|
+
ommlds/cli/sessions/chat/tools/weather.py,sha256=vZXOHdRGGlkDEXasW5foc58MyEMOc79bhIfIgrumRlo,302
|
|
131
136
|
ommlds/cli/sessions/completion/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
132
|
-
ommlds/cli/sessions/completion/
|
|
137
|
+
ommlds/cli/sessions/completion/configs.py,sha256=KeOmvNrq6KkI96FaRRPnpWNx3yDlD-FgaiOwPEL9HPU,245
|
|
138
|
+
ommlds/cli/sessions/completion/inject.py,sha256=qpyp2Ro0sPOIOssk-7eXOseKG1Fu_vf1zvyLjZi5qIE,564
|
|
139
|
+
ommlds/cli/sessions/completion/session.py,sha256=YLq9beHxfgCAu8t9Xj54qQxXj8ebwqrcN8JsJ3_2KOw,1067
|
|
133
140
|
ommlds/cli/sessions/embedding/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
134
|
-
ommlds/cli/sessions/embedding/
|
|
135
|
-
ommlds/cli/
|
|
136
|
-
ommlds/cli/
|
|
137
|
-
ommlds/cli/
|
|
138
|
-
ommlds/cli/
|
|
141
|
+
ommlds/cli/sessions/embedding/configs.py,sha256=WwWwJ7GpUYUEOPcYr2EhNLV8m1cK6llp5N_bMnFX_cw,243
|
|
142
|
+
ommlds/cli/sessions/embedding/inject.py,sha256=XYjqDT5GajZ0LNks36aZRNNKhH1m-xfAL1bbMxfISYQ,559
|
|
143
|
+
ommlds/cli/sessions/embedding/session.py,sha256=SccMICjbS1BL7wMkDzd17d2TWRjbzAmMwFn_CjC2-a8,1039
|
|
144
|
+
ommlds/cli/state/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
145
|
+
ommlds/cli/state/inject.py,sha256=-wqovpgxLYBpJkkCzscn2o6F6AD-agF8PoNjVac6FuQ,702
|
|
146
|
+
ommlds/cli/state/storage.py,sha256=tRPmgCANRrw7A5Qr700OaH58F6S96O37I8Ivrbo7_gI,3001
|
|
139
147
|
ommlds/datasets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
140
148
|
ommlds/datasets/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
141
149
|
ommlds/datasets/lib/movies.py,sha256=LmdfoXsZU9XMM_r-sxCLv_s06BFzwWO4xUj6sc9XVcI,1961
|
|
@@ -161,9 +169,10 @@ ommlds/minichain/backends/impls/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm
|
|
|
161
169
|
ommlds/minichain/backends/impls/mistral.py,sha256=I_HTwXqAoQi2xyw_nLTeUamtOZLLl-oQZ234AVJZZLA,2649
|
|
162
170
|
ommlds/minichain/backends/impls/sqlite.py,sha256=NOFm_fgr-OZ8mo7etj0zwvxsDnidRwKzhdDom58e6ks,2157
|
|
163
171
|
ommlds/minichain/backends/impls/anthropic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
164
|
-
ommlds/minichain/backends/impls/anthropic/chat.py,sha256=
|
|
172
|
+
ommlds/minichain/backends/impls/anthropic/chat.py,sha256=LVaRP_Pbz4UghSHD8GZ22hMWE4Rsd_6bSysgl2BR_AM,4166
|
|
165
173
|
ommlds/minichain/backends/impls/anthropic/names.py,sha256=GPPeYt0CcDcDCR8I6BMd7bMjC_Zk_bjnLLpF9ClwXcg,1099
|
|
166
|
-
ommlds/minichain/backends/impls/anthropic/
|
|
174
|
+
ommlds/minichain/backends/impls/anthropic/protocol.py,sha256=whPVYuKShKiMCzasHl77sCIiymhzXj8mFZXEyhZvld8,3292
|
|
175
|
+
ommlds/minichain/backends/impls/anthropic/stream.py,sha256=agET8PPbKg-7gYL3FGyU45J-QqV65VkEo15ipScEzUA,7667
|
|
167
176
|
ommlds/minichain/backends/impls/duckduckgo/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
168
177
|
ommlds/minichain/backends/impls/duckduckgo/search.py,sha256=igzeU9P9b1MMiu4KAJVS9H6KLIoPm68wXi4Kx3_DHyQ,940
|
|
169
178
|
ommlds/minichain/backends/impls/google/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -358,9 +367,9 @@ ommlds/wiki/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
|
|
|
358
367
|
ommlds/wiki/utils/io.py,sha256=UKgDJGtmpnWvIqVd2mJc2QNPOqlToEY1GEveNp6_pMo,7088
|
|
359
368
|
ommlds/wiki/utils/progress.py,sha256=EhvKcMFYtsarCQhIahlO6f0SboyAKP3UwUyrnVnP-Vk,3222
|
|
360
369
|
ommlds/wiki/utils/xml.py,sha256=vVV8Ctn13aaRM9eYfs9Wd6rHn5WOCEUzQ44fIhOvJdg,3754
|
|
361
|
-
ommlds-0.0.0.
|
|
362
|
-
ommlds-0.0.0.
|
|
363
|
-
ommlds-0.0.0.
|
|
364
|
-
ommlds-0.0.0.
|
|
365
|
-
ommlds-0.0.0.
|
|
366
|
-
ommlds-0.0.0.
|
|
370
|
+
ommlds-0.0.0.dev465.dist-info/licenses/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
|
|
371
|
+
ommlds-0.0.0.dev465.dist-info/METADATA,sha256=JAD5TLj7Vqeese-787MMUhAcQFykg29h_upNHQ5XUFA,3224
|
|
372
|
+
ommlds-0.0.0.dev465.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
373
|
+
ommlds-0.0.0.dev465.dist-info/entry_points.txt,sha256=Z5YWtX7ClfiCKdW-dd_CSVvM0h4yQpJPi-2G3q6gNFo,35
|
|
374
|
+
ommlds-0.0.0.dev465.dist-info/top_level.txt,sha256=Rbnk5d5wi58vnAXx13WFZqdQ4VX8hBCS2hEL3WeXOhY,7
|
|
375
|
+
ommlds-0.0.0.dev465.dist-info/RECORD,,
|
ommlds/cli/sessions/chat/base.py
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import dataclasses as dc
|
|
2
|
-
import typing as ta
|
|
3
|
-
|
|
4
|
-
from omlish import lang
|
|
5
|
-
|
|
6
|
-
from .... import minichain as mc
|
|
7
|
-
from ..base import Session
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
##
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
DEFAULT_CHAT_MODEL_BACKEND = 'openai'
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
##
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
ChatOption: ta.TypeAlias = mc.ChatChoicesOptions
|
|
20
|
-
ChatOptions = ta.NewType('ChatOptions', ta.Sequence[ChatOption])
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
##
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
ChatSessionConfigT = ta.TypeVar('ChatSessionConfigT', bound='ChatSession.Config')
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class ChatSession(Session[ChatSessionConfigT], lang.Abstract, ta.Generic[ChatSessionConfigT]):
|
|
30
|
-
@dc.dataclass(frozen=True)
|
|
31
|
-
class Config(Session.Config, lang.Abstract):
|
|
32
|
-
_: dc.KW_ONLY
|
|
33
|
-
|
|
34
|
-
markdown: bool = False
|
|
35
|
-
|
|
36
|
-
dangerous_no_tool_confirmation: bool = False
|
|
37
|
-
|
|
38
|
-
def __init__(
|
|
39
|
-
self,
|
|
40
|
-
config: ChatSessionConfigT,
|
|
41
|
-
) -> None:
|
|
42
|
-
super().__init__(config)
|
ommlds/cli/sessions/chat/code.py
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import dataclasses as dc
|
|
2
|
-
import itertools
|
|
3
|
-
import os.path
|
|
4
|
-
|
|
5
|
-
from omlish import check
|
|
6
|
-
from omlish import lang
|
|
7
|
-
|
|
8
|
-
from .... import minichain as mc
|
|
9
|
-
from ....minichain.lib.code.prompts import CODE_AGENT_SYSTEM_PROMPT
|
|
10
|
-
from ...tools.config import ToolsConfig
|
|
11
|
-
from .base import DEFAULT_CHAT_MODEL_BACKEND
|
|
12
|
-
from .base import ChatOptions
|
|
13
|
-
from .base import ChatSession
|
|
14
|
-
from .printing import ChatSessionPrinter
|
|
15
|
-
from .state import ChatStateManager
|
|
16
|
-
from .tools import ToolUseExecutor
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
##
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class CodeChatSession(ChatSession['CodeChatSession.Config']):
|
|
23
|
-
@dc.dataclass(frozen=True)
|
|
24
|
-
class Config(ChatSession.Config):
|
|
25
|
-
_: dc.KW_ONLY
|
|
26
|
-
|
|
27
|
-
new: bool = False
|
|
28
|
-
|
|
29
|
-
backend: str | None = None
|
|
30
|
-
model_name: str | None = None
|
|
31
|
-
|
|
32
|
-
initial_message: mc.Content | None = None
|
|
33
|
-
|
|
34
|
-
def __init__(
|
|
35
|
-
self,
|
|
36
|
-
config: Config,
|
|
37
|
-
*,
|
|
38
|
-
state_manager: ChatStateManager,
|
|
39
|
-
chat_options: ChatOptions | None = None,
|
|
40
|
-
printer: ChatSessionPrinter,
|
|
41
|
-
backend_catalog: mc.BackendCatalog,
|
|
42
|
-
tool_exec_request_executor: ToolUseExecutor,
|
|
43
|
-
tools_config: ToolsConfig | None = None,
|
|
44
|
-
) -> None:
|
|
45
|
-
super().__init__(config)
|
|
46
|
-
|
|
47
|
-
self._state_manager = state_manager
|
|
48
|
-
self._chat_options = chat_options
|
|
49
|
-
self._printer = printer
|
|
50
|
-
self._backend_catalog = backend_catalog
|
|
51
|
-
self._tool_exec_request_executor = tool_exec_request_executor
|
|
52
|
-
self._tools_config = tools_config
|
|
53
|
-
|
|
54
|
-
async def run(self) -> None:
|
|
55
|
-
if self._config.new:
|
|
56
|
-
self._state_manager.clear_state()
|
|
57
|
-
state = self._state_manager.extend_chat([
|
|
58
|
-
mc.SystemMessage(CODE_AGENT_SYSTEM_PROMPT),
|
|
59
|
-
])
|
|
60
|
-
|
|
61
|
-
else:
|
|
62
|
-
state = self._state_manager.get_state()
|
|
63
|
-
|
|
64
|
-
backend = self._config.backend
|
|
65
|
-
if backend is None:
|
|
66
|
-
backend = DEFAULT_CHAT_MODEL_BACKEND
|
|
67
|
-
|
|
68
|
-
# FIXME: lol
|
|
69
|
-
from ....minichain.lib.fs.context import FsContext
|
|
70
|
-
fs_tool_context = FsContext(
|
|
71
|
-
root_dir=os.getcwd(),
|
|
72
|
-
writes_permitted=self._tools_config is not None and self._tools_config.enable_unsafe_tools_do_not_use_lol,
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
from ....minichain.lib.todo.context import TodoContext
|
|
76
|
-
todo_tool_context = TodoContext()
|
|
77
|
-
|
|
78
|
-
mdl: mc.ChatChoicesService
|
|
79
|
-
async with lang.async_maybe_managing(self._backend_catalog.get_backend(
|
|
80
|
-
mc.ChatChoicesService,
|
|
81
|
-
backend,
|
|
82
|
-
*([mc.ModelName(mn)] if (mn := self._config.model_name) is not None else []),
|
|
83
|
-
)) as mdl:
|
|
84
|
-
for i in itertools.count():
|
|
85
|
-
if not i and self._config.initial_message is not None:
|
|
86
|
-
req_msg = mc.UserMessage(self._config.initial_message)
|
|
87
|
-
else:
|
|
88
|
-
try:
|
|
89
|
-
prompt = input('> ') # FIXME: async lol
|
|
90
|
-
except EOFError:
|
|
91
|
-
break
|
|
92
|
-
req_msg = mc.UserMessage(prompt)
|
|
93
|
-
|
|
94
|
-
state = self._state_manager.extend_chat([req_msg])
|
|
95
|
-
|
|
96
|
-
while True:
|
|
97
|
-
response = await mdl.invoke(mc.ChatChoicesRequest(
|
|
98
|
-
state.chat,
|
|
99
|
-
(self._chat_options or []),
|
|
100
|
-
))
|
|
101
|
-
|
|
102
|
-
tool_resp_lst = []
|
|
103
|
-
for resp_msg in check.single(response.v).ms:
|
|
104
|
-
state = self._state_manager.extend_chat([resp_msg])
|
|
105
|
-
|
|
106
|
-
if isinstance(resp_msg, mc.AiMessage):
|
|
107
|
-
self._printer.print(resp_msg)
|
|
108
|
-
|
|
109
|
-
elif isinstance(resp_msg, mc.ToolUseMessage):
|
|
110
|
-
trm = await self._tool_exec_request_executor.execute_tool_use(
|
|
111
|
-
resp_msg.tu,
|
|
112
|
-
fs_tool_context,
|
|
113
|
-
todo_tool_context,
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
self._printer.print(trm.tur.c)
|
|
117
|
-
tool_resp_lst.append(trm)
|
|
118
|
-
|
|
119
|
-
else:
|
|
120
|
-
raise TypeError(resp_msg)
|
|
121
|
-
|
|
122
|
-
if not tool_resp_lst:
|
|
123
|
-
break
|
|
124
|
-
|
|
125
|
-
state = self._state_manager.extend_chat(tool_resp_lst)
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import dataclasses as dc
|
|
2
|
-
|
|
3
|
-
from omlish import check
|
|
4
|
-
from omlish import lang
|
|
5
|
-
|
|
6
|
-
from .... import minichain as mc
|
|
7
|
-
from .base import DEFAULT_CHAT_MODEL_BACKEND
|
|
8
|
-
from .base import ChatSession
|
|
9
|
-
from .printing import ChatSessionPrinter
|
|
10
|
-
from .state import ChatStateManager
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
##
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class InteractiveChatSession(ChatSession['InteractiveChatSession.Config']):
|
|
17
|
-
@dc.dataclass(frozen=True)
|
|
18
|
-
class Config(ChatSession.Config):
|
|
19
|
-
_: dc.KW_ONLY
|
|
20
|
-
|
|
21
|
-
new: bool = False
|
|
22
|
-
|
|
23
|
-
backend: str | None = None
|
|
24
|
-
model_name: str | None = None
|
|
25
|
-
|
|
26
|
-
def __init__(
|
|
27
|
-
self,
|
|
28
|
-
config: Config,
|
|
29
|
-
*,
|
|
30
|
-
state_manager: ChatStateManager,
|
|
31
|
-
printer: ChatSessionPrinter,
|
|
32
|
-
backend_catalog: mc.BackendCatalog,
|
|
33
|
-
) -> None:
|
|
34
|
-
super().__init__(config)
|
|
35
|
-
|
|
36
|
-
self._state_manager = state_manager
|
|
37
|
-
self._printer = printer
|
|
38
|
-
self._backend_catalog = backend_catalog
|
|
39
|
-
|
|
40
|
-
async def run(self) -> None:
|
|
41
|
-
if self._config.new:
|
|
42
|
-
state = self._state_manager.clear_state()
|
|
43
|
-
else:
|
|
44
|
-
state = self._state_manager.get_state()
|
|
45
|
-
|
|
46
|
-
backend = self._config.backend
|
|
47
|
-
if backend is None:
|
|
48
|
-
backend = DEFAULT_CHAT_MODEL_BACKEND
|
|
49
|
-
|
|
50
|
-
mdl: mc.ChatChoicesService
|
|
51
|
-
async with lang.async_maybe_managing(self._backend_catalog.get_backend(
|
|
52
|
-
mc.ChatChoicesService,
|
|
53
|
-
backend,
|
|
54
|
-
*([mc.ModelName(mn)] if (mn := self._config.model_name) is not None else []),
|
|
55
|
-
)) as mdl:
|
|
56
|
-
while True:
|
|
57
|
-
try:
|
|
58
|
-
prompt = input('> ') # FIXME: async lol
|
|
59
|
-
except EOFError:
|
|
60
|
-
break
|
|
61
|
-
|
|
62
|
-
req_msg = mc.UserMessage(prompt)
|
|
63
|
-
|
|
64
|
-
response = await mdl.invoke(mc.ChatChoicesRequest([*state.chat, req_msg]))
|
|
65
|
-
|
|
66
|
-
resp_msg = check.isinstance(check.single(response.v[0].ms), mc.AiMessage)
|
|
67
|
-
|
|
68
|
-
self._printer.print(resp_msg)
|
|
69
|
-
|
|
70
|
-
state = self._state_manager.extend_chat([req_msg, resp_msg])
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import abc
|
|
2
|
-
import typing as ta
|
|
3
|
-
|
|
4
|
-
from omdev.tui import rich
|
|
5
|
-
from omlish import check
|
|
6
|
-
from omlish import lang
|
|
7
|
-
from omlish.formats import json
|
|
8
|
-
|
|
9
|
-
from .... import minichain as mc
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
##
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class ChatSessionPrinter(lang.Abstract):
|
|
16
|
-
@abc.abstractmethod
|
|
17
|
-
def print(self, obj: mc.Message | mc.Content) -> None:
|
|
18
|
-
raise NotImplementedError
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
#
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class StringChatSessionPrinter(ChatSessionPrinter, lang.Abstract):
|
|
25
|
-
@abc.abstractmethod
|
|
26
|
-
def _print_str(self, s: str) -> None:
|
|
27
|
-
raise NotImplementedError
|
|
28
|
-
|
|
29
|
-
def print(self, obj: mc.Message | mc.Content) -> None:
|
|
30
|
-
if obj is None:
|
|
31
|
-
pass
|
|
32
|
-
|
|
33
|
-
elif isinstance(obj, mc.Message):
|
|
34
|
-
if isinstance(obj, mc.SystemMessage):
|
|
35
|
-
if obj.c is not None:
|
|
36
|
-
self._print_str(check.isinstance(obj.c, str))
|
|
37
|
-
elif isinstance(obj, mc.UserMessage):
|
|
38
|
-
if obj.c is not None:
|
|
39
|
-
self._print_str(check.isinstance(obj.c, str))
|
|
40
|
-
elif isinstance(obj, mc.AiMessage):
|
|
41
|
-
if obj.c is not None:
|
|
42
|
-
self._print_str(check.isinstance(obj.c, str))
|
|
43
|
-
elif isinstance(obj, mc.ToolUseResultMessage):
|
|
44
|
-
self._print_str(check.isinstance(obj.tur.c, str))
|
|
45
|
-
else:
|
|
46
|
-
raise TypeError(obj)
|
|
47
|
-
|
|
48
|
-
elif isinstance(obj, mc.JsonContent):
|
|
49
|
-
self._print_str(json.dumps_pretty(obj.v))
|
|
50
|
-
|
|
51
|
-
elif isinstance(obj, str):
|
|
52
|
-
self._print_str(obj)
|
|
53
|
-
|
|
54
|
-
else:
|
|
55
|
-
raise TypeError(obj)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
#
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
class SimpleStringChatSessionPrinter(StringChatSessionPrinter):
|
|
62
|
-
def __init__(
|
|
63
|
-
self,
|
|
64
|
-
*,
|
|
65
|
-
str_printer: ta.Callable[[str], None] | None = None,
|
|
66
|
-
) -> None:
|
|
67
|
-
super().__init__()
|
|
68
|
-
|
|
69
|
-
if str_printer is None:
|
|
70
|
-
str_printer = print
|
|
71
|
-
self._str_printer = str_printer
|
|
72
|
-
|
|
73
|
-
def _print_str(self, s: str) -> None:
|
|
74
|
-
s = s.strip()
|
|
75
|
-
if not s:
|
|
76
|
-
return
|
|
77
|
-
|
|
78
|
-
self._str_printer(s)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
#
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
class MarkdownStringChatSessionPrinter(StringChatSessionPrinter):
|
|
85
|
-
def _print_str(self, s: str) -> None:
|
|
86
|
-
s = s.strip()
|
|
87
|
-
if not s:
|
|
88
|
-
return
|
|
89
|
-
|
|
90
|
-
rich.Console().print(rich.Markdown(s))
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
##
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
class StreamPrinter(lang.ExitStacked, lang.Abstract):
|
|
97
|
-
@abc.abstractmethod
|
|
98
|
-
def feed(self, s: str) -> None:
|
|
99
|
-
raise NotImplementedError
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
#
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
class SimpleStreamPrinter(StreamPrinter):
|
|
106
|
-
def feed(self, s: str) -> None:
|
|
107
|
-
print(s, end='', flush=True)
|
|
108
|
-
|
|
109
|
-
def _exit_contexts(self) -> None:
|
|
110
|
-
super()._exit_contexts()
|
|
111
|
-
print(flush=True)
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
#
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
class MarkdownStreamPrinter(StreamPrinter):
|
|
118
|
-
def __init__(self) -> None:
|
|
119
|
-
super().__init__()
|
|
120
|
-
|
|
121
|
-
def _enter_contexts(self) -> None:
|
|
122
|
-
super()._enter_contexts()
|
|
123
|
-
self._ir: rich.MarkdownLiveStream = self._enter_context(rich.IncrementalMarkdownLiveStream())
|
|
124
|
-
|
|
125
|
-
def feed(self, s: str) -> None:
|
|
126
|
-
self._ir.feed(s)
|