ommlds 0.0.0.dev440__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.dev440.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.dev440.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.dev440.dist-info → ommlds-0.0.0.dev480.dist-info}/WHEEL +0 -0
- {ommlds-0.0.0.dev440.dist-info → ommlds-0.0.0.dev480.dist-info}/entry_points.txt +0 -0
- {ommlds-0.0.0.dev440.dist-info → ommlds-0.0.0.dev480.dist-info}/licenses/LICENSE +0 -0
- {ommlds-0.0.0.dev440.dist-info → ommlds-0.0.0.dev480.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"""
|
|
2
|
+
https://modelcontextprotocol.io/specification/2025-06-18
|
|
3
|
+
https://modelcontextprotocol.io/specification/2025-06-18/schema
|
|
4
|
+
"""
|
|
5
|
+
import abc
|
|
6
|
+
import typing as ta
|
|
7
|
+
|
|
8
|
+
from omlish import collections as col
|
|
9
|
+
from omlish import dataclasses as dc
|
|
10
|
+
from omlish import lang
|
|
11
|
+
from omlish import marshal as msh
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
msh.register_global_module_import('._marshal', __package__)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
##
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _set_class_marshal_options(cls):
|
|
21
|
+
msh.update_object_metadata(
|
|
22
|
+
cls,
|
|
23
|
+
field_naming=msh.Naming.LOW_CAMEL,
|
|
24
|
+
field_defaults=msh.FieldMetadata(
|
|
25
|
+
options=msh.FieldOptions(
|
|
26
|
+
omit_if=lang.is_none,
|
|
27
|
+
),
|
|
28
|
+
),
|
|
29
|
+
)
|
|
30
|
+
return cls
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
##
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
37
|
+
class Message(lang.Sealed, lang.Abstract):
|
|
38
|
+
@property
|
|
39
|
+
@abc.abstractmethod
|
|
40
|
+
def json_rpc_method_name(self) -> str:
|
|
41
|
+
raise NotImplementedError
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class ClientRequest(Message, lang.Abstract):
|
|
45
|
+
pass
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class ClientResult(Message, lang.Abstract):
|
|
49
|
+
pass
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class ServerRequest(Message, lang.Abstract):
|
|
53
|
+
pass
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class ServerResult(Message, lang.Abstract):
|
|
57
|
+
pass
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class Notification(Message, lang.Abstract):
|
|
61
|
+
pass
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
#
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
68
|
+
class WithMeta(lang.Sealed, lang.Abstract):
|
|
69
|
+
meta_: ta.Mapping[str, ta.Any] | None = dc.field(default=None) | msh.with_field_metadata(name='_meta')
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
##
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
76
|
+
@_set_class_marshal_options
|
|
77
|
+
class Implementation(lang.Final):
|
|
78
|
+
name: str
|
|
79
|
+
version: str
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
DEFAULT_PROTOCOL_VERSION = '2025-06-18'
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
86
|
+
@_set_class_marshal_options
|
|
87
|
+
class ClientCapabilities:
|
|
88
|
+
elicitation: ta.Any | None = None
|
|
89
|
+
|
|
90
|
+
experimental: ta.Mapping[str, ta.Any] | None = None
|
|
91
|
+
|
|
92
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
93
|
+
@_set_class_marshal_options
|
|
94
|
+
class Roots:
|
|
95
|
+
list_changed: bool | None = None
|
|
96
|
+
|
|
97
|
+
roots: Roots | None = None
|
|
98
|
+
|
|
99
|
+
sampling: ta.Any | None = None
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
103
|
+
@_set_class_marshal_options
|
|
104
|
+
class InitializeRequest(ClientRequest):
|
|
105
|
+
json_rpc_method_name: ta.ClassVar[str] = 'initialize'
|
|
106
|
+
|
|
107
|
+
client_info: Implementation
|
|
108
|
+
protocol_version: str = DEFAULT_PROTOCOL_VERSION
|
|
109
|
+
capabilities: ClientCapabilities = ClientCapabilities()
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
113
|
+
@_set_class_marshal_options
|
|
114
|
+
class ServerCapabilities:
|
|
115
|
+
completions: ta.Any | None = None
|
|
116
|
+
|
|
117
|
+
experimental: ta.Mapping[str, ta.Any] | None = None
|
|
118
|
+
|
|
119
|
+
logging: ta.Any | None = None
|
|
120
|
+
|
|
121
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
122
|
+
@_set_class_marshal_options
|
|
123
|
+
class Prompts:
|
|
124
|
+
list_changed: bool | None = None
|
|
125
|
+
|
|
126
|
+
prompts: Prompts | None = None
|
|
127
|
+
|
|
128
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
129
|
+
@_set_class_marshal_options
|
|
130
|
+
class Resources:
|
|
131
|
+
list_changed: bool | None = None
|
|
132
|
+
subscribe: bool | None = None
|
|
133
|
+
|
|
134
|
+
resources: Resources | None = None
|
|
135
|
+
|
|
136
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
137
|
+
@_set_class_marshal_options
|
|
138
|
+
class Tools:
|
|
139
|
+
list_changed: bool | None = None
|
|
140
|
+
|
|
141
|
+
tools: Tools | None = None
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
145
|
+
@_set_class_marshal_options
|
|
146
|
+
class InitializeResult(ClientResult, WithMeta):
|
|
147
|
+
json_rpc_method_name: ta.ClassVar[str] = 'initialize'
|
|
148
|
+
|
|
149
|
+
server_info: Implementation
|
|
150
|
+
protocol_version: str
|
|
151
|
+
capabilities: ServerCapabilities
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
155
|
+
@_set_class_marshal_options
|
|
156
|
+
class InitializedNotification(Notification):
|
|
157
|
+
json_rpc_method_name: ta.ClassVar[str] = 'initialized'
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
##
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
164
|
+
@_set_class_marshal_options
|
|
165
|
+
class ToolAnnotations(lang.Final):
|
|
166
|
+
destructive_hint: bool | None = None
|
|
167
|
+
idempotent_hint: bool | None = None
|
|
168
|
+
open_world_hint: bool | None = None
|
|
169
|
+
read_only_hint: bool | None = None
|
|
170
|
+
title: str | None = None
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
174
|
+
@_set_class_marshal_options
|
|
175
|
+
class Tool(lang.Final):
|
|
176
|
+
name: str
|
|
177
|
+
title: str | None = None
|
|
178
|
+
|
|
179
|
+
description: str | None = None
|
|
180
|
+
|
|
181
|
+
annotations: ToolAnnotations | None = None
|
|
182
|
+
|
|
183
|
+
input_schema: ta.Any
|
|
184
|
+
output_schema: ta.Any | None = None
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
188
|
+
@_set_class_marshal_options
|
|
189
|
+
class ListToolsRequest(ClientRequest):
|
|
190
|
+
json_rpc_method_name: ta.ClassVar[str] = 'tools/list'
|
|
191
|
+
|
|
192
|
+
cursor: str | None = None
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
196
|
+
@_set_class_marshal_options
|
|
197
|
+
class ListToolsResult(ClientResult, WithMeta):
|
|
198
|
+
json_rpc_method_name: ta.ClassVar[str] = 'tools/list'
|
|
199
|
+
|
|
200
|
+
tools: ta.Sequence[Tool]
|
|
201
|
+
next_cursor: str | None = None
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
##
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
class ContentBlock(lang.Abstract):
|
|
208
|
+
pass
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
212
|
+
@_set_class_marshal_options
|
|
213
|
+
class TextContentBlock(ContentBlock, lang.Final):
|
|
214
|
+
text: str
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
##
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
221
|
+
@_set_class_marshal_options
|
|
222
|
+
class CallToolRequest(ClientRequest):
|
|
223
|
+
json_rpc_method_name: ta.ClassVar[str] = 'tools/call'
|
|
224
|
+
|
|
225
|
+
name: str
|
|
226
|
+
arguments: ta.Mapping[str, ta.Any] | None = None
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
230
|
+
@_set_class_marshal_options
|
|
231
|
+
class CallToolResult(ClientResult, WithMeta):
|
|
232
|
+
json_rpc_method_name: ta.ClassVar[str] = 'tools/call'
|
|
233
|
+
|
|
234
|
+
content: ta.Sequence[ContentBlock]
|
|
235
|
+
is_error: bool | None = None
|
|
236
|
+
structured_content: ta.Mapping[str, ta.Any] | None = None
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
##
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
243
|
+
@_set_class_marshal_options
|
|
244
|
+
class PingRequest(ClientRequest, WithMeta):
|
|
245
|
+
json_rpc_method_name: ta.ClassVar[str] = 'ping'
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
249
|
+
@_set_class_marshal_options
|
|
250
|
+
class PingResult(ClientResult):
|
|
251
|
+
json_rpc_method_name: ta.ClassVar[str] = 'ping'
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
##
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
MESSAGE_TYPES_BY_JSON_RPC_METHOD_NAME: ta.Mapping[type[Message], ta.Mapping[str, type[Message]]] = {
|
|
258
|
+
bty: col.make_map_by(lambda mty: mty.json_rpc_method_name, lang.deep_subclasses(bty, concrete_only=True)) # type: ignore # noqa
|
|
259
|
+
for bty in [
|
|
260
|
+
ClientRequest,
|
|
261
|
+
ClientResult,
|
|
262
|
+
ServerRequest,
|
|
263
|
+
ServerResult,
|
|
264
|
+
Notification,
|
|
265
|
+
]
|
|
266
|
+
}
|
ommlds/tools/git.py
CHANGED
|
@@ -16,6 +16,7 @@ from omdev.tools.git.messages import GitMessageGenerator
|
|
|
16
16
|
from omlish import check
|
|
17
17
|
from omlish import lang
|
|
18
18
|
from omlish.configs.classes import Configurable
|
|
19
|
+
from omlish.http import all as http
|
|
19
20
|
from omlish.subprocesses.sync import subprocesses
|
|
20
21
|
|
|
21
22
|
from .. import minichain as mc
|
|
@@ -23,10 +24,8 @@ from ..minichain.backends.impls.openai.chat import OpenaiChatChoicesService
|
|
|
23
24
|
from ..server.client import McServerClient
|
|
24
25
|
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
with lang.auto_proxy_import(globals()):
|
|
27
28
|
from ..minichain.backends.impls.mlx import chat as mc_mlx_chat
|
|
28
|
-
else:
|
|
29
|
-
mc_mlx_chat = lang.proxy_import('..minichain.backends.impls.mlx.chat', __package__)
|
|
30
29
|
|
|
31
30
|
|
|
32
31
|
GitAiBackendConfigT = ta.TypeVar('GitAiBackendConfigT', bound='GitAiBackend.Config')
|
|
@@ -45,6 +44,22 @@ class GitAiBackend(Configurable[GitAiBackendConfigT], lang.Abstract):
|
|
|
45
44
|
raise NotImplementedError
|
|
46
45
|
|
|
47
46
|
|
|
47
|
+
def _get_single_ai_message_str(resp: mc.ChatChoicesResponse) -> str:
|
|
48
|
+
return check.not_empty(
|
|
49
|
+
check.isinstance(
|
|
50
|
+
check.isinstance(
|
|
51
|
+
check.single(
|
|
52
|
+
check.single(
|
|
53
|
+
resp.v,
|
|
54
|
+
).ms,
|
|
55
|
+
),
|
|
56
|
+
mc.AiMessage,
|
|
57
|
+
).c,
|
|
58
|
+
str,
|
|
59
|
+
),
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
48
63
|
#
|
|
49
64
|
|
|
50
65
|
|
|
@@ -62,13 +77,15 @@ class OpenaiGitAiBackend(GitAiBackend['OpenaiGitAiBackend.Config']):
|
|
|
62
77
|
if (sec := load_secrets().try_get(key.lower())) is not None:
|
|
63
78
|
os.environ[key] = sec.reveal()
|
|
64
79
|
|
|
65
|
-
llm = OpenaiChatChoicesService(
|
|
80
|
+
llm = OpenaiChatChoicesService(
|
|
81
|
+
http_client=http.SyncAsyncHttpClient(http.client()),
|
|
82
|
+
)
|
|
66
83
|
|
|
67
|
-
resp = llm.invoke(mc.ChatChoicesRequest(
|
|
84
|
+
resp = lang.sync_await(llm.invoke(mc.ChatChoicesRequest(
|
|
68
85
|
[mc.UserMessage(prompt)],
|
|
69
86
|
# FIXME: *((MaxTokens(self._config.max_tokens),) if self._config.max_tokens is not None else ()),
|
|
70
|
-
))
|
|
71
|
-
return
|
|
87
|
+
)))
|
|
88
|
+
return _get_single_ai_message_str(resp)
|
|
72
89
|
|
|
73
90
|
|
|
74
91
|
#
|
|
@@ -93,11 +110,11 @@ class MlxGitAiBackend(GitAiBackend['MlxGitAiBackend.Config']):
|
|
|
93
110
|
|
|
94
111
|
def _run_prompt(self, prompt: str) -> str:
|
|
95
112
|
with mc_mlx_chat.MlxChatChoicesService(mc.ModelRepo.parse(self._config.model)) as llm:
|
|
96
|
-
resp = llm.invoke(mc.ChatChoicesRequest(
|
|
113
|
+
resp = lang.sync_await(llm.invoke(mc.ChatChoicesRequest(
|
|
97
114
|
[mc.UserMessage(prompt)],
|
|
98
115
|
# FIXME: *((MaxTokens(self._config.max_tokens),) if self._config.max_tokens is not None else ()),
|
|
99
|
-
))
|
|
100
|
-
text =
|
|
116
|
+
)))
|
|
117
|
+
text = _get_single_ai_message_str(resp)
|
|
101
118
|
|
|
102
119
|
text = _strip_markdown_code_block(text)
|
|
103
120
|
|
ommlds/tools/ocr.py
CHANGED
|
@@ -13,20 +13,13 @@ from omlish import check
|
|
|
13
13
|
from omlish import lang
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
with lang.auto_proxy_import(globals()):
|
|
17
17
|
import pytesseract
|
|
18
18
|
import rapidocr_onnxruntime as rapidocr
|
|
19
19
|
from PIL import Image
|
|
20
20
|
|
|
21
21
|
from omdev.clipboard import darwin_cf as darwin_clipboard
|
|
22
22
|
|
|
23
|
-
else:
|
|
24
|
-
pytesseract = lang.proxy_import('pytesseract')
|
|
25
|
-
rapidocr = lang.proxy_import('rapidocr_onnxruntime')
|
|
26
|
-
Image = lang.proxy_import('PIL.Image')
|
|
27
|
-
|
|
28
|
-
darwin_clipboard = lang.proxy_import('omdev.clipboard.darwin_cf')
|
|
29
|
-
|
|
30
23
|
|
|
31
24
|
##
|
|
32
25
|
|
|
@@ -34,7 +27,7 @@ else:
|
|
|
34
27
|
Ocr: ta.TypeAlias = ta.Callable[['Image.Image'], str]
|
|
35
28
|
|
|
36
29
|
OCR_BACKENDS: ta.Mapping[str, Ocr] = {
|
|
37
|
-
'rapidocr': lambda img: '\n'.join(text[1] for text in rapidocr.RapidOCR()(img)[0] or []),
|
|
30
|
+
'rapidocr': lambda img: '\n'.join(text[1] for text in rapidocr.RapidOCR()(_get_img_png_bytes(img))[0] or []),
|
|
38
31
|
'tesseract': lambda img: pytesseract.image_to_string(img),
|
|
39
32
|
}
|
|
40
33
|
|
|
@@ -62,6 +55,12 @@ def _get_img_data(file: str | None) -> ta.Any:
|
|
|
62
55
|
return sys.stdin.buffer
|
|
63
56
|
|
|
64
57
|
|
|
58
|
+
def _get_img_png_bytes(img: 'Image.Image') -> bytes:
|
|
59
|
+
out = io.BytesIO()
|
|
60
|
+
img.save(out, format='PNG')
|
|
61
|
+
return out.getvalue()
|
|
62
|
+
|
|
63
|
+
|
|
65
64
|
def _main() -> None:
|
|
66
65
|
parser = argparse.ArgumentParser()
|
|
67
66
|
parser.add_argument('file', nargs='?')
|
ommlds/wiki/analyze.py
CHANGED
|
@@ -213,7 +213,7 @@ class FileAnalyzer:
|
|
|
213
213
|
self.verbose and print()
|
|
214
214
|
return True
|
|
215
215
|
|
|
216
|
-
@logs.
|
|
216
|
+
@logs.exception_logging(log)
|
|
217
217
|
def run(self, file_name: str) -> None:
|
|
218
218
|
log.info(f'{self._ctx.deathpact=} {file_name}') # noqa
|
|
219
219
|
|
|
@@ -268,7 +268,7 @@ class FileAnalyzer:
|
|
|
268
268
|
self._flush_rows()
|
|
269
269
|
|
|
270
270
|
|
|
271
|
-
@logs.
|
|
271
|
+
@logs.exception_logging(log)
|
|
272
272
|
def analyze_file(
|
|
273
273
|
file_name: str,
|
|
274
274
|
db_url: str,
|
ommlds/wiki/text/mfh.py
CHANGED
|
@@ -13,14 +13,10 @@ from omlish import lang
|
|
|
13
13
|
from omlish import marshal as msh
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
with lang.auto_proxy_import(globals()):
|
|
17
17
|
import mwparserfromhell as mfh
|
|
18
18
|
import mwparserfromhell.nodes as mfn
|
|
19
19
|
|
|
20
|
-
else:
|
|
21
|
-
mfh = lang.proxy_import('mwparserfromhell')
|
|
22
|
-
mfn = lang.proxy_import('mwparserfromhell.nodes')
|
|
23
|
-
|
|
24
20
|
|
|
25
21
|
Wikicode: ta.TypeAlias = 'mfh.wikicode.Wikicode'
|
|
26
22
|
|
ommlds/wiki/text/wtp.py
CHANGED
|
@@ -26,10 +26,8 @@ from omlish import cached
|
|
|
26
26
|
from omlish import lang
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
with lang.auto_proxy_import(globals()):
|
|
30
30
|
import wikitextparser as wtp
|
|
31
|
-
else:
|
|
32
|
-
wtp = lang.proxy_import('wikitextparser')
|
|
33
31
|
|
|
34
32
|
|
|
35
33
|
WikiText: ta.TypeAlias = 'wtp.WikiText'
|
ommlds/wiki/utils/xml.py
CHANGED
|
@@ -24,7 +24,7 @@ else:
|
|
|
24
24
|
|
|
25
25
|
T = ta.TypeVar('T')
|
|
26
26
|
|
|
27
|
-
Element: ta.TypeAlias = ta.Union[ET.Element, 'lxml_etree.Element']
|
|
27
|
+
Element: ta.TypeAlias = ta.Union[ET.Element, 'lxml_etree.Element'] # type: ignore[valid-type]
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
##
|
|
@@ -83,8 +83,8 @@ class ElementToKwargs:
|
|
|
83
83
|
raise KeyError(k)
|
|
84
84
|
kw[k] = v
|
|
85
85
|
|
|
86
|
-
if el.attrib:
|
|
87
|
-
for k, v in el.attrib.items():
|
|
86
|
+
if el.attrib: # type: ignore
|
|
87
|
+
for k, v in el.attrib.items(): # type: ignore
|
|
88
88
|
k = strip_ns(k)
|
|
89
89
|
|
|
90
90
|
if k in self.attrs:
|
|
@@ -99,7 +99,7 @@ class ElementToKwargs:
|
|
|
99
99
|
else:
|
|
100
100
|
raise KeyError(k)
|
|
101
101
|
|
|
102
|
-
for cel in el:
|
|
102
|
+
for cel in el: # type: ignore
|
|
103
103
|
k = strip_ns(cel.tag)
|
|
104
104
|
|
|
105
105
|
if k in self.scalars:
|
|
@@ -123,7 +123,7 @@ class ElementToKwargs:
|
|
|
123
123
|
raise KeyError(k)
|
|
124
124
|
|
|
125
125
|
if self.text is not None:
|
|
126
|
-
set_kw(self.text, el.text)
|
|
126
|
+
set_kw(self.text, el.text) # type: ignore
|
|
127
127
|
|
|
128
128
|
return kw
|
|
129
129
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ommlds
|
|
3
|
-
Version: 0.0.0.
|
|
3
|
+
Version: 0.0.0.dev480
|
|
4
4
|
Summary: ommlds
|
|
5
5
|
Author: wrmsr
|
|
6
6
|
License-Expression: BSD-3-Clause
|
|
@@ -14,50 +14,53 @@ 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.dev480
|
|
18
|
+
Requires-Dist: omlish==0.0.0.dev480
|
|
19
19
|
Provides-Extra: all
|
|
20
20
|
Requires-Dist: llama-cpp-python~=0.3; extra == "all"
|
|
21
|
-
Requires-Dist: mlx~=0.
|
|
22
|
-
Requires-Dist: mlx-lm~=0.
|
|
23
|
-
Requires-Dist: tiktoken~=0.
|
|
21
|
+
Requires-Dist: mlx~=0.30; sys_platform == "darwin" and extra == "all"
|
|
22
|
+
Requires-Dist: mlx-lm~=0.28; sys_platform == "darwin" and extra == "all"
|
|
23
|
+
Requires-Dist: tiktoken~=0.12; extra == "all"
|
|
24
24
|
Requires-Dist: tinygrad~=0.11; extra == "all"
|
|
25
25
|
Requires-Dist: tokenizers~=0.22; extra == "all"
|
|
26
|
-
Requires-Dist: torch~=2.
|
|
27
|
-
Requires-Dist: transformers~=4.
|
|
26
|
+
Requires-Dist: torch~=2.9; extra == "all"
|
|
27
|
+
Requires-Dist: transformers~=4.57; extra == "all"
|
|
28
28
|
Requires-Dist: sentence-transformers~=5.1; extra == "all"
|
|
29
|
-
Requires-Dist: huggingface-hub~=0.
|
|
30
|
-
Requires-Dist: datasets~=4.
|
|
29
|
+
Requires-Dist: huggingface-hub~=0.36; extra == "all"
|
|
30
|
+
Requires-Dist: datasets~=4.4; extra == "all"
|
|
31
|
+
Requires-Dist: regex>=2025.0; extra == "all"
|
|
31
32
|
Requires-Dist: numpy>=1.26; extra == "all"
|
|
32
33
|
Requires-Dist: pytesseract~=0.3; extra == "all"
|
|
33
34
|
Requires-Dist: rapidocr-onnxruntime~=1.4; extra == "all"
|
|
34
|
-
Requires-Dist: pillow~=
|
|
35
|
-
Requires-Dist: ddgs~=9.
|
|
35
|
+
Requires-Dist: pillow~=12.0; extra == "all"
|
|
36
|
+
Requires-Dist: ddgs~=9.9; extra == "all"
|
|
36
37
|
Requires-Dist: mwparserfromhell~=0.7; extra == "all"
|
|
37
38
|
Requires-Dist: wikitextparser~=0.56; extra == "all"
|
|
38
39
|
Requires-Dist: lxml>=5.3; python_version < "3.13" and extra == "all"
|
|
39
40
|
Provides-Extra: backends
|
|
40
41
|
Requires-Dist: llama-cpp-python~=0.3; extra == "backends"
|
|
41
|
-
Requires-Dist: mlx~=0.
|
|
42
|
-
Requires-Dist: mlx-lm~=0.
|
|
43
|
-
Requires-Dist: tiktoken~=0.
|
|
42
|
+
Requires-Dist: mlx~=0.30; sys_platform == "darwin" and extra == "backends"
|
|
43
|
+
Requires-Dist: mlx-lm~=0.28; sys_platform == "darwin" and extra == "backends"
|
|
44
|
+
Requires-Dist: tiktoken~=0.12; extra == "backends"
|
|
44
45
|
Requires-Dist: tinygrad~=0.11; extra == "backends"
|
|
45
46
|
Requires-Dist: tokenizers~=0.22; extra == "backends"
|
|
46
|
-
Requires-Dist: torch~=2.
|
|
47
|
-
Requires-Dist: transformers~=4.
|
|
47
|
+
Requires-Dist: torch~=2.9; extra == "backends"
|
|
48
|
+
Requires-Dist: transformers~=4.57; extra == "backends"
|
|
48
49
|
Requires-Dist: sentence-transformers~=5.1; extra == "backends"
|
|
49
50
|
Provides-Extra: huggingface
|
|
50
|
-
Requires-Dist: huggingface-hub~=0.
|
|
51
|
-
Requires-Dist: datasets~=4.
|
|
51
|
+
Requires-Dist: huggingface-hub~=0.36; extra == "huggingface"
|
|
52
|
+
Requires-Dist: datasets~=4.4; extra == "huggingface"
|
|
53
|
+
Provides-Extra: nanochat
|
|
54
|
+
Requires-Dist: regex>=2025.0; extra == "nanochat"
|
|
52
55
|
Provides-Extra: numpy
|
|
53
56
|
Requires-Dist: numpy>=1.26; extra == "numpy"
|
|
54
57
|
Provides-Extra: ocr
|
|
55
58
|
Requires-Dist: pytesseract~=0.3; extra == "ocr"
|
|
56
59
|
Requires-Dist: rapidocr-onnxruntime~=1.4; extra == "ocr"
|
|
57
60
|
Provides-Extra: pillow
|
|
58
|
-
Requires-Dist: pillow~=
|
|
61
|
+
Requires-Dist: pillow~=12.0; extra == "pillow"
|
|
59
62
|
Provides-Extra: search
|
|
60
|
-
Requires-Dist: ddgs~=9.
|
|
63
|
+
Requires-Dist: ddgs~=9.9; extra == "search"
|
|
61
64
|
Provides-Extra: wiki
|
|
62
65
|
Requires-Dist: mwparserfromhell~=0.7; extra == "wiki"
|
|
63
66
|
Requires-Dist: wikitextparser~=0.56; extra == "wiki"
|