ommlds 0.0.0.dev436__py3-none-any.whl → 0.0.0.dev480__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 +332 -35
- ommlds/__about__.py +15 -9
- 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/_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 +30 -9
- ommlds/backends/google/protocol/__init__.py +3 -0
- ommlds/backends/google/protocol/_marshal.py +16 -0
- ommlds/backends/google/protocol/types.py +626 -0
- ommlds/backends/groq/_marshal.py +23 -0
- ommlds/backends/groq/protocol.py +249 -0
- ommlds/backends/mlx/generation.py +1 -1
- ommlds/backends/mlx/loading.py +58 -1
- ommlds/backends/ollama/__init__.py +0 -0
- ommlds/backends/ollama/protocol.py +170 -0
- ommlds/backends/openai/protocol/__init__.py +9 -28
- ommlds/backends/openai/protocol/_common.py +18 -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 +0 -0
- ommlds/backends/tavily/protocol.py +301 -0
- ommlds/backends/tinygrad/models/llama3/__init__.py +22 -14
- ommlds/backends/transformers/__init__.py +0 -0
- ommlds/backends/transformers/filecache.py +109 -0
- ommlds/backends/transformers/streamers.py +73 -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/__init__.py +0 -0
- ommlds/cli/content/messages.py +34 -0
- ommlds/cli/content/strings.py +42 -0
- ommlds/cli/inject.py +15 -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/_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 +1 -1
- 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/llamacpp/chat.py +33 -18
- ommlds/minichain/backends/impls/llamacpp/completion.py +1 -1
- ommlds/minichain/backends/impls/llamacpp/format.py +4 -2
- ommlds/minichain/backends/impls/llamacpp/stream.py +37 -20
- ommlds/minichain/backends/impls/mistral.py +20 -5
- ommlds/minichain/backends/impls/mlx/chat.py +96 -22
- 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/tavily.py +66 -0
- ommlds/minichain/backends/impls/tinygrad/chat.py +23 -16
- ommlds/minichain/backends/impls/transformers/sentence.py +1 -1
- ommlds/minichain/backends/impls/transformers/tokens.py +1 -1
- ommlds/minichain/backends/impls/transformers/transformers.py +155 -34
- 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 +66 -43
- 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/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/nanochat/LICENSE +21 -0
- ommlds/nanochat/__init__.py +0 -0
- ommlds/nanochat/rustbpe/LICENSE +21 -0
- ommlds/nanochat/tokenizers.py +406 -0
- ommlds/server/server.py +3 -3
- ommlds/specs/__init__.py +0 -0
- ommlds/specs/mcp/__init__.py +0 -0
- ommlds/specs/mcp/_marshal.py +23 -0
- ommlds/specs/mcp/protocol.py +266 -0
- ommlds/tools/git.py +27 -10
- ommlds/tools/ocr.py +8 -9
- ommlds/wiki/analyze.py +2 -2
- 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.dev436.dist-info → ommlds-0.0.0.dev480.dist-info}/METADATA +24 -21
- ommlds-0.0.0.dev480.dist-info/RECORD +427 -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.dev436.dist-info/RECORD +0 -303
- /ommlds/{cli/tools → backends/google}/__init__.py +0 -0
- /ommlds/{minichain/lib/fs/ls → backends/groq}/__init__.py +0 -0
- /ommlds/{huggingface.py → backends/huggingface.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.dev436.dist-info → ommlds-0.0.0.dev480.dist-info}/WHEEL +0 -0
- {ommlds-0.0.0.dev436.dist-info → ommlds-0.0.0.dev480.dist-info}/entry_points.txt +0 -0
- {ommlds-0.0.0.dev436.dist-info → ommlds-0.0.0.dev480.dist-info}/licenses/LICENSE +0 -0
- {ommlds-0.0.0.dev436.dist-info → ommlds-0.0.0.dev480.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import typing as ta
|
|
2
|
+
|
|
3
|
+
from omlish import dataclasses as dc
|
|
4
|
+
from omlish import inject as inj
|
|
5
|
+
from omlish import lang
|
|
6
|
+
|
|
7
|
+
from ..... import minichain as mc
|
|
8
|
+
from .configs import ToolSetConfig
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
with lang.auto_proxy_import(globals()):
|
|
12
|
+
from . import execution as _execution
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
ToolSetConfigT = ta.TypeVar('ToolSetConfigT', bound='ToolSetConfig')
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
##
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@lang.cached_function
|
|
22
|
+
def tool_catalog_entries() -> 'inj.ItemsBinderHelper[mc.ToolCatalogEntry]':
|
|
23
|
+
return inj.items_binder_helper[mc.ToolCatalogEntry](mc.ToolCatalogEntries)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@lang.cached_function
|
|
27
|
+
def tool_context_providers() -> 'inj.ItemsBinderHelper[_execution.ToolContextProvider]':
|
|
28
|
+
return inj.items_binder_helper[_execution.ToolContextProvider](_execution.ToolContextProviders)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def bind_tool_context_provider_to_key(key: ta.Any) -> inj.Elements:
|
|
32
|
+
return tool_context_providers().bind_item(to_fn=inj.KwargsTarget.of(
|
|
33
|
+
lambda v: _execution.ToolContextProvider(lambda: [v]),
|
|
34
|
+
v=key,
|
|
35
|
+
), singleton=True)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
##
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@dc.dataclass(frozen=True)
|
|
42
|
+
class ToolSetBinder(lang.Final, ta.Generic[ToolSetConfigT]):
|
|
43
|
+
cfg_cls: type[ToolSetConfig]
|
|
44
|
+
fn: ta.Callable[[ToolSetConfigT], inj.Elements]
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import typing as ta
|
|
2
|
+
|
|
3
|
+
from ..... import minichain as mc
|
|
4
|
+
from ....rendering.types import ContentRendering
|
|
5
|
+
from .execution import ToolUseExecutor
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
##
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ArgsRenderingToolUseExecutor(ToolUseExecutor):
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
*,
|
|
15
|
+
wrapped: ToolUseExecutor,
|
|
16
|
+
renderer: ContentRendering,
|
|
17
|
+
) -> None:
|
|
18
|
+
super().__init__()
|
|
19
|
+
|
|
20
|
+
self._wrapped = wrapped
|
|
21
|
+
self._renderer = renderer
|
|
22
|
+
|
|
23
|
+
async def execute_tool_use(
|
|
24
|
+
self,
|
|
25
|
+
use: 'mc.ToolUse',
|
|
26
|
+
*ctx_items: ta.Any,
|
|
27
|
+
) -> 'mc.ToolUseResultMessage':
|
|
28
|
+
await self._renderer.render_content(mc.JsonContent(dict(
|
|
29
|
+
id=use.id,
|
|
30
|
+
name=use.name,
|
|
31
|
+
args=use.args,
|
|
32
|
+
)))
|
|
33
|
+
|
|
34
|
+
return await self._wrapped.execute_tool_use(use, *ctx_items)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class ResultRenderingToolUseExecutor(ToolUseExecutor):
|
|
38
|
+
def __init__(
|
|
39
|
+
self,
|
|
40
|
+
*,
|
|
41
|
+
wrapped: ToolUseExecutor,
|
|
42
|
+
renderer: ContentRendering,
|
|
43
|
+
) -> None:
|
|
44
|
+
super().__init__()
|
|
45
|
+
|
|
46
|
+
self._wrapped = wrapped
|
|
47
|
+
self._renderer = renderer
|
|
48
|
+
|
|
49
|
+
async def execute_tool_use(
|
|
50
|
+
self,
|
|
51
|
+
use: 'mc.ToolUse',
|
|
52
|
+
*ctx_items: ta.Any,
|
|
53
|
+
) -> 'mc.ToolUseResultMessage':
|
|
54
|
+
out = await self._wrapped.execute_tool_use(use, *ctx_items)
|
|
55
|
+
|
|
56
|
+
await self._renderer.render_content(out.tur.c)
|
|
57
|
+
|
|
58
|
+
return out
|
|
File without changes
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from omlish import inject as inj
|
|
2
|
+
|
|
3
|
+
from ..injection import ToolSetBinder
|
|
4
|
+
from ..injection import bind_tool_context_provider_to_key
|
|
5
|
+
from ..injection import tool_catalog_entries
|
|
6
|
+
from .configs import TodoToolSetConfig
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
##
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def bind_todo_tools(cfg: TodoToolSetConfig) -> inj.Elements:
|
|
13
|
+
from ......minichain.lib.todo.context import TodoContext
|
|
14
|
+
from ......minichain.lib.todo.tools.read import todo_read_tool
|
|
15
|
+
from ......minichain.lib.todo.tools.write import todo_write_tool
|
|
16
|
+
|
|
17
|
+
return inj.as_elements(
|
|
18
|
+
tool_catalog_entries().bind_item_consts(
|
|
19
|
+
todo_read_tool(),
|
|
20
|
+
todo_write_tool(),
|
|
21
|
+
),
|
|
22
|
+
|
|
23
|
+
inj.bind(TodoContext()),
|
|
24
|
+
bind_tool_context_provider_to_key(TodoContext),
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
##
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
TODO_TOOL_SET_BINDER = ToolSetBinder(TodoToolSetConfig, bind_todo_tools)
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from omlish import inject as inj
|
|
2
|
+
|
|
3
|
+
from ..injection import ToolSetBinder
|
|
4
|
+
from ..injection import tool_catalog_entries
|
|
5
|
+
from .configs import WeatherToolSetConfig
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
##
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def bind_weather_tools(cfg: WeatherToolSetConfig) -> inj.Elements:
|
|
12
|
+
from .tools import WEATHER_TOOL
|
|
13
|
+
|
|
14
|
+
return inj.as_elements(
|
|
15
|
+
tool_catalog_entries().bind_item_consts(WEATHER_TOOL),
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
##
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
WEATHER_TOOL_SET_BINDER = ToolSetBinder(WeatherToolSetConfig, bind_weather_tools)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from omlish import dataclasses as dc
|
|
2
|
+
|
|
3
|
+
from .... import minichain as mc
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
##
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
DEFAULT_BACKEND = 'openai'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
##
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dc.dataclass(frozen=True)
|
|
16
|
+
class CompletionConfig:
|
|
17
|
+
content: 'mc.Content'
|
|
18
|
+
|
|
19
|
+
_: dc.KW_ONLY
|
|
20
|
+
|
|
21
|
+
backend: str | None = None
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from omlish import dataclasses as dc
|
|
2
|
+
from omlish import inject as inj
|
|
3
|
+
from omlish import lang
|
|
4
|
+
|
|
5
|
+
from ...backends.configs import BackendConfig
|
|
6
|
+
from ...backends.types import DefaultBackendName
|
|
7
|
+
from ..base import Session
|
|
8
|
+
from .configs import DEFAULT_BACKEND
|
|
9
|
+
from .configs import CompletionConfig
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
with lang.auto_proxy_import(globals()):
|
|
13
|
+
from ...backends import inject as _backends
|
|
14
|
+
from . import session as _session
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
##
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def bind_completion(cfg: CompletionConfig) -> inj.Elements:
|
|
21
|
+
els: list[inj.Elemental] = []
|
|
22
|
+
|
|
23
|
+
#
|
|
24
|
+
|
|
25
|
+
els.extend([
|
|
26
|
+
inj.bind(_session.CompletionSession.Config(**dc.asdict(cfg))),
|
|
27
|
+
inj.bind(Session, to_ctor=_session.CompletionSession, singleton=True),
|
|
28
|
+
])
|
|
29
|
+
|
|
30
|
+
#
|
|
31
|
+
|
|
32
|
+
els.extend([
|
|
33
|
+
_backends.bind_backends(BackendConfig(
|
|
34
|
+
backend=cfg.backend,
|
|
35
|
+
)),
|
|
36
|
+
|
|
37
|
+
inj.bind(DefaultBackendName, to_const=DEFAULT_BACKEND),
|
|
38
|
+
])
|
|
39
|
+
|
|
40
|
+
#
|
|
41
|
+
|
|
42
|
+
return inj.as_elements(*els)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from omlish import check
|
|
2
|
+
from omlish import dataclasses as dc
|
|
3
|
+
|
|
4
|
+
from .... import minichain as mc
|
|
5
|
+
from ...backends.types import CompletionServiceBackendProvider
|
|
6
|
+
from ..base import Session
|
|
7
|
+
from .configs import CompletionConfig
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
##
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class CompletionSession(Session['CompletionSession.Config']):
|
|
14
|
+
@dc.dataclass(frozen=True)
|
|
15
|
+
class Config(Session.Config, CompletionConfig):
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
config: Config,
|
|
21
|
+
*,
|
|
22
|
+
service_provider: CompletionServiceBackendProvider,
|
|
23
|
+
) -> None:
|
|
24
|
+
super().__init__(config)
|
|
25
|
+
|
|
26
|
+
self._service_provider = service_provider
|
|
27
|
+
|
|
28
|
+
async def run(self) -> None:
|
|
29
|
+
prompt = check.isinstance(self._config.content, str)
|
|
30
|
+
|
|
31
|
+
mdl: mc.CompletionService
|
|
32
|
+
async with self._service_provider.provide_backend() as mdl:
|
|
33
|
+
response = await mdl.invoke(mc.CompletionRequest(prompt))
|
|
34
|
+
|
|
35
|
+
print(response.v.strip())
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from omlish import dataclasses as dc
|
|
2
|
+
|
|
3
|
+
from .... import minichain as mc
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
##
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
DEFAULT_BACKEND = 'openai'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
##
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dc.dataclass(frozen=True)
|
|
16
|
+
class EmbeddingConfig:
|
|
17
|
+
content: 'mc.Content'
|
|
18
|
+
|
|
19
|
+
_: dc.KW_ONLY
|
|
20
|
+
|
|
21
|
+
backend: str | None = None
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from omlish import dataclasses as dc
|
|
2
|
+
from omlish import inject as inj
|
|
3
|
+
from omlish import lang
|
|
4
|
+
|
|
5
|
+
from ...backends.configs import BackendConfig
|
|
6
|
+
from ...backends.types import DefaultBackendName
|
|
7
|
+
from ..base import Session
|
|
8
|
+
from .configs import DEFAULT_BACKEND
|
|
9
|
+
from .configs import EmbeddingConfig
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
with lang.auto_proxy_import(globals()):
|
|
13
|
+
from ...backends import inject as _backends
|
|
14
|
+
from . import session as _session
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
##
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def bind_embedding(cfg: EmbeddingConfig) -> inj.Elements:
|
|
21
|
+
els: list[inj.Elemental] = []
|
|
22
|
+
|
|
23
|
+
#
|
|
24
|
+
|
|
25
|
+
els.extend([
|
|
26
|
+
inj.bind(_session.EmbeddingSession.Config(**dc.asdict(cfg))),
|
|
27
|
+
inj.bind(Session, to_ctor=_session.EmbeddingSession, singleton=True),
|
|
28
|
+
])
|
|
29
|
+
|
|
30
|
+
#
|
|
31
|
+
|
|
32
|
+
els.extend([
|
|
33
|
+
_backends.bind_backends(BackendConfig(
|
|
34
|
+
backend=cfg.backend,
|
|
35
|
+
)),
|
|
36
|
+
|
|
37
|
+
inj.bind(DefaultBackendName, to_const=DEFAULT_BACKEND),
|
|
38
|
+
])
|
|
39
|
+
|
|
40
|
+
#
|
|
41
|
+
|
|
42
|
+
return inj.as_elements(*els)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from omlish import dataclasses as dc
|
|
2
|
+
from omlish.formats import json
|
|
3
|
+
|
|
4
|
+
from .... import minichain as mc
|
|
5
|
+
from ...backends.types import EmbeddingServiceBackendProvider
|
|
6
|
+
from ..base import Session
|
|
7
|
+
from .configs import EmbeddingConfig
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
##
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class EmbeddingSession(Session['EmbeddingSession.Config']):
|
|
14
|
+
@dc.dataclass(frozen=True)
|
|
15
|
+
class Config(Session.Config, EmbeddingConfig):
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
config: Config,
|
|
21
|
+
*,
|
|
22
|
+
service_provider: EmbeddingServiceBackendProvider,
|
|
23
|
+
) -> None:
|
|
24
|
+
super().__init__(config)
|
|
25
|
+
|
|
26
|
+
self._service_provider = service_provider
|
|
27
|
+
|
|
28
|
+
async def run(self) -> None:
|
|
29
|
+
mdl: mc.EmbeddingService
|
|
30
|
+
async with self._service_provider.provide_backend() as mdl:
|
|
31
|
+
response = await mdl.invoke(mc.EmbeddingRequest(self._config.content))
|
|
32
|
+
|
|
33
|
+
print(json.dumps_compact(list(map(float, response.v))))
|
ommlds/cli/sessions/inject.py
CHANGED
|
@@ -1,21 +1,38 @@
|
|
|
1
|
+
import typing as ta
|
|
2
|
+
|
|
1
3
|
from omlish import inject as inj
|
|
4
|
+
from omlish import lang
|
|
5
|
+
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
from .chat
|
|
5
|
-
from .chat
|
|
7
|
+
with lang.auto_proxy_import(globals()):
|
|
8
|
+
from .chat import configs as _chat_cfgs
|
|
9
|
+
from .chat import inject as _chat_inj
|
|
10
|
+
from .completion import configs as _completion_cfgs
|
|
11
|
+
from .completion import inject as _completion_inj
|
|
12
|
+
from .embedding import configs as _embedding_cfgs
|
|
13
|
+
from .embedding import inject as _embedding_inj
|
|
6
14
|
|
|
7
15
|
|
|
8
16
|
##
|
|
9
17
|
|
|
10
18
|
|
|
11
|
-
def bind_sessions(
|
|
12
|
-
els: list[inj.Elemental] = [
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
def bind_sessions(cfg: ta.Any) -> inj.Elements:
|
|
20
|
+
els: list[inj.Elemental] = []
|
|
21
|
+
|
|
22
|
+
#
|
|
23
|
+
|
|
24
|
+
if isinstance(cfg, _chat_cfgs.ChatConfig):
|
|
25
|
+
els.append(_chat_inj.bind_chat(cfg))
|
|
26
|
+
|
|
27
|
+
elif isinstance(cfg, _completion_cfgs.CompletionConfig):
|
|
28
|
+
els.append(_completion_inj.bind_completion(cfg))
|
|
29
|
+
|
|
30
|
+
elif isinstance(cfg, _embedding_cfgs.EmbeddingConfig):
|
|
31
|
+
els.append(_embedding_inj.bind_embedding(cfg))
|
|
32
|
+
|
|
33
|
+
else:
|
|
34
|
+
raise TypeError(cfg)
|
|
17
35
|
|
|
18
|
-
|
|
19
|
-
els.append(bind_chat_session(session_cfg))
|
|
36
|
+
#
|
|
20
37
|
|
|
21
38
|
return inj.as_elements(*els)
|
|
File without changes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import os.path
|
|
2
|
+
|
|
3
|
+
from omdev.home.paths import get_home_paths
|
|
4
|
+
from omlish import inject as inj
|
|
5
|
+
from omlish import lang
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
with lang.auto_proxy_import(globals()):
|
|
9
|
+
from . import storage as _storage
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
##
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _provide_state_storage() -> '_storage.StateStorage':
|
|
16
|
+
state_dir = os.path.join(get_home_paths().state_dir, 'minichain', 'cli')
|
|
17
|
+
if not os.path.exists(state_dir):
|
|
18
|
+
os.makedirs(state_dir, exist_ok=True)
|
|
19
|
+
os.chmod(state_dir, 0o770) # noqa
|
|
20
|
+
|
|
21
|
+
state_file = os.path.join(state_dir, 'state.json')
|
|
22
|
+
return _storage.JsonFileStateStorage(state_file)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def bind_state() -> inj.Elements:
|
|
26
|
+
return inj.as_elements(
|
|
27
|
+
inj.bind(_provide_state_storage, singleton=True),
|
|
28
|
+
)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import abc
|
|
2
|
-
import dataclasses as dc
|
|
3
2
|
import os.path
|
|
4
3
|
import typing as ta
|
|
5
4
|
|
|
5
|
+
from omlish import dataclasses as dc
|
|
6
6
|
from omlish import lang
|
|
7
7
|
from omlish import marshal as msh
|
|
8
8
|
from omlish.formats import json
|
|
@@ -14,6 +14,38 @@ T = ta.TypeVar('T')
|
|
|
14
14
|
##
|
|
15
15
|
|
|
16
16
|
|
|
17
|
+
class StateStorage(lang.Abstract):
|
|
18
|
+
@abc.abstractmethod
|
|
19
|
+
def load_state(self, key: str, ty: type[T] | None) -> ta.Awaitable[T | None]:
|
|
20
|
+
raise NotImplementedError
|
|
21
|
+
|
|
22
|
+
@abc.abstractmethod
|
|
23
|
+
def save_state(self, key: str, obj: ta.Any | None, ty: type[T] | None) -> ta.Awaitable[None]:
|
|
24
|
+
raise NotImplementedError
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
##
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class InMemoryStateStorage(StateStorage):
|
|
31
|
+
def __init__(self) -> None:
|
|
32
|
+
super().__init__()
|
|
33
|
+
|
|
34
|
+
self._dct: dict[str, ta.Any] = {}
|
|
35
|
+
|
|
36
|
+
async def load_state(self, key: str, ty: type[T] | None) -> T | None:
|
|
37
|
+
return self._dct.get(key)
|
|
38
|
+
|
|
39
|
+
async def save_state(self, key: str, obj: ta.Any | None, ty: type[T] | None) -> None:
|
|
40
|
+
if obj is None:
|
|
41
|
+
self._dct.pop(key, None)
|
|
42
|
+
else:
|
|
43
|
+
self._dct[key] = obj
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
##
|
|
47
|
+
|
|
48
|
+
|
|
17
49
|
STATE_VERSION = 0
|
|
18
50
|
|
|
19
51
|
|
|
@@ -23,10 +55,7 @@ class MarshaledState:
|
|
|
23
55
|
payload: ta.Any
|
|
24
56
|
|
|
25
57
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class StateStorage(lang.Abstract):
|
|
58
|
+
class MarshalStateStorage(StateStorage, lang.Abstract):
|
|
30
59
|
def __init__(
|
|
31
60
|
self,
|
|
32
61
|
*,
|
|
@@ -36,36 +65,24 @@ class StateStorage(lang.Abstract):
|
|
|
36
65
|
|
|
37
66
|
self._version = version
|
|
38
67
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def unmarshal_state(self, obj: ta.Any, ty: type[T] | None = None) -> T | None:
|
|
68
|
+
def _unmarshal_state(self, obj: ta.Any, ty: type[T] | None = None) -> T | None:
|
|
42
69
|
ms = msh.unmarshal(obj, MarshaledState)
|
|
43
70
|
if ms.version < self._version:
|
|
44
71
|
return None
|
|
45
72
|
return msh.unmarshal(ms.payload, ty)
|
|
46
73
|
|
|
47
|
-
def
|
|
74
|
+
def _marshal_state(self, obj: ta.Any, ty: type | None = None) -> ta.Any:
|
|
48
75
|
ms = MarshaledState(
|
|
49
76
|
version=self._version,
|
|
50
77
|
payload=msh.marshal(obj, ty),
|
|
51
78
|
)
|
|
52
79
|
return msh.marshal(ms)
|
|
53
80
|
|
|
54
|
-
#
|
|
55
|
-
|
|
56
|
-
@abc.abstractmethod
|
|
57
|
-
def load_state(self, key: str, ty: type[T] | None) -> T | None:
|
|
58
|
-
raise NotImplementedError
|
|
59
|
-
|
|
60
|
-
@abc.abstractmethod
|
|
61
|
-
def save_state(self, key: str, obj: ta.Any | None, ty: type[T] | None) -> None:
|
|
62
|
-
raise NotImplementedError
|
|
63
|
-
|
|
64
81
|
|
|
65
82
|
#
|
|
66
83
|
|
|
67
84
|
|
|
68
|
-
class JsonFileStateStorage(
|
|
85
|
+
class JsonFileStateStorage(MarshalStateStorage):
|
|
69
86
|
def __init__(
|
|
70
87
|
self,
|
|
71
88
|
file: str,
|
|
@@ -91,19 +108,19 @@ class JsonFileStateStorage(StateStorage):
|
|
|
91
108
|
|
|
92
109
|
#
|
|
93
110
|
|
|
94
|
-
def load_state(self, key: str, ty: type[T] | None) -> T | None:
|
|
111
|
+
async def load_state(self, key: str, ty: type[T] | None) -> T | None:
|
|
95
112
|
if not (data := self._load_file_data()):
|
|
96
113
|
return None
|
|
97
114
|
if (dct := data.get(key)) is None:
|
|
98
115
|
return None
|
|
99
|
-
return self.
|
|
116
|
+
return self._unmarshal_state(dct, ty)
|
|
100
117
|
|
|
101
|
-
def save_state(self, key: str, obj: ta.Any | None, ty: type[T] | None) -> None:
|
|
118
|
+
async def save_state(self, key: str, obj: ta.Any | None, ty: type[T] | None) -> None:
|
|
102
119
|
if (data := self._load_file_data()) is None:
|
|
103
120
|
data = {}
|
|
104
121
|
if obj is None:
|
|
105
122
|
data.pop(key, None)
|
|
106
123
|
else:
|
|
107
|
-
dct = self.
|
|
124
|
+
dct = self._marshal_state(obj, ty)
|
|
108
125
|
data[key] = dct
|
|
109
126
|
self._save_file_data(data)
|