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
|
@@ -8,7 +8,7 @@ from .types import Content
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
@lang.static_init
|
|
11
|
-
def
|
|
11
|
+
def _install_standard_marshaling() -> None:
|
|
12
12
|
for root_cls in [
|
|
13
13
|
Content,
|
|
14
14
|
Content.CacheControl,
|
|
@@ -17,7 +17,7 @@ def _install_standard_marshalling() -> None:
|
|
|
17
17
|
msh.polymorphism_from_subclasses(
|
|
18
18
|
root_cls,
|
|
19
19
|
naming=msh.Naming.SNAKE,
|
|
20
|
-
strip_suffix=
|
|
20
|
+
strip_suffix=msh.AutoStripSuffix,
|
|
21
21
|
),
|
|
22
22
|
msh.FieldTypeTagging('type'),
|
|
23
23
|
))
|
|
@@ -8,7 +8,7 @@ from .events import AnthropicSseDecoderEvents
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
@lang.static_init
|
|
11
|
-
def
|
|
11
|
+
def _install_standard_marshaling() -> None:
|
|
12
12
|
for root_cls in [
|
|
13
13
|
AnthropicSseDecoderEvents.Event,
|
|
14
14
|
AnthropicSseDecoderEvents.ContentBlockStart.ContentBlock,
|
|
@@ -63,9 +63,10 @@ class AnthropicSseMessageAssembler(
|
|
|
63
63
|
while True:
|
|
64
64
|
ae: ta.Any = check.not_none((yield from self._next_event()))
|
|
65
65
|
if isinstance(ae, AnthropicSseDecoderEvents.ContentBlockStart):
|
|
66
|
-
check.equal(ae.index, len(content))
|
|
66
|
+
# check.equal(ae.index, len(content))
|
|
67
67
|
c = yield from self._do_content_block(ae)
|
|
68
|
-
|
|
68
|
+
if c is not None:
|
|
69
|
+
content.append(check.isinstance(c, Content))
|
|
69
70
|
elif isinstance(ae, AnthropicSseDecoderEvents.MessageDelta):
|
|
70
71
|
for k in ('stop_reason', 'stop_sequence'):
|
|
71
72
|
if (v := getattr(ae.delta, k)) is not None:
|
|
@@ -76,7 +77,7 @@ class AnthropicSseMessageAssembler(
|
|
|
76
77
|
elif isinstance(ae, AnthropicSseDecoderEvents.MessageStop):
|
|
77
78
|
yield [Message(
|
|
78
79
|
id=ms.message.id,
|
|
79
|
-
role=ms.message.role,
|
|
80
|
+
role=ms.message.role, # type: ignore[arg-type]
|
|
80
81
|
model=ms.message.model,
|
|
81
82
|
content=content,
|
|
82
83
|
stop_reason=dct['stop_reason'],
|
|
@@ -92,6 +93,8 @@ class AnthropicSseMessageAssembler(
|
|
|
92
93
|
return (yield from self._do_text_content_block(cbs))
|
|
93
94
|
elif isinstance(cbs.content_block, AnthropicSseDecoderEvents.ContentBlockStart.ToolUse):
|
|
94
95
|
return (yield from self._do_tool_use_content_block(cbs))
|
|
96
|
+
elif isinstance(cbs.content_block, AnthropicSseDecoderEvents.ContentBlockStart.Thinking):
|
|
97
|
+
return (yield from self._do_thinking_content_block(cbs))
|
|
95
98
|
else:
|
|
96
99
|
raise TypeError(cbs.content_block)
|
|
97
100
|
|
|
@@ -101,11 +104,11 @@ class AnthropicSseMessageAssembler(
|
|
|
101
104
|
while True:
|
|
102
105
|
ae: ta.Any = check.not_none((yield from self._next_event()))
|
|
103
106
|
if isinstance(ae, AnthropicSseDecoderEvents.ContentBlockDelta):
|
|
104
|
-
check.equal(ae.index, cbs.index)
|
|
107
|
+
# check.equal(ae.index, cbs.index)
|
|
105
108
|
cdc = check.isinstance(ae.delta, AnthropicSseDecoderEvents.ContentBlockDelta.TextDelta)
|
|
106
109
|
parts.append(cdc.text)
|
|
107
110
|
elif isinstance(ae, AnthropicSseDecoderEvents.ContentBlockStop):
|
|
108
|
-
check.equal(ae.index, cbs.index)
|
|
111
|
+
# check.equal(ae.index, cbs.index)
|
|
109
112
|
return Text(''.join(parts))
|
|
110
113
|
else:
|
|
111
114
|
raise TypeError(ae)
|
|
@@ -119,11 +122,11 @@ class AnthropicSseMessageAssembler(
|
|
|
119
122
|
while True:
|
|
120
123
|
ae: ta.Any = check.not_none((yield from self._next_event()))
|
|
121
124
|
if isinstance(ae, AnthropicSseDecoderEvents.ContentBlockDelta):
|
|
122
|
-
check.equal(ae.index, cbs.index)
|
|
125
|
+
# check.equal(ae.index, cbs.index)
|
|
123
126
|
cdc = check.isinstance(ae.delta, AnthropicSseDecoderEvents.ContentBlockDelta.InputJsonDelta)
|
|
124
127
|
json_parts.append(cdc.partial_json)
|
|
125
128
|
elif isinstance(ae, AnthropicSseDecoderEvents.ContentBlockStop):
|
|
126
|
-
check.equal(ae.index, cbs.index)
|
|
129
|
+
# check.equal(ae.index, cbs.index)
|
|
127
130
|
dj = ''.join(json_parts).strip()
|
|
128
131
|
if dj:
|
|
129
132
|
dd = check.isinstance(json.loads(dj), ta.Mapping)
|
|
@@ -138,3 +141,16 @@ class AnthropicSseMessageAssembler(
|
|
|
138
141
|
)
|
|
139
142
|
else:
|
|
140
143
|
raise TypeError(ae)
|
|
144
|
+
|
|
145
|
+
def _do_thinking_content_block(self, cbs: AnthropicSseDecoderEvents.ContentBlockStart) -> ta.Any:
|
|
146
|
+
# csc = check.isinstance(cbs.content_block, AnthropicSseDecoderEvents.ContentBlockStart.Thinking)
|
|
147
|
+
while True:
|
|
148
|
+
ae: ta.Any = check.not_none((yield from self._next_event()))
|
|
149
|
+
if isinstance(ae, AnthropicSseDecoderEvents.ContentBlockDelta):
|
|
150
|
+
pass
|
|
151
|
+
elif isinstance(ae, AnthropicSseDecoderEvents.ContentBlockStop):
|
|
152
|
+
return None
|
|
153
|
+
else:
|
|
154
|
+
raise TypeError(ae)
|
|
155
|
+
return # type: ignore # noqa
|
|
156
|
+
yield # noqa
|
|
@@ -80,6 +80,11 @@ class AnthropicSseDecoderEvents(lang.Namespace):
|
|
|
80
80
|
name: str
|
|
81
81
|
input: ta.Any
|
|
82
82
|
|
|
83
|
+
@dc.dataclass(frozen=True)
|
|
84
|
+
class Thinking(ContentBlock):
|
|
85
|
+
signature: str
|
|
86
|
+
thinking: str
|
|
87
|
+
|
|
83
88
|
content_block: ContentBlock
|
|
84
89
|
index: int
|
|
85
90
|
|
|
@@ -96,6 +101,14 @@ class AnthropicSseDecoderEvents(lang.Namespace):
|
|
|
96
101
|
class InputJsonDelta(Delta):
|
|
97
102
|
partial_json: str
|
|
98
103
|
|
|
104
|
+
@dc.dataclass(frozen=True)
|
|
105
|
+
class ThinkingDelta(Delta):
|
|
106
|
+
thinking: str
|
|
107
|
+
|
|
108
|
+
@dc.dataclass(frozen=True)
|
|
109
|
+
class SignatureDelta(Delta):
|
|
110
|
+
signature: str
|
|
111
|
+
|
|
99
112
|
delta: Delta
|
|
100
113
|
index: int
|
|
101
114
|
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"""
|
|
2
|
+
https://docs.claude.com/en/api/messages
|
|
3
|
+
"""
|
|
1
4
|
import typing as ta
|
|
2
5
|
|
|
3
6
|
from omlish import dataclasses as dc
|
|
@@ -8,6 +11,22 @@ from omlish import marshal as msh
|
|
|
8
11
|
##
|
|
9
12
|
|
|
10
13
|
|
|
14
|
+
def _set_class_marshal_options(cls):
|
|
15
|
+
msh.update_object_metadata(
|
|
16
|
+
cls,
|
|
17
|
+
field_defaults=msh.FieldMetadata(
|
|
18
|
+
options=msh.FieldOptions(
|
|
19
|
+
omit_if=lang.is_none,
|
|
20
|
+
),
|
|
21
|
+
),
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
return cls
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
##
|
|
28
|
+
|
|
29
|
+
|
|
11
30
|
class Content(lang.Abstract, lang.Sealed):
|
|
12
31
|
class CacheControl(lang.Abstract, lang.Sealed):
|
|
13
32
|
"""https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching"""
|
|
@@ -18,7 +37,7 @@ class Content(lang.Abstract, lang.Sealed):
|
|
|
18
37
|
|
|
19
38
|
|
|
20
39
|
@dc.dataclass(frozen=True)
|
|
21
|
-
@
|
|
40
|
+
@_set_class_marshal_options
|
|
22
41
|
class Text(Content):
|
|
23
42
|
text: str
|
|
24
43
|
|
|
@@ -28,7 +47,7 @@ class Text(Content):
|
|
|
28
47
|
|
|
29
48
|
|
|
30
49
|
@dc.dataclass(frozen=True)
|
|
31
|
-
@
|
|
50
|
+
@_set_class_marshal_options
|
|
32
51
|
class ToolUse(Content):
|
|
33
52
|
id: str
|
|
34
53
|
name: str
|
|
@@ -40,6 +59,7 @@ class ToolUse(Content):
|
|
|
40
59
|
|
|
41
60
|
|
|
42
61
|
@dc.dataclass(frozen=True)
|
|
62
|
+
@_set_class_marshal_options
|
|
43
63
|
class ToolResult(Content):
|
|
44
64
|
tool_use_id: str
|
|
45
65
|
content: str
|
|
@@ -49,13 +69,24 @@ class ToolResult(Content):
|
|
|
49
69
|
|
|
50
70
|
|
|
51
71
|
@dc.dataclass(frozen=True, kw_only=True)
|
|
52
|
-
@
|
|
72
|
+
@_set_class_marshal_options
|
|
73
|
+
class CacheCreation:
|
|
74
|
+
ephemeral_5m_input_tokens: int | None = None
|
|
75
|
+
ephemeral_1h_input_tokens: int | None = None
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
##
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
82
|
+
@_set_class_marshal_options
|
|
53
83
|
class Usage:
|
|
54
84
|
input_tokens: int | None = None
|
|
55
85
|
output_tokens: int | None = None
|
|
56
86
|
|
|
57
87
|
cache_creation_input_tokens: int | None = None
|
|
58
88
|
cache_read_input_tokens: int | None = None
|
|
89
|
+
cache_creation: CacheCreation | None = None
|
|
59
90
|
|
|
60
91
|
service_tier: str | None = None
|
|
61
92
|
|
|
@@ -64,15 +95,15 @@ class Usage:
|
|
|
64
95
|
|
|
65
96
|
|
|
66
97
|
@dc.dataclass(frozen=True, kw_only=True)
|
|
67
|
-
@
|
|
98
|
+
@_set_class_marshal_options
|
|
68
99
|
class Message:
|
|
69
100
|
id: str | None = None
|
|
70
101
|
|
|
71
|
-
role:
|
|
102
|
+
role: ta.Literal['user', 'assistant']
|
|
72
103
|
|
|
73
104
|
model: str | None = None
|
|
74
105
|
|
|
75
|
-
content: ta.Sequence[Content] | None = None
|
|
106
|
+
content: str | ta.Sequence[Content] | None = None
|
|
76
107
|
|
|
77
108
|
stop_reason: str | None = None
|
|
78
109
|
stop_sequence: str | None = None
|
|
@@ -84,6 +115,7 @@ class Message:
|
|
|
84
115
|
|
|
85
116
|
|
|
86
117
|
@dc.dataclass(frozen=True)
|
|
118
|
+
@_set_class_marshal_options
|
|
87
119
|
class ToolSpec:
|
|
88
120
|
name: str
|
|
89
121
|
description: str
|
|
@@ -94,7 +126,7 @@ class ToolSpec:
|
|
|
94
126
|
|
|
95
127
|
|
|
96
128
|
@dc.dataclass(frozen=True)
|
|
97
|
-
@
|
|
129
|
+
@_set_class_marshal_options
|
|
98
130
|
class MessagesRequest:
|
|
99
131
|
model: str
|
|
100
132
|
|
|
@@ -102,7 +134,7 @@ class MessagesRequest:
|
|
|
102
134
|
|
|
103
135
|
_: dc.KW_ONLY
|
|
104
136
|
|
|
105
|
-
system: ta.Sequence[Content] | None = None
|
|
137
|
+
system: str | ta.Sequence[Content] | None = None
|
|
106
138
|
|
|
107
139
|
tools: ta.Sequence[ToolSpec] | None = None
|
|
108
140
|
|