ommlds 0.0.0.dev426__py3-none-any.whl → 0.0.0.dev485__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.
- ommlds/.omlish-manifests.json +336 -39
- ommlds/__about__.py +16 -10
- ommlds/_hacks/__init__.py +4 -0
- ommlds/_hacks/funcs.py +110 -0
- ommlds/_hacks/names.py +158 -0
- ommlds/_hacks/params.py +73 -0
- ommlds/_hacks/patches.py +0 -3
- ommlds/backends/anthropic/protocol/__init__.py +13 -1
- ommlds/backends/anthropic/protocol/_dataclasses.py +1625 -0
- ommlds/backends/anthropic/protocol/_marshal.py +2 -2
- ommlds/backends/anthropic/protocol/sse/_marshal.py +1 -1
- ommlds/backends/anthropic/protocol/sse/assemble.py +23 -7
- ommlds/backends/anthropic/protocol/sse/events.py +13 -0
- ommlds/backends/anthropic/protocol/types.py +40 -8
- ommlds/backends/google/protocol/__init__.py +16 -0
- ommlds/backends/google/protocol/_dataclasses.py +5997 -0
- ommlds/backends/google/protocol/_marshal.py +16 -0
- ommlds/backends/google/protocol/types.py +626 -0
- ommlds/backends/groq/__init__.py +7 -0
- ommlds/backends/groq/_dataclasses.py +3901 -0
- ommlds/backends/groq/_marshal.py +23 -0
- ommlds/backends/groq/protocol.py +249 -0
- ommlds/backends/llamacpp/logging.py +4 -1
- ommlds/backends/mlx/caching.py +7 -3
- ommlds/backends/mlx/cli.py +10 -7
- ommlds/backends/mlx/generation.py +19 -17
- ommlds/backends/mlx/limits.py +10 -6
- ommlds/backends/mlx/loading.py +65 -5
- ommlds/backends/ollama/__init__.py +7 -0
- ommlds/backends/ollama/_dataclasses.py +3458 -0
- ommlds/backends/ollama/protocol.py +170 -0
- ommlds/backends/openai/protocol/__init__.py +24 -29
- ommlds/backends/openai/protocol/_common.py +18 -0
- ommlds/backends/openai/protocol/_dataclasses.py +7708 -0
- ommlds/backends/openai/protocol/_marshal.py +27 -0
- ommlds/backends/openai/protocol/chatcompletion/chunk.py +58 -31
- ommlds/backends/openai/protocol/chatcompletion/contentpart.py +49 -44
- ommlds/backends/openai/protocol/chatcompletion/message.py +55 -43
- ommlds/backends/openai/protocol/chatcompletion/request.py +114 -66
- ommlds/backends/openai/protocol/chatcompletion/response.py +71 -45
- ommlds/backends/openai/protocol/chatcompletion/responseformat.py +27 -20
- ommlds/backends/openai/protocol/chatcompletion/tokenlogprob.py +16 -7
- ommlds/backends/openai/protocol/completionusage.py +24 -15
- ommlds/backends/tavily/__init__.py +7 -0
- ommlds/backends/tavily/_dataclasses.py +1734 -0
- ommlds/backends/tavily/protocol.py +301 -0
- ommlds/backends/tinygrad/models/llama3/__init__.py +22 -14
- ommlds/backends/transformers/__init__.py +14 -0
- ommlds/backends/transformers/filecache.py +109 -0
- ommlds/backends/transformers/streamers.py +73 -0
- ommlds/cli/__init__.py +7 -0
- ommlds/cli/_dataclasses.py +2562 -0
- ommlds/cli/asyncs.py +30 -0
- ommlds/cli/backends/catalog.py +93 -0
- ommlds/cli/backends/configs.py +9 -0
- ommlds/cli/backends/inject.py +31 -36
- ommlds/cli/backends/injection.py +16 -0
- ommlds/cli/backends/types.py +46 -0
- ommlds/cli/content/messages.py +34 -0
- ommlds/cli/content/strings.py +42 -0
- ommlds/cli/inject.py +17 -32
- ommlds/cli/inputs/__init__.py +0 -0
- ommlds/cli/inputs/asyncs.py +32 -0
- ommlds/cli/inputs/sync.py +75 -0
- ommlds/cli/main.py +270 -110
- ommlds/cli/rendering/__init__.py +0 -0
- ommlds/cli/rendering/configs.py +9 -0
- ommlds/cli/rendering/inject.py +31 -0
- ommlds/cli/rendering/markdown.py +52 -0
- ommlds/cli/rendering/raw.py +73 -0
- ommlds/cli/rendering/types.py +21 -0
- ommlds/cli/secrets.py +21 -0
- ommlds/cli/sessions/base.py +1 -1
- ommlds/cli/sessions/chat/chat/__init__.py +0 -0
- ommlds/cli/sessions/chat/chat/ai/__init__.py +0 -0
- ommlds/cli/sessions/chat/chat/ai/configs.py +11 -0
- ommlds/cli/sessions/chat/chat/ai/inject.py +74 -0
- ommlds/cli/sessions/chat/chat/ai/injection.py +14 -0
- ommlds/cli/sessions/chat/chat/ai/rendering.py +70 -0
- ommlds/cli/sessions/chat/chat/ai/services.py +79 -0
- ommlds/cli/sessions/chat/chat/ai/tools.py +44 -0
- ommlds/cli/sessions/chat/chat/ai/types.py +28 -0
- ommlds/cli/sessions/chat/chat/state/__init__.py +0 -0
- ommlds/cli/sessions/chat/chat/state/configs.py +11 -0
- ommlds/cli/sessions/chat/chat/state/inject.py +36 -0
- ommlds/cli/sessions/chat/chat/state/inmemory.py +33 -0
- ommlds/cli/sessions/chat/chat/state/storage.py +52 -0
- ommlds/cli/sessions/chat/chat/state/types.py +38 -0
- ommlds/cli/sessions/chat/chat/user/__init__.py +0 -0
- ommlds/cli/sessions/chat/chat/user/configs.py +17 -0
- ommlds/cli/sessions/chat/chat/user/inject.py +62 -0
- ommlds/cli/sessions/chat/chat/user/interactive.py +31 -0
- ommlds/cli/sessions/chat/chat/user/oneshot.py +25 -0
- ommlds/cli/sessions/chat/chat/user/types.py +15 -0
- ommlds/cli/sessions/chat/configs.py +27 -0
- ommlds/cli/sessions/chat/driver.py +43 -0
- ommlds/cli/sessions/chat/inject.py +33 -65
- ommlds/cli/sessions/chat/phases/__init__.py +0 -0
- ommlds/cli/sessions/chat/phases/inject.py +27 -0
- ommlds/cli/sessions/chat/phases/injection.py +14 -0
- ommlds/cli/sessions/chat/phases/manager.py +29 -0
- ommlds/cli/sessions/chat/phases/types.py +29 -0
- ommlds/cli/sessions/chat/session.py +27 -0
- ommlds/cli/sessions/chat/tools/__init__.py +0 -0
- ommlds/cli/sessions/chat/tools/configs.py +22 -0
- ommlds/cli/sessions/chat/tools/confirmation.py +46 -0
- ommlds/cli/sessions/chat/tools/execution.py +66 -0
- ommlds/cli/sessions/chat/tools/fs/__init__.py +0 -0
- ommlds/cli/sessions/chat/tools/fs/configs.py +12 -0
- ommlds/cli/sessions/chat/tools/fs/inject.py +35 -0
- ommlds/cli/sessions/chat/tools/inject.py +88 -0
- ommlds/cli/sessions/chat/tools/injection.py +44 -0
- ommlds/cli/sessions/chat/tools/rendering.py +58 -0
- ommlds/cli/sessions/chat/tools/todo/__init__.py +0 -0
- ommlds/cli/sessions/chat/tools/todo/configs.py +12 -0
- ommlds/cli/sessions/chat/tools/todo/inject.py +31 -0
- ommlds/cli/sessions/chat/tools/weather/__init__.py +0 -0
- ommlds/cli/sessions/chat/tools/weather/configs.py +12 -0
- ommlds/cli/sessions/chat/tools/weather/inject.py +22 -0
- ommlds/cli/{tools/weather.py → sessions/chat/tools/weather/tools.py} +1 -1
- ommlds/cli/sessions/completion/configs.py +21 -0
- ommlds/cli/sessions/completion/inject.py +42 -0
- ommlds/cli/sessions/completion/session.py +35 -0
- ommlds/cli/sessions/embedding/configs.py +21 -0
- ommlds/cli/sessions/embedding/inject.py +42 -0
- ommlds/cli/sessions/embedding/session.py +33 -0
- ommlds/cli/sessions/inject.py +28 -11
- ommlds/cli/state/__init__.py +0 -0
- ommlds/cli/state/inject.py +28 -0
- ommlds/cli/{state.py → state/storage.py} +41 -24
- ommlds/minichain/__init__.py +84 -24
- ommlds/minichain/_dataclasses.py +15401 -0
- ommlds/minichain/_marshal.py +49 -9
- ommlds/minichain/_typedvalues.py +2 -4
- ommlds/minichain/backends/catalogs/base.py +20 -1
- ommlds/minichain/backends/catalogs/simple.py +2 -2
- ommlds/minichain/backends/catalogs/strings.py +10 -8
- ommlds/minichain/backends/impls/anthropic/chat.py +65 -27
- ommlds/minichain/backends/impls/anthropic/names.py +10 -8
- ommlds/minichain/backends/impls/anthropic/protocol.py +109 -0
- ommlds/minichain/backends/impls/anthropic/stream.py +111 -43
- ommlds/minichain/backends/impls/duckduckgo/search.py +6 -2
- ommlds/minichain/backends/impls/dummy/__init__.py +0 -0
- ommlds/minichain/backends/impls/dummy/chat.py +69 -0
- ommlds/minichain/backends/impls/google/chat.py +114 -22
- ommlds/minichain/backends/impls/google/search.py +7 -2
- ommlds/minichain/backends/impls/google/stream.py +219 -0
- ommlds/minichain/backends/impls/google/tools.py +149 -0
- ommlds/minichain/backends/impls/groq/__init__.py +0 -0
- ommlds/minichain/backends/impls/groq/chat.py +75 -0
- ommlds/minichain/backends/impls/groq/names.py +48 -0
- ommlds/minichain/backends/impls/groq/protocol.py +143 -0
- ommlds/minichain/backends/impls/groq/stream.py +125 -0
- ommlds/minichain/backends/impls/huggingface/repos.py +1 -5
- ommlds/minichain/backends/impls/llamacpp/chat.py +40 -22
- ommlds/minichain/backends/impls/llamacpp/completion.py +9 -5
- ommlds/minichain/backends/impls/llamacpp/format.py +4 -2
- ommlds/minichain/backends/impls/llamacpp/stream.py +43 -23
- ommlds/minichain/backends/impls/mistral.py +20 -5
- ommlds/minichain/backends/impls/mlx/chat.py +101 -24
- ommlds/minichain/backends/impls/ollama/__init__.py +0 -0
- ommlds/minichain/backends/impls/ollama/chat.py +199 -0
- ommlds/minichain/backends/impls/openai/chat.py +18 -8
- ommlds/minichain/backends/impls/openai/completion.py +10 -3
- ommlds/minichain/backends/impls/openai/embedding.py +10 -3
- ommlds/minichain/backends/impls/openai/format.py +131 -106
- ommlds/minichain/backends/impls/openai/names.py +31 -5
- ommlds/minichain/backends/impls/openai/stream.py +43 -25
- ommlds/minichain/backends/impls/sentencepiece/tokens.py +9 -6
- ommlds/minichain/backends/impls/tavily.py +66 -0
- ommlds/minichain/backends/impls/tinygrad/chat.py +30 -20
- ommlds/minichain/backends/impls/tokenizers/tokens.py +9 -6
- ommlds/minichain/backends/impls/transformers/sentence.py +6 -3
- ommlds/minichain/backends/impls/transformers/tokens.py +10 -7
- ommlds/minichain/backends/impls/transformers/transformers.py +160 -37
- ommlds/minichain/backends/strings/parsing.py +1 -1
- ommlds/minichain/backends/strings/resolving.py +4 -1
- ommlds/minichain/chat/_marshal.py +16 -9
- ommlds/minichain/chat/choices/adapters.py +4 -4
- ommlds/minichain/chat/choices/services.py +1 -1
- ommlds/minichain/chat/choices/stream/__init__.py +0 -0
- ommlds/minichain/chat/choices/stream/adapters.py +35 -0
- ommlds/minichain/chat/choices/stream/joining.py +31 -0
- ommlds/minichain/chat/choices/stream/services.py +45 -0
- ommlds/minichain/chat/choices/stream/types.py +43 -0
- ommlds/minichain/chat/choices/types.py +2 -2
- ommlds/minichain/chat/history.py +3 -3
- ommlds/minichain/chat/messages.py +55 -19
- ommlds/minichain/chat/services.py +3 -3
- ommlds/minichain/chat/stream/_marshal.py +16 -0
- ommlds/minichain/chat/stream/joining.py +85 -0
- ommlds/minichain/chat/stream/services.py +15 -21
- ommlds/minichain/chat/stream/types.py +32 -19
- ommlds/minichain/chat/tools/execution.py +8 -7
- ommlds/minichain/chat/tools/ids.py +9 -15
- ommlds/minichain/chat/tools/parsing.py +17 -26
- ommlds/minichain/chat/transforms/base.py +29 -38
- ommlds/minichain/chat/transforms/metadata.py +30 -4
- ommlds/minichain/chat/transforms/services.py +9 -11
- ommlds/minichain/content/_marshal.py +44 -20
- ommlds/minichain/content/json.py +13 -0
- ommlds/minichain/content/materialize.py +14 -21
- ommlds/minichain/content/prepare.py +4 -0
- ommlds/minichain/content/transforms/interleave.py +1 -1
- ommlds/minichain/content/transforms/squeeze.py +1 -1
- ommlds/minichain/content/transforms/stringify.py +1 -1
- ommlds/minichain/json.py +20 -0
- ommlds/minichain/lib/code/__init__.py +0 -0
- ommlds/minichain/lib/code/prompts.py +6 -0
- ommlds/minichain/lib/fs/binfiles.py +108 -0
- ommlds/minichain/lib/fs/context.py +126 -0
- ommlds/minichain/lib/fs/errors.py +101 -0
- ommlds/minichain/lib/fs/suggestions.py +36 -0
- ommlds/minichain/lib/fs/tools/__init__.py +0 -0
- ommlds/minichain/lib/fs/tools/edit.py +104 -0
- ommlds/minichain/lib/fs/tools/ls.py +38 -0
- ommlds/minichain/lib/fs/tools/read.py +115 -0
- ommlds/minichain/lib/fs/tools/recursivels/__init__.py +0 -0
- ommlds/minichain/lib/fs/tools/recursivels/execution.py +40 -0
- ommlds/minichain/lib/todo/__init__.py +0 -0
- ommlds/minichain/lib/todo/context.py +54 -0
- ommlds/minichain/lib/todo/tools/__init__.py +0 -0
- ommlds/minichain/lib/todo/tools/read.py +44 -0
- ommlds/minichain/lib/todo/tools/write.py +335 -0
- ommlds/minichain/lib/todo/types.py +60 -0
- ommlds/minichain/llms/_marshal.py +25 -17
- ommlds/minichain/llms/types.py +4 -0
- ommlds/minichain/registries/globals.py +18 -4
- ommlds/minichain/resources.py +68 -45
- ommlds/minichain/search.py +1 -1
- ommlds/minichain/services/_marshal.py +46 -39
- ommlds/minichain/services/facades.py +3 -3
- ommlds/minichain/services/services.py +1 -1
- ommlds/minichain/standard.py +8 -0
- ommlds/minichain/stream/services.py +152 -38
- ommlds/minichain/stream/wrap.py +22 -24
- ommlds/minichain/text/toolparsing/llamacpp/hermes2.py +3 -2
- ommlds/minichain/text/toolparsing/llamacpp/llama31.py +3 -2
- ommlds/minichain/text/toolparsing/llamacpp/utils.py +3 -2
- ommlds/minichain/tools/_marshal.py +1 -1
- ommlds/minichain/tools/execution/catalog.py +2 -1
- ommlds/minichain/tools/execution/context.py +34 -14
- ommlds/minichain/tools/execution/errors.py +15 -0
- ommlds/minichain/tools/execution/executors.py +8 -3
- ommlds/minichain/tools/execution/reflect.py +40 -5
- ommlds/minichain/tools/fns.py +46 -9
- ommlds/minichain/tools/jsonschema.py +14 -5
- ommlds/minichain/tools/reflect.py +54 -18
- ommlds/minichain/tools/types.py +33 -1
- ommlds/minichain/utils.py +27 -0
- ommlds/minichain/vectors/_marshal.py +11 -10
- ommlds/minichain/vectors/types.py +1 -1
- ommlds/nanochat/LICENSE +21 -0
- ommlds/nanochat/__init__.py +0 -0
- ommlds/nanochat/rustbpe/LICENSE +21 -0
- ommlds/nanochat/tokenizers.py +406 -0
- ommlds/server/cli.py +1 -2
- ommlds/server/server.py +5 -5
- ommlds/server/service.py +1 -1
- ommlds/specs/__init__.py +0 -0
- ommlds/specs/mcp/__init__.py +0 -0
- ommlds/specs/mcp/_marshal.py +23 -0
- ommlds/specs/mcp/clients.py +146 -0
- ommlds/specs/mcp/protocol.py +371 -0
- ommlds/tools/git.py +35 -12
- ommlds/tools/ocr.py +8 -9
- ommlds/wiki/analyze.py +6 -7
- ommlds/wiki/text/mfh.py +1 -5
- ommlds/wiki/text/wtp.py +1 -3
- ommlds/wiki/utils/xml.py +5 -5
- {ommlds-0.0.0.dev426.dist-info → ommlds-0.0.0.dev485.dist-info}/METADATA +24 -21
- ommlds-0.0.0.dev485.dist-info/RECORD +436 -0
- ommlds/cli/backends/standard.py +0 -20
- ommlds/cli/sessions/chat/base.py +0 -42
- ommlds/cli/sessions/chat/interactive.py +0 -73
- ommlds/cli/sessions/chat/printing.py +0 -96
- ommlds/cli/sessions/chat/prompt.py +0 -143
- ommlds/cli/sessions/chat/state.py +0 -109
- ommlds/cli/sessions/chat/tools.py +0 -91
- ommlds/cli/sessions/completion/completion.py +0 -44
- ommlds/cli/sessions/embedding/embedding.py +0 -42
- ommlds/cli/tools/config.py +0 -13
- ommlds/cli/tools/inject.py +0 -64
- ommlds/minichain/chat/stream/adapters.py +0 -69
- ommlds/minichain/lib/fs/ls/execution.py +0 -32
- ommlds-0.0.0.dev426.dist-info/RECORD +0 -303
- /ommlds/{cli/tools → backends/google}/__init__.py +0 -0
- /ommlds/{huggingface.py → backends/huggingface.py} +0 -0
- /ommlds/{minichain/lib/fs/ls → cli/content}/__init__.py +0 -0
- /ommlds/minichain/lib/fs/{ls → tools/recursivels}/rendering.py +0 -0
- /ommlds/minichain/lib/fs/{ls → tools/recursivels}/running.py +0 -0
- {ommlds-0.0.0.dev426.dist-info → ommlds-0.0.0.dev485.dist-info}/WHEEL +0 -0
- {ommlds-0.0.0.dev426.dist-info → ommlds-0.0.0.dev485.dist-info}/entry_points.txt +0 -0
- {ommlds-0.0.0.dev426.dist-info → ommlds-0.0.0.dev485.dist-info}/licenses/LICENSE +0 -0
- {ommlds-0.0.0.dev426.dist-info → ommlds-0.0.0.dev485.dist-info}/top_level.txt +0 -0
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import abc
|
|
2
|
-
import typing as ta
|
|
3
|
-
|
|
4
|
-
from omlish import check
|
|
5
|
-
from omlish import lang
|
|
6
|
-
|
|
7
|
-
from .... import minichain as mc
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if ta.TYPE_CHECKING:
|
|
11
|
-
from omdev import ptk
|
|
12
|
-
from omdev.ptk import markdown as ptk_md
|
|
13
|
-
else:
|
|
14
|
-
ptk = lang.proxy_import('omdev.ptk')
|
|
15
|
-
ptk_md = lang.proxy_import('omdev.ptk.markdown')
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
##
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class ChatSessionPrinter(lang.Abstract):
|
|
22
|
-
@abc.abstractmethod
|
|
23
|
-
def print(self, obj: mc.Message | mc.Content) -> None:
|
|
24
|
-
raise NotImplementedError
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
##
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class StringChatSessionPrinter(ChatSessionPrinter, lang.Abstract):
|
|
31
|
-
@abc.abstractmethod
|
|
32
|
-
def _print_str(self, s: str) -> None:
|
|
33
|
-
raise NotImplementedError
|
|
34
|
-
|
|
35
|
-
def print(self, obj: mc.Message | mc.Content) -> None:
|
|
36
|
-
if obj is None:
|
|
37
|
-
pass
|
|
38
|
-
|
|
39
|
-
elif isinstance(obj, mc.Message):
|
|
40
|
-
if isinstance(obj, mc.SystemMessage):
|
|
41
|
-
if obj.c is not None:
|
|
42
|
-
self._print_str(check.isinstance(obj.c, str))
|
|
43
|
-
elif isinstance(obj, mc.UserMessage):
|
|
44
|
-
if obj.c is not None:
|
|
45
|
-
self._print_str(check.isinstance(obj.c, str))
|
|
46
|
-
elif isinstance(obj, mc.AiMessage):
|
|
47
|
-
if obj.c is not None:
|
|
48
|
-
self._print_str(check.isinstance(obj.c, str))
|
|
49
|
-
elif isinstance(obj, mc.ToolExecResultMessage):
|
|
50
|
-
self._print_str(check.isinstance(obj.c, str))
|
|
51
|
-
else:
|
|
52
|
-
raise TypeError(obj)
|
|
53
|
-
|
|
54
|
-
elif isinstance(obj, str):
|
|
55
|
-
self._print_str(obj)
|
|
56
|
-
|
|
57
|
-
else:
|
|
58
|
-
raise TypeError(obj)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
##
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
class SimpleStringChatSessionPrinter(StringChatSessionPrinter):
|
|
65
|
-
def __init__(
|
|
66
|
-
self,
|
|
67
|
-
*,
|
|
68
|
-
str_printer: ta.Callable[[str], None] | None = None,
|
|
69
|
-
) -> None:
|
|
70
|
-
super().__init__()
|
|
71
|
-
|
|
72
|
-
if str_printer is None:
|
|
73
|
-
str_printer = print
|
|
74
|
-
self._str_printer = str_printer
|
|
75
|
-
|
|
76
|
-
def _print_str(self, s: str) -> None:
|
|
77
|
-
s = s.strip()
|
|
78
|
-
if not s:
|
|
79
|
-
return
|
|
80
|
-
|
|
81
|
-
self._str_printer(s)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
##
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
class MarkdownStringChatSessionPrinter(StringChatSessionPrinter):
|
|
88
|
-
def _print_str(self, s: str) -> None:
|
|
89
|
-
s = s.strip()
|
|
90
|
-
if not s:
|
|
91
|
-
return
|
|
92
|
-
|
|
93
|
-
ptk.print_formatted_text(
|
|
94
|
-
ptk_md.Markdown(s),
|
|
95
|
-
style=ptk.Style(list(ptk_md.MARKDOWN_STYLE)),
|
|
96
|
-
)
|
|
@@ -1,143 +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 ChatOptions
|
|
9
|
-
from .base import ChatSession
|
|
10
|
-
from .printing import ChatSessionPrinter
|
|
11
|
-
from .state import ChatStateManager
|
|
12
|
-
from .tools import ToolExecRequestExecutor
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
##
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class ToolExecutionRequestDeniedError(Exception):
|
|
19
|
-
pass
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class PromptChatSession(ChatSession['PromptChatSession.Config']):
|
|
23
|
-
@dc.dataclass(frozen=True)
|
|
24
|
-
class Config(ChatSession.Config): # noqa
|
|
25
|
-
content: mc.Content
|
|
26
|
-
|
|
27
|
-
_: dc.KW_ONLY
|
|
28
|
-
|
|
29
|
-
new: bool = False
|
|
30
|
-
|
|
31
|
-
backend: str | None = None
|
|
32
|
-
model_name: str | None = None
|
|
33
|
-
|
|
34
|
-
stream: bool = False
|
|
35
|
-
|
|
36
|
-
def __init__(
|
|
37
|
-
self,
|
|
38
|
-
config: Config,
|
|
39
|
-
*,
|
|
40
|
-
state_manager: ChatStateManager,
|
|
41
|
-
chat_options: ChatOptions | None = None,
|
|
42
|
-
printer: ChatSessionPrinter,
|
|
43
|
-
backend_catalog: mc.BackendCatalog,
|
|
44
|
-
tool_exec_request_executor: ToolExecRequestExecutor,
|
|
45
|
-
) -> None:
|
|
46
|
-
super().__init__(config)
|
|
47
|
-
|
|
48
|
-
self._state_manager = state_manager
|
|
49
|
-
self._chat_options = chat_options
|
|
50
|
-
self._printer = printer
|
|
51
|
-
self._backend_catalog = backend_catalog
|
|
52
|
-
self._tool_exec_request_executor = tool_exec_request_executor
|
|
53
|
-
|
|
54
|
-
async def run(self) -> None:
|
|
55
|
-
if self._config.stream:
|
|
56
|
-
await self._run_stream()
|
|
57
|
-
else:
|
|
58
|
-
await self._run_immediate()
|
|
59
|
-
|
|
60
|
-
async def _run_stream(self) -> None:
|
|
61
|
-
prompt = check.isinstance(self._config.content, str)
|
|
62
|
-
|
|
63
|
-
if self._config.new:
|
|
64
|
-
state = self._state_manager.clear_state()
|
|
65
|
-
else:
|
|
66
|
-
state = self._state_manager.get_state()
|
|
67
|
-
|
|
68
|
-
new_chat: list[mc.Message] = [
|
|
69
|
-
mc.UserMessage(prompt),
|
|
70
|
-
]
|
|
71
|
-
|
|
72
|
-
mdl: mc.ChatChoicesStreamService
|
|
73
|
-
with lang.maybe_managing(self._backend_catalog.get_backend(
|
|
74
|
-
mc.ChatChoicesStreamService,
|
|
75
|
-
self._config.backend or DEFAULT_CHAT_MODEL_BACKEND,
|
|
76
|
-
*([mc.ModelName(mn)] if (mn := self._config.model_name) is not None else []),
|
|
77
|
-
)) as mdl:
|
|
78
|
-
with mdl.invoke(mc.ChatChoicesStreamRequest(
|
|
79
|
-
[*state.chat, *new_chat],
|
|
80
|
-
(self._chat_options or []),
|
|
81
|
-
)).v as st_resp:
|
|
82
|
-
lst: list[str] = []
|
|
83
|
-
for o in st_resp:
|
|
84
|
-
if o:
|
|
85
|
-
m = check.single(o).m
|
|
86
|
-
if m.c is not None:
|
|
87
|
-
print(check.isinstance(m.c, str), end='', flush=True)
|
|
88
|
-
lst.append(check.isinstance(m.c, str))
|
|
89
|
-
check.none(m.tool_exec_requests)
|
|
90
|
-
print()
|
|
91
|
-
|
|
92
|
-
resp_m = mc.AiMessage(''.join(lst))
|
|
93
|
-
new_chat.append(resp_m)
|
|
94
|
-
|
|
95
|
-
self._state_manager.extend_chat(new_chat)
|
|
96
|
-
|
|
97
|
-
async def _run_immediate(self) -> None:
|
|
98
|
-
prompt = check.isinstance(self._config.content, str)
|
|
99
|
-
|
|
100
|
-
if self._config.new:
|
|
101
|
-
state = self._state_manager.clear_state()
|
|
102
|
-
else:
|
|
103
|
-
state = self._state_manager.get_state()
|
|
104
|
-
|
|
105
|
-
new_chat: list[mc.Message] = [
|
|
106
|
-
mc.UserMessage(prompt),
|
|
107
|
-
]
|
|
108
|
-
|
|
109
|
-
mdl: mc.ChatChoicesService
|
|
110
|
-
with lang.maybe_managing(self._backend_catalog.get_backend(
|
|
111
|
-
mc.ChatChoicesService,
|
|
112
|
-
self._config.backend or DEFAULT_CHAT_MODEL_BACKEND,
|
|
113
|
-
*([mc.ModelName(mn)] if (mn := self._config.model_name) is not None else []),
|
|
114
|
-
)) as mdl:
|
|
115
|
-
response: mc.ChatChoicesResponse = mdl.invoke(mc.ChatChoicesRequest(
|
|
116
|
-
[*state.chat, *new_chat],
|
|
117
|
-
(self._chat_options or []),
|
|
118
|
-
))
|
|
119
|
-
|
|
120
|
-
resp_m = response.v[0].m
|
|
121
|
-
new_chat.append(resp_m)
|
|
122
|
-
|
|
123
|
-
if (trs := resp_m.tool_exec_requests):
|
|
124
|
-
check.state(resp_m.c is None)
|
|
125
|
-
|
|
126
|
-
tr: mc.ToolExecRequest = check.single(check.not_none(trs))
|
|
127
|
-
|
|
128
|
-
trm = await self._tool_exec_request_executor.execute_tool_request(tr)
|
|
129
|
-
|
|
130
|
-
print(trm.c)
|
|
131
|
-
new_chat.append(trm)
|
|
132
|
-
|
|
133
|
-
response = mdl.invoke(mc.ChatChoicesRequest(
|
|
134
|
-
[*state.chat, *new_chat],
|
|
135
|
-
(self._chat_options or []),
|
|
136
|
-
))
|
|
137
|
-
|
|
138
|
-
resp_m = response.v[0].m
|
|
139
|
-
new_chat.append(resp_m)
|
|
140
|
-
|
|
141
|
-
self._printer.print(resp_m)
|
|
142
|
-
|
|
143
|
-
self._state_manager.extend_chat(new_chat)
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import abc
|
|
2
|
-
import dataclasses as dc
|
|
3
|
-
import datetime
|
|
4
|
-
|
|
5
|
-
from omlish import check
|
|
6
|
-
from omlish import lang
|
|
7
|
-
|
|
8
|
-
from .... import minichain as mc
|
|
9
|
-
from ...state import StateStorage
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
##
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
@dc.dataclass(frozen=True)
|
|
16
|
-
class ChatState:
|
|
17
|
-
name: str | None = None
|
|
18
|
-
|
|
19
|
-
created_at: datetime.datetime = dc.field(default_factory=lang.utcnow)
|
|
20
|
-
updated_at: datetime.datetime = dc.field(default_factory=lang.utcnow)
|
|
21
|
-
|
|
22
|
-
chat: mc.Chat = ()
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
##
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class ChatStateManager(lang.Abstract):
|
|
29
|
-
@abc.abstractmethod
|
|
30
|
-
def get_state(self) -> ChatState:
|
|
31
|
-
raise NotImplementedError
|
|
32
|
-
|
|
33
|
-
@abc.abstractmethod
|
|
34
|
-
def clear_state(self) -> ChatState:
|
|
35
|
-
raise NotImplementedError
|
|
36
|
-
|
|
37
|
-
@abc.abstractmethod
|
|
38
|
-
def extend_chat(self, chat_additions: mc.Chat) -> ChatState:
|
|
39
|
-
raise NotImplementedError
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
##
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
class InMemoryChatStateManager(ChatStateManager):
|
|
46
|
-
def __init__(self, initial_state: ChatState | None = None) -> None:
|
|
47
|
-
super().__init__()
|
|
48
|
-
|
|
49
|
-
if initial_state is None:
|
|
50
|
-
initial_state = ChatState()
|
|
51
|
-
self._state = initial_state
|
|
52
|
-
|
|
53
|
-
def get_state(self) -> ChatState:
|
|
54
|
-
return self._state
|
|
55
|
-
|
|
56
|
-
def clear_state(self) -> ChatState:
|
|
57
|
-
self._state = ChatState()
|
|
58
|
-
return self._state
|
|
59
|
-
|
|
60
|
-
def extend_chat(self, chat_additions: mc.Chat) -> ChatState:
|
|
61
|
-
self._state = dc.replace(
|
|
62
|
-
self._state,
|
|
63
|
-
chat=[*self._state.chat, *chat_additions],
|
|
64
|
-
updated_at=lang.utcnow(),
|
|
65
|
-
)
|
|
66
|
-
return self._state
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
##
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
class StateStorageChatStateManager(ChatStateManager):
|
|
73
|
-
def __init__(
|
|
74
|
-
self,
|
|
75
|
-
*,
|
|
76
|
-
storage: StateStorage,
|
|
77
|
-
key: str = 'chat',
|
|
78
|
-
) -> None:
|
|
79
|
-
super().__init__()
|
|
80
|
-
|
|
81
|
-
self._storage = storage
|
|
82
|
-
self._key = check.non_empty_str(key)
|
|
83
|
-
|
|
84
|
-
self._state: ChatState | None = None
|
|
85
|
-
|
|
86
|
-
def get_state(self) -> ChatState:
|
|
87
|
-
if self._state is not None:
|
|
88
|
-
return self._state
|
|
89
|
-
state: ChatState | None = self._storage.load_state(self._key, ChatState)
|
|
90
|
-
if state is None:
|
|
91
|
-
state = ChatState()
|
|
92
|
-
self._state = state
|
|
93
|
-
return state
|
|
94
|
-
|
|
95
|
-
def clear_state(self) -> ChatState:
|
|
96
|
-
state = ChatState()
|
|
97
|
-
self._storage.save_state(self._key, state, ChatState)
|
|
98
|
-
self._state = state
|
|
99
|
-
return state
|
|
100
|
-
|
|
101
|
-
def extend_chat(self, chat_additions: mc.Chat) -> ChatState:
|
|
102
|
-
state = self.get_state()
|
|
103
|
-
state = dc.replace(
|
|
104
|
-
state,
|
|
105
|
-
chat=[*state.chat, *chat_additions],
|
|
106
|
-
updated_at=lang.utcnow(),
|
|
107
|
-
)
|
|
108
|
-
self._storage.save_state(self._key, state, ChatState)
|
|
109
|
-
return state
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import abc
|
|
2
|
-
import typing as ta
|
|
3
|
-
|
|
4
|
-
from omlish import check
|
|
5
|
-
from omlish import lang
|
|
6
|
-
from omlish import marshal as msh
|
|
7
|
-
from omlish.formats import json
|
|
8
|
-
|
|
9
|
-
from .... import minichain as mc
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if ta.TYPE_CHECKING:
|
|
13
|
-
from omdev import ptk
|
|
14
|
-
else:
|
|
15
|
-
ptk = lang.proxy_import('omdev.ptk')
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
##
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class ToolExecutionRequestDeniedError(Exception):
|
|
22
|
-
pass
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class ToolExecutionConfirmation(lang.Abstract):
|
|
26
|
-
@abc.abstractmethod
|
|
27
|
-
def confirm_tool_execution_or_raise(
|
|
28
|
-
self,
|
|
29
|
-
tr: mc.ToolExecRequest,
|
|
30
|
-
tce: mc.ToolCatalogEntry,
|
|
31
|
-
) -> ta.Awaitable[None]:
|
|
32
|
-
raise NotImplementedError
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
class NopToolExecutionConfirmation(ToolExecutionConfirmation):
|
|
36
|
-
async def confirm_tool_execution_or_raise(
|
|
37
|
-
self,
|
|
38
|
-
tr: mc.ToolExecRequest,
|
|
39
|
-
tce: mc.ToolCatalogEntry,
|
|
40
|
-
) -> None:
|
|
41
|
-
pass
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
class AskingToolExecutionConfirmation(ToolExecutionConfirmation):
|
|
45
|
-
async def confirm_tool_execution_or_raise(
|
|
46
|
-
self,
|
|
47
|
-
tr: mc.ToolExecRequest,
|
|
48
|
-
tce: mc.ToolCatalogEntry,
|
|
49
|
-
) -> None:
|
|
50
|
-
tr_dct = dict(
|
|
51
|
-
id=tr.id,
|
|
52
|
-
spec=msh.marshal(tce.spec),
|
|
53
|
-
args=tr.args,
|
|
54
|
-
)
|
|
55
|
-
cr = await ptk.strict_confirm(f'Execute requested tool?\n\n{json.dumps_pretty(tr_dct)}\n\n')
|
|
56
|
-
|
|
57
|
-
if not cr:
|
|
58
|
-
raise ToolExecutionRequestDeniedError
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
##
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
class ToolExecRequestExecutor(lang.Abstract):
|
|
65
|
-
@abc.abstractmethod
|
|
66
|
-
def execute_tool_request(self, tr: mc.ToolExecRequest) -> ta.Awaitable[mc.ToolExecResultMessage]:
|
|
67
|
-
raise NotImplementedError
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
class ToolExecRequestExecutorImpl(ToolExecRequestExecutor):
|
|
71
|
-
def __init__(
|
|
72
|
-
self,
|
|
73
|
-
*,
|
|
74
|
-
catalog: mc.ToolCatalog,
|
|
75
|
-
confirmation: ToolExecutionConfirmation,
|
|
76
|
-
) -> None:
|
|
77
|
-
super().__init__()
|
|
78
|
-
|
|
79
|
-
self._catalog = catalog
|
|
80
|
-
self._confirmation = confirmation
|
|
81
|
-
|
|
82
|
-
async def execute_tool_request(self, tr: mc.ToolExecRequest) -> mc.ToolExecResultMessage:
|
|
83
|
-
tce = self._catalog.by_name[check.non_empty_str(tr.name)]
|
|
84
|
-
|
|
85
|
-
await self._confirmation.confirm_tool_execution_or_raise(tr, tce)
|
|
86
|
-
|
|
87
|
-
return await mc.execute_tool_request(
|
|
88
|
-
mc.ToolContext(),
|
|
89
|
-
tce.executor(),
|
|
90
|
-
tr,
|
|
91
|
-
)
|
|
@@ -1,44 +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 Session
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
##
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
DEFAULT_COMPLETION_MODEL_BACKEND = 'openai'
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class CompletionSession(Session['CompletionSession.Config']):
|
|
17
|
-
@dc.dataclass(frozen=True)
|
|
18
|
-
class Config(Session.Config):
|
|
19
|
-
content: mc.Content
|
|
20
|
-
|
|
21
|
-
_: dc.KW_ONLY
|
|
22
|
-
|
|
23
|
-
backend: str | None = None
|
|
24
|
-
|
|
25
|
-
def __init__(
|
|
26
|
-
self,
|
|
27
|
-
config: Config,
|
|
28
|
-
*,
|
|
29
|
-
backend_catalog: mc.BackendCatalog,
|
|
30
|
-
) -> None:
|
|
31
|
-
super().__init__(config)
|
|
32
|
-
|
|
33
|
-
self._backend_catalog = backend_catalog
|
|
34
|
-
|
|
35
|
-
async def run(self) -> None:
|
|
36
|
-
prompt = check.isinstance(self._config.content, str)
|
|
37
|
-
|
|
38
|
-
mdl: mc.CompletionService
|
|
39
|
-
with lang.maybe_managing(self._backend_catalog.get_backend(
|
|
40
|
-
mc.CompletionService,
|
|
41
|
-
self._config.backend or DEFAULT_COMPLETION_MODEL_BACKEND,
|
|
42
|
-
)) as mdl:
|
|
43
|
-
response = mdl.invoke(mc.CompletionRequest(prompt))
|
|
44
|
-
print(response.v.strip())
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import dataclasses as dc
|
|
2
|
-
|
|
3
|
-
from omlish import lang
|
|
4
|
-
from omlish.formats import json
|
|
5
|
-
|
|
6
|
-
from .... import minichain as mc
|
|
7
|
-
from ..base import Session
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
##
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
DEFAULT_EMBEDDING_MODEL_BACKEND = 'openai'
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class EmbeddingSession(Session['EmbeddingSession.Config']):
|
|
17
|
-
@dc.dataclass(frozen=True)
|
|
18
|
-
class Config(Session.Config):
|
|
19
|
-
content: mc.Content
|
|
20
|
-
|
|
21
|
-
_: dc.KW_ONLY
|
|
22
|
-
|
|
23
|
-
backend: str | None = None
|
|
24
|
-
|
|
25
|
-
def __init__(
|
|
26
|
-
self,
|
|
27
|
-
config: Config,
|
|
28
|
-
*,
|
|
29
|
-
backend_catalog: mc.BackendCatalog,
|
|
30
|
-
) -> None:
|
|
31
|
-
super().__init__(config)
|
|
32
|
-
|
|
33
|
-
self._backend_catalog = backend_catalog
|
|
34
|
-
|
|
35
|
-
async def run(self) -> None:
|
|
36
|
-
mdl: mc.EmbeddingService
|
|
37
|
-
with lang.maybe_managing(self._backend_catalog.get_backend(
|
|
38
|
-
mc.EmbeddingService,
|
|
39
|
-
self._config.backend or DEFAULT_EMBEDDING_MODEL_BACKEND,
|
|
40
|
-
)) as mdl:
|
|
41
|
-
response = mdl.invoke(mc.EmbeddingRequest(self._config.content))
|
|
42
|
-
print(json.dumps_compact(list(map(float, response.v))))
|
ommlds/cli/tools/config.py
DELETED
ommlds/cli/tools/inject.py
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import dataclasses as dc
|
|
2
|
-
import typing as ta
|
|
3
|
-
|
|
4
|
-
from omlish import inject as inj
|
|
5
|
-
from omlish import lang
|
|
6
|
-
|
|
7
|
-
from ... import minichain as mc
|
|
8
|
-
from ..sessions.chat.inject import bind_chat_options
|
|
9
|
-
from .config import ToolsConfig
|
|
10
|
-
from .weather import WEATHER_TOOL
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
##
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
@dc.dataclass(frozen=True, eq=False)
|
|
17
|
-
class _InjectedTool:
|
|
18
|
-
tce: mc.ToolCatalogEntry
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def bind_tool(tce: mc.ToolCatalogEntry) -> inj.Element | inj.Elements:
|
|
22
|
-
return inj.as_elements(
|
|
23
|
-
inj.bind_set_entry_const(ta.AbstractSet[_InjectedTool], _InjectedTool(tce)),
|
|
24
|
-
|
|
25
|
-
bind_chat_options(mc.Tool(tce.spec)),
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
##
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def bind_tools(tools_config: ToolsConfig) -> inj.Elements:
|
|
33
|
-
els: list[inj.Elemental] = [
|
|
34
|
-
inj.bind(tools_config),
|
|
35
|
-
|
|
36
|
-
inj.bind(mc.ToolCatalog, singleton=True),
|
|
37
|
-
|
|
38
|
-
inj.set_binder[_InjectedTool](),
|
|
39
|
-
inj.bind(
|
|
40
|
-
lang.typed_lambda(mc.ToolCatalogEntries, s=ta.AbstractSet[_InjectedTool])(
|
|
41
|
-
lambda s: [it.tce for it in s],
|
|
42
|
-
),
|
|
43
|
-
singleton=True,
|
|
44
|
-
),
|
|
45
|
-
]
|
|
46
|
-
|
|
47
|
-
#
|
|
48
|
-
|
|
49
|
-
if tools_config.enable_fs_tools:
|
|
50
|
-
from ...minichain.lib.fs.ls.execution import ls_tool
|
|
51
|
-
|
|
52
|
-
els.append(bind_tool(ls_tool()))
|
|
53
|
-
|
|
54
|
-
if tools_config.enable_unsafe_bash_tool:
|
|
55
|
-
from ...minichain.lib.bash import bash_tool
|
|
56
|
-
|
|
57
|
-
els.append(bind_tool(bash_tool()))
|
|
58
|
-
|
|
59
|
-
if tools_config.enable_test_weather_tool:
|
|
60
|
-
els.append(bind_tool(WEATHER_TOOL))
|
|
61
|
-
|
|
62
|
-
#
|
|
63
|
-
|
|
64
|
-
return inj.as_elements(*els)
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import typing as ta
|
|
2
|
-
|
|
3
|
-
from omlish import check
|
|
4
|
-
from omlish import dataclasses as dc
|
|
5
|
-
|
|
6
|
-
from ...services import Response
|
|
7
|
-
from ..choices.services import ChatChoicesRequest
|
|
8
|
-
from ..choices.services import static_check_is_chat_choices_service
|
|
9
|
-
from ..choices.types import AiChoice
|
|
10
|
-
from ..choices.types import AiChoices
|
|
11
|
-
from ..messages import AiMessage
|
|
12
|
-
from ..messages import ToolExecRequest
|
|
13
|
-
from .services import ChatChoicesOutputs
|
|
14
|
-
from .services import ChatChoicesStreamOutputs
|
|
15
|
-
from .services import ChatChoicesStreamService
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
##
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
@static_check_is_chat_choices_service
|
|
22
|
-
@dc.dataclass(frozen=True)
|
|
23
|
-
class ChatChoicesStreamServiceChatChoicesService:
|
|
24
|
-
service: ChatChoicesStreamService
|
|
25
|
-
|
|
26
|
-
class _Choice(ta.NamedTuple):
|
|
27
|
-
parts: list[str]
|
|
28
|
-
trs: list[ToolExecRequest]
|
|
29
|
-
|
|
30
|
-
def invoke(self, request: ChatChoicesRequest) -> Response[
|
|
31
|
-
AiChoices,
|
|
32
|
-
ChatChoicesOutputs | ChatChoicesStreamOutputs,
|
|
33
|
-
]:
|
|
34
|
-
lst: list[ChatChoicesStreamServiceChatChoicesService._Choice] = []
|
|
35
|
-
|
|
36
|
-
resp = self.service.invoke(request)
|
|
37
|
-
with resp.v as resp_v:
|
|
38
|
-
i = -1 # noqa
|
|
39
|
-
for i, cs in enumerate(resp_v):
|
|
40
|
-
if i == 0:
|
|
41
|
-
for c in cs:
|
|
42
|
-
m = c.m
|
|
43
|
-
lst.append(self._Choice(
|
|
44
|
-
[check.isinstance(m.c, str)] if m.c is not None else [],
|
|
45
|
-
# FIXME
|
|
46
|
-
# list(m.tool_exec_requests or []),
|
|
47
|
-
[],
|
|
48
|
-
))
|
|
49
|
-
|
|
50
|
-
else:
|
|
51
|
-
for ch, c in zip(lst, cs, strict=True):
|
|
52
|
-
m = c.m
|
|
53
|
-
if m.c is not None:
|
|
54
|
-
ch.parts.append(check.isinstance(m.c, str))
|
|
55
|
-
# FIXME
|
|
56
|
-
# if m.tool_exec_requests:
|
|
57
|
-
# ch.trs.extend(m.tool_exec_requests)
|
|
58
|
-
|
|
59
|
-
check.state(resp_v.is_done)
|
|
60
|
-
|
|
61
|
-
ret: list[AiChoice] = []
|
|
62
|
-
for ch in lst:
|
|
63
|
-
ret.append(AiChoice(AiMessage(
|
|
64
|
-
''.join(ch.parts) if ch.parts else None,
|
|
65
|
-
ch.trs or None,
|
|
66
|
-
)))
|
|
67
|
-
|
|
68
|
-
# FIXME: outputs lol
|
|
69
|
-
return Response(ret)
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
from omlish import lang
|
|
2
|
-
|
|
3
|
-
from ....tools.execution.catalog import ToolCatalogEntry
|
|
4
|
-
from ....tools.execution.reflect import reflect_tool_catalog_entry
|
|
5
|
-
from .rendering import LsLinesRenderer
|
|
6
|
-
from .running import LsRunner
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def execute_ls_tool(
|
|
13
|
-
base_path: str,
|
|
14
|
-
) -> str:
|
|
15
|
-
"""
|
|
16
|
-
Recursively lists the directory contents of the given base path.
|
|
17
|
-
|
|
18
|
-
Args:
|
|
19
|
-
base_path: The path of the directory to list the contents of.
|
|
20
|
-
|
|
21
|
-
Returns:
|
|
22
|
-
A formatted string of the recursive directory contents.
|
|
23
|
-
"""
|
|
24
|
-
|
|
25
|
-
root = LsRunner().run(base_path)
|
|
26
|
-
lines = LsLinesRenderer().render(root)
|
|
27
|
-
return '\n'.join(lines.lines)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
@lang.cached_function
|
|
31
|
-
def ls_tool() -> ToolCatalogEntry:
|
|
32
|
-
return reflect_tool_catalog_entry(execute_ls_tool)
|