ommlds 0.0.0.dev466__py3-none-any.whl → 0.0.0.dev512__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 +404 -31
- ommlds/README.md +11 -0
- ommlds/__about__.py +21 -12
- 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/sse/events.py +2 -0
- ommlds/backends/anthropic/protocol/types.py +5 -7
- ommlds/backends/cerebras/__init__.py +7 -0
- ommlds/backends/cerebras/_dataclasses.py +4254 -0
- ommlds/backends/cerebras/_marshal.py +24 -0
- ommlds/backends/cerebras/clients.py +9 -0
- ommlds/backends/cerebras/protocol.py +310 -0
- ommlds/backends/google/protocol/__init__.py +13 -0
- ommlds/backends/google/protocol/_dataclasses.py +5997 -0
- ommlds/backends/google/protocol/types.py +6 -8
- ommlds/backends/groq/__init__.py +7 -0
- ommlds/backends/groq/_dataclasses.py +3901 -0
- ommlds/backends/groq/_marshal.py +23 -0
- ommlds/backends/groq/clients.py +9 -0
- ommlds/backends/groq/protocol.py +247 -0
- ommlds/{huggingface.py → backends/huggingface/cache.py} +1 -6
- ommlds/backends/huggingface/cli.py +208 -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 +18 -16
- ommlds/backends/mlx/limits.py +10 -6
- ommlds/backends/mlx/loading.py +7 -4
- ommlds/backends/ollama/__init__.py +7 -0
- ommlds/backends/ollama/_dataclasses.py +3940 -0
- ommlds/backends/ollama/cli.py +36 -0
- ommlds/backends/ollama/protocol.py +201 -0
- ommlds/backends/openai/protocol/__init__.py +15 -1
- ommlds/backends/openai/protocol/_common.py +3 -5
- ommlds/backends/openai/protocol/_dataclasses.py +7708 -0
- ommlds/backends/tavily/__init__.py +7 -0
- ommlds/backends/tavily/_dataclasses.py +1734 -0
- ommlds/backends/tavily/protocol.py +299 -0
- ommlds/backends/tinygrad/models/llama3/__init__.py +22 -14
- ommlds/backends/torch/backends.py +1 -1
- 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 +3835 -0
- ommlds/cli/asyncs.py +30 -0
- ommlds/cli/backends/catalog.py +88 -0
- ommlds/cli/backends/configs.py +9 -0
- ommlds/cli/backends/inject.py +100 -42
- ommlds/cli/{sessions/chat/backends → backends}/injection.py +1 -1
- ommlds/cli/backends/meta.py +82 -0
- ommlds/cli/{sessions/chat/backends → backends}/types.py +11 -1
- ommlds/cli/{sessions/chat/content → content}/messages.py +2 -2
- ommlds/cli/{sessions/chat/content → content}/strings.py +1 -1
- ommlds/cli/inject.py +17 -8
- ommlds/cli/inputs/asyncs.py +32 -0
- ommlds/cli/inputs/sync.py +75 -0
- ommlds/cli/main.py +346 -114
- ommlds/cli/rendering/configs.py +9 -0
- ommlds/cli/{sessions/chat/rendering → rendering}/inject.py +4 -5
- ommlds/cli/{sessions/chat/rendering → rendering}/markdown.py +1 -1
- ommlds/cli/{sessions/chat/rendering → rendering}/raw.py +1 -1
- ommlds/cli/{sessions/chat/rendering → rendering}/types.py +7 -1
- ommlds/cli/secrets.py +22 -0
- ommlds/cli/sessions/base.py +1 -10
- ommlds/cli/sessions/chat/configs.py +13 -30
- ommlds/cli/sessions/chat/drivers/ai/configs.py +13 -0
- ommlds/cli/sessions/chat/drivers/ai/events.py +57 -0
- ommlds/cli/sessions/chat/{chat → drivers}/ai/inject.py +15 -12
- ommlds/cli/sessions/chat/{chat → drivers}/ai/rendering.py +8 -8
- ommlds/cli/sessions/chat/{chat → drivers}/ai/services.py +5 -5
- ommlds/cli/sessions/chat/{chat → drivers}/ai/tools.py +4 -8
- ommlds/cli/sessions/chat/{chat → drivers}/ai/types.py +10 -1
- ommlds/cli/sessions/chat/drivers/configs.py +25 -0
- ommlds/cli/sessions/chat/drivers/events/inject.py +27 -0
- ommlds/cli/sessions/chat/drivers/events/injection.py +14 -0
- ommlds/cli/sessions/chat/drivers/events/manager.py +16 -0
- ommlds/cli/sessions/chat/drivers/events/types.py +44 -0
- ommlds/cli/sessions/chat/drivers/impl.py +50 -0
- ommlds/cli/sessions/chat/drivers/inject.py +70 -0
- ommlds/cli/sessions/chat/drivers/state/configs.py +13 -0
- ommlds/cli/sessions/chat/drivers/state/ids.py +25 -0
- ommlds/cli/sessions/chat/drivers/state/inject.py +83 -0
- ommlds/cli/sessions/chat/{chat → drivers}/state/inmemory.py +1 -6
- ommlds/cli/sessions/chat/{chat → drivers}/state/storage.py +18 -12
- ommlds/cli/sessions/chat/{chat → drivers}/state/types.py +11 -6
- ommlds/cli/sessions/chat/drivers/tools/configs.py +22 -0
- ommlds/cli/sessions/chat/drivers/tools/confirmation.py +44 -0
- ommlds/cli/sessions/chat/drivers/tools/errorhandling.py +39 -0
- ommlds/cli/sessions/chat/{tools → drivers/tools}/execution.py +3 -4
- ommlds/cli/sessions/chat/drivers/tools/fs/__init__.py +0 -0
- ommlds/cli/sessions/chat/drivers/tools/fs/configs.py +12 -0
- ommlds/cli/sessions/chat/drivers/tools/fs/inject.py +35 -0
- ommlds/cli/sessions/chat/drivers/tools/inject.py +83 -0
- ommlds/cli/sessions/chat/{tools → drivers/tools}/injection.py +20 -5
- ommlds/cli/sessions/chat/{tools → drivers/tools}/rendering.py +3 -3
- ommlds/cli/sessions/chat/drivers/tools/todo/__init__.py +0 -0
- ommlds/cli/sessions/chat/drivers/tools/todo/configs.py +12 -0
- ommlds/cli/sessions/chat/drivers/tools/todo/inject.py +31 -0
- ommlds/cli/sessions/chat/drivers/tools/weather/__init__.py +0 -0
- ommlds/cli/sessions/chat/drivers/tools/weather/configs.py +12 -0
- ommlds/cli/sessions/chat/drivers/tools/weather/inject.py +22 -0
- ommlds/cli/sessions/chat/{tools/weather.py → drivers/tools/weather/tools.py} +1 -1
- ommlds/cli/sessions/chat/drivers/types.py +31 -0
- ommlds/cli/sessions/chat/drivers/user/__init__.py +0 -0
- ommlds/cli/sessions/chat/drivers/user/configs.py +14 -0
- ommlds/cli/sessions/chat/drivers/user/inject.py +41 -0
- ommlds/cli/sessions/chat/facades/__init__.py +0 -0
- ommlds/cli/sessions/chat/facades/commands/__init__.py +0 -0
- ommlds/cli/sessions/chat/facades/commands/base.py +83 -0
- ommlds/cli/sessions/chat/facades/commands/configs.py +9 -0
- ommlds/cli/sessions/chat/facades/commands/inject.py +41 -0
- ommlds/cli/sessions/chat/facades/commands/injection.py +15 -0
- ommlds/cli/sessions/chat/facades/commands/manager.py +59 -0
- ommlds/cli/sessions/chat/facades/commands/simple.py +34 -0
- ommlds/cli/sessions/chat/facades/commands/types.py +13 -0
- ommlds/cli/sessions/chat/facades/configs.py +11 -0
- ommlds/cli/sessions/chat/facades/facade.py +26 -0
- ommlds/cli/sessions/chat/facades/inject.py +35 -0
- ommlds/cli/sessions/chat/facades/ui.py +34 -0
- ommlds/cli/sessions/chat/inject.py +10 -49
- ommlds/cli/sessions/chat/interfaces/__init__.py +0 -0
- ommlds/cli/sessions/chat/interfaces/bare/__init__.py +0 -0
- ommlds/cli/sessions/chat/interfaces/bare/configs.py +15 -0
- ommlds/cli/sessions/chat/interfaces/bare/inject.py +69 -0
- ommlds/cli/sessions/chat/interfaces/bare/interactive.py +49 -0
- ommlds/cli/sessions/chat/interfaces/bare/oneshot.py +21 -0
- ommlds/cli/sessions/chat/{tools/confirmation.py → interfaces/bare/tools.py} +3 -22
- ommlds/cli/sessions/chat/interfaces/base.py +13 -0
- ommlds/cli/sessions/chat/interfaces/configs.py +11 -0
- ommlds/cli/sessions/chat/interfaces/inject.py +29 -0
- ommlds/cli/sessions/chat/interfaces/textual/__init__.py +0 -0
- ommlds/cli/sessions/chat/interfaces/textual/app.py +429 -0
- ommlds/cli/sessions/chat/interfaces/textual/configs.py +11 -0
- ommlds/cli/sessions/chat/interfaces/textual/facades.py +19 -0
- ommlds/cli/sessions/chat/interfaces/textual/inject.py +111 -0
- ommlds/cli/sessions/chat/interfaces/textual/inputhistory.py +174 -0
- ommlds/cli/sessions/chat/interfaces/textual/interface.py +24 -0
- ommlds/cli/sessions/chat/interfaces/textual/styles/__init__.py +29 -0
- ommlds/cli/sessions/chat/interfaces/textual/styles/input.tcss +53 -0
- ommlds/cli/sessions/chat/interfaces/textual/styles/markdown.tcss +7 -0
- ommlds/cli/sessions/chat/interfaces/textual/styles/messages.tcss +167 -0
- ommlds/cli/sessions/chat/interfaces/textual/tools.py +38 -0
- ommlds/cli/sessions/chat/interfaces/textual/widgets/__init__.py +0 -0
- ommlds/cli/sessions/chat/interfaces/textual/widgets/input.py +70 -0
- ommlds/cli/sessions/chat/interfaces/textual/widgets/messages.py +207 -0
- ommlds/cli/sessions/chat/session.py +8 -13
- ommlds/cli/sessions/completion/configs.py +5 -6
- ommlds/cli/sessions/completion/inject.py +15 -2
- ommlds/cli/sessions/completion/session.py +10 -18
- ommlds/cli/sessions/configs.py +10 -0
- ommlds/cli/sessions/embedding/configs.py +5 -6
- ommlds/cli/sessions/embedding/inject.py +15 -2
- ommlds/cli/sessions/embedding/session.py +10 -18
- ommlds/cli/sessions/inject.py +15 -15
- ommlds/cli/state/storage.py +8 -2
- ommlds/minichain/__init__.py +217 -60
- ommlds/minichain/_dataclasses.py +20640 -0
- ommlds/minichain/_typedvalues.py +15 -8
- ommlds/minichain/backends/catalogs/base.py +20 -1
- ommlds/minichain/backends/catalogs/simple.py +2 -2
- ommlds/minichain/backends/catalogs/strings.py +13 -10
- ommlds/minichain/backends/impls/anthropic/chat.py +28 -5
- ommlds/minichain/backends/impls/anthropic/names.py +3 -3
- ommlds/minichain/backends/impls/anthropic/protocol.py +2 -2
- ommlds/minichain/backends/impls/anthropic/stream.py +23 -18
- ommlds/minichain/backends/impls/cerebras/__init__.py +0 -0
- ommlds/minichain/backends/impls/cerebras/chat.py +82 -0
- ommlds/minichain/backends/impls/cerebras/names.py +45 -0
- ommlds/minichain/backends/impls/cerebras/protocol.py +143 -0
- ommlds/minichain/backends/impls/cerebras/stream.py +114 -0
- ommlds/minichain/backends/impls/duckduckgo/search.py +5 -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 +20 -84
- ommlds/minichain/backends/impls/google/names.py +6 -0
- ommlds/minichain/backends/impls/google/protocol.py +105 -0
- ommlds/minichain/backends/impls/google/search.py +10 -5
- ommlds/minichain/backends/impls/google/stream.py +64 -142
- ommlds/minichain/backends/impls/google/tools.py +2 -2
- ommlds/minichain/backends/impls/groq/__init__.py +0 -0
- ommlds/minichain/backends/impls/groq/chat.py +77 -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 +114 -0
- ommlds/minichain/backends/impls/huggingface/repos.py +1 -5
- ommlds/minichain/backends/impls/llamacpp/chat.py +15 -3
- ommlds/minichain/backends/impls/llamacpp/completion.py +7 -3
- ommlds/minichain/backends/impls/llamacpp/stream.py +38 -19
- ommlds/minichain/backends/impls/mistral.py +9 -2
- ommlds/minichain/backends/impls/mlx/chat.py +100 -23
- ommlds/minichain/backends/impls/ollama/__init__.py +0 -0
- ommlds/minichain/backends/impls/ollama/chat.py +193 -0
- ommlds/minichain/backends/impls/ollama/protocol.py +144 -0
- ommlds/minichain/backends/impls/openai/chat.py +14 -7
- ommlds/minichain/backends/impls/openai/completion.py +9 -2
- ommlds/minichain/backends/impls/openai/embedding.py +9 -2
- ommlds/minichain/backends/impls/openai/format.py +117 -115
- ommlds/minichain/backends/impls/openai/names.py +33 -5
- ommlds/minichain/backends/impls/openai/stream.py +61 -70
- ommlds/minichain/backends/impls/sentencepiece/tokens.py +9 -6
- ommlds/minichain/backends/impls/tavily.py +66 -0
- ommlds/minichain/backends/impls/tinygrad/chat.py +17 -14
- ommlds/minichain/backends/impls/tokenizers/tokens.py +9 -6
- ommlds/minichain/backends/impls/transformers/sentence.py +5 -2
- ommlds/minichain/backends/impls/transformers/tokens.py +9 -6
- ommlds/minichain/backends/impls/transformers/transformers.py +139 -20
- ommlds/minichain/backends/strings/parsing.py +2 -2
- ommlds/minichain/backends/strings/resolving.py +7 -2
- ommlds/minichain/chat/choices/stream/__init__.py +0 -0
- ommlds/minichain/chat/{stream → choices/stream}/adapters.py +7 -7
- 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/content.py +42 -0
- ommlds/minichain/chat/messages.py +46 -42
- ommlds/minichain/chat/stream/_marshal.py +4 -4
- ommlds/minichain/chat/stream/joining.py +56 -43
- ommlds/minichain/chat/stream/services.py +15 -15
- ommlds/minichain/chat/stream/types.py +17 -24
- ommlds/minichain/chat/templating.py +3 -3
- ommlds/minichain/content/__init__.py +20 -3
- ommlds/minichain/content/_marshal.py +181 -55
- ommlds/minichain/content/code.py +26 -0
- ommlds/minichain/content/composite.py +28 -0
- ommlds/minichain/content/content.py +27 -0
- ommlds/minichain/content/dynamic.py +12 -0
- ommlds/minichain/content/emphasis.py +27 -0
- ommlds/minichain/content/images.py +2 -2
- ommlds/minichain/content/json.py +2 -2
- ommlds/minichain/content/link.py +13 -0
- ommlds/minichain/content/markdown.py +12 -0
- ommlds/minichain/content/metadata.py +10 -0
- ommlds/minichain/content/namespaces.py +8 -0
- ommlds/minichain/content/placeholders.py +10 -9
- ommlds/minichain/content/quote.py +26 -0
- ommlds/minichain/content/raw.py +49 -0
- ommlds/minichain/content/recursive.py +12 -0
- ommlds/minichain/content/resources.py +22 -0
- ommlds/minichain/content/section.py +26 -0
- ommlds/minichain/content/sequence.py +17 -3
- ommlds/minichain/content/standard.py +32 -0
- ommlds/minichain/content/tag.py +28 -0
- ommlds/minichain/content/templates.py +13 -0
- ommlds/minichain/content/text.py +2 -2
- ommlds/minichain/content/transform/__init__.py +0 -0
- ommlds/minichain/content/transform/json.py +55 -0
- ommlds/minichain/content/transform/markdown.py +8 -0
- ommlds/minichain/content/transform/materialize.py +59 -0
- ommlds/minichain/content/transform/metadata.py +16 -0
- ommlds/minichain/content/transform/namespaces.py +20 -0
- ommlds/minichain/content/transform/placeholders.py +60 -0
- ommlds/minichain/content/{prepare.py → transform/prepare.py} +10 -15
- ommlds/minichain/content/transform/recursive.py +54 -0
- ommlds/minichain/content/transform/resources.py +58 -0
- ommlds/minichain/content/transform/standard.py +43 -0
- ommlds/minichain/content/{transforms → transform}/stringify.py +1 -7
- ommlds/minichain/content/transform/strings.py +33 -0
- ommlds/minichain/content/transform/templates.py +25 -0
- ommlds/minichain/content/transform/types.py +18 -0
- ommlds/minichain/content/transform/visitors.py +38 -0
- ommlds/minichain/content/visitors.py +218 -0
- ommlds/minichain/http/__init__.py +0 -0
- ommlds/minichain/http/stream.py +195 -0
- ommlds/minichain/lib/fs/tools/read.py +1 -1
- ommlds/minichain/lib/fs/tools/recursivels/rendering.py +1 -1
- ommlds/minichain/lib/fs/tools/recursivels/running.py +1 -1
- ommlds/minichain/lib/todo/tools/write.py +2 -1
- ommlds/minichain/lib/todo/types.py +1 -1
- ommlds/minichain/llms/types.py +4 -0
- ommlds/minichain/metadata.py +56 -2
- ommlds/minichain/models/configs.py +2 -2
- ommlds/minichain/models/names.py +2 -0
- ommlds/minichain/registries/globals.py +18 -4
- ommlds/minichain/resources.py +49 -3
- ommlds/minichain/search.py +1 -1
- ommlds/minichain/services/README.md +154 -0
- ommlds/minichain/services/__init__.py +6 -2
- ommlds/minichain/services/_marshal.py +46 -10
- ommlds/minichain/services/_origclasses.py +11 -0
- ommlds/minichain/services/_typedvalues.py +8 -3
- ommlds/minichain/services/requests.py +73 -3
- ommlds/minichain/services/responses.py +73 -3
- ommlds/minichain/services/services.py +9 -0
- ommlds/minichain/standard.py +8 -0
- ommlds/minichain/stream/services.py +43 -17
- ommlds/minichain/text/applypatch.py +2 -1
- ommlds/minichain/text/toolparsing/llamacpp/types.py +1 -1
- ommlds/minichain/tokens/specials.py +1 -1
- ommlds/minichain/tools/execution/catalog.py +2 -2
- ommlds/minichain/tools/execution/errorhandling.py +36 -0
- ommlds/minichain/tools/execution/errors.py +2 -2
- ommlds/minichain/tools/execution/executors.py +1 -1
- ommlds/minichain/tools/fns.py +1 -1
- ommlds/minichain/tools/jsonschema.py +2 -2
- ommlds/minichain/tools/reflect.py +11 -7
- ommlds/minichain/tools/types.py +16 -19
- ommlds/minichain/vectors/_marshal.py +1 -1
- ommlds/minichain/vectors/embeddings.py +1 -1
- ommlds/minichain/wrappers/__init__.py +7 -0
- ommlds/minichain/wrappers/firstinwins.py +144 -0
- ommlds/minichain/wrappers/instrument.py +146 -0
- ommlds/minichain/wrappers/retry.py +168 -0
- ommlds/minichain/wrappers/services.py +98 -0
- ommlds/minichain/wrappers/stream.py +57 -0
- ommlds/nanochat/LICENSE +21 -0
- ommlds/nanochat/__init__.py +0 -0
- ommlds/nanochat/rustbpe/LICENSE +21 -0
- ommlds/nanochat/rustbpe/README.md +10 -0
- ommlds/nanochat/tokenizers.py +440 -0
- 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 +369 -0
- ommlds/tools/git.py +84 -64
- ommlds/tools/ocr.py +1 -1
- ommlds/wiki/analyze.py +2 -2
- ommlds/wiki/models.py +4 -4
- ommlds/wiki/text/mfh.py +9 -9
- ommlds/wiki/utils/xml.py +5 -5
- {ommlds-0.0.0.dev466.dist-info → ommlds-0.0.0.dev512.dist-info}/METADATA +28 -21
- ommlds-0.0.0.dev512.dist-info/RECORD +534 -0
- {ommlds-0.0.0.dev466.dist-info → ommlds-0.0.0.dev512.dist-info}/WHEEL +1 -1
- ommlds/cli/backends/standard.py +0 -20
- ommlds/cli/sessions/chat/backends/catalog.py +0 -56
- ommlds/cli/sessions/chat/backends/inject.py +0 -37
- ommlds/cli/sessions/chat/chat/state/inject.py +0 -40
- ommlds/cli/sessions/chat/chat/user/inject.py +0 -61
- ommlds/cli/sessions/chat/chat/user/interactive.py +0 -29
- ommlds/cli/sessions/chat/chat/user/oneshot.py +0 -25
- ommlds/cli/sessions/chat/chat/user/types.py +0 -15
- ommlds/cli/sessions/chat/driver.py +0 -43
- ommlds/cli/sessions/chat/tools/inject.py +0 -145
- ommlds/minichain/backends/impls/openai/format2.py +0 -210
- ommlds/minichain/content/materialize.py +0 -196
- ommlds/minichain/content/simple.py +0 -47
- ommlds/minichain/content/transforms/base.py +0 -46
- ommlds/minichain/content/transforms/interleave.py +0 -70
- ommlds/minichain/content/transforms/squeeze.py +0 -72
- ommlds/minichain/content/transforms/strings.py +0 -24
- ommlds/minichain/content/types.py +0 -43
- ommlds/minichain/stream/wrap.py +0 -62
- ommlds-0.0.0.dev466.dist-info/RECORD +0 -376
- /ommlds/{cli/sessions/chat/backends → backends/huggingface}/__init__.py +0 -0
- /ommlds/cli/{sessions/chat/chat → content}/__init__.py +0 -0
- /ommlds/cli/{sessions/chat/chat/ai → inputs}/__init__.py +0 -0
- /ommlds/cli/{sessions/chat/chat/state → rendering}/__init__.py +0 -0
- /ommlds/cli/sessions/chat/{chat/user → drivers}/__init__.py +0 -0
- /ommlds/cli/sessions/chat/{content → drivers/ai}/__init__.py +0 -0
- /ommlds/cli/sessions/chat/{chat → drivers}/ai/injection.py +0 -0
- /ommlds/cli/sessions/chat/{phases → drivers/events}/__init__.py +0 -0
- /ommlds/cli/sessions/chat/{rendering → drivers/phases}/__init__.py +0 -0
- /ommlds/cli/sessions/chat/{phases → drivers/phases}/inject.py +0 -0
- /ommlds/cli/sessions/chat/{phases → drivers/phases}/injection.py +0 -0
- /ommlds/cli/sessions/chat/{phases → drivers/phases}/manager.py +0 -0
- /ommlds/cli/sessions/chat/{phases → drivers/phases}/types.py +0 -0
- /ommlds/cli/sessions/chat/{tools → drivers/state}/__init__.py +0 -0
- /ommlds/{minichain/content/transforms → cli/sessions/chat/drivers/tools}/__init__.py +0 -0
- {ommlds-0.0.0.dev466.dist-info → ommlds-0.0.0.dev512.dist-info}/entry_points.txt +0 -0
- {ommlds-0.0.0.dev466.dist-info → ommlds-0.0.0.dev512.dist-info}/licenses/LICENSE +0 -0
- {ommlds-0.0.0.dev466.dist-info → ommlds-0.0.0.dev512.dist-info}/top_level.txt +0 -0
|
@@ -4,32 +4,57 @@ TODO:
|
|
|
4
4
|
- https://huggingface.co/blog/aifeifei798/transformers-streaming-output
|
|
5
5
|
"""
|
|
6
6
|
import sys
|
|
7
|
+
import threading
|
|
7
8
|
import typing as ta
|
|
8
9
|
|
|
9
|
-
import transformers as tfm
|
|
10
|
-
|
|
11
10
|
from omlish import check
|
|
12
11
|
from omlish import lang
|
|
13
12
|
from omlish import typedvalues as tv
|
|
13
|
+
from omlish.asyncs.asyncio.sync import AsyncioBufferRelay
|
|
14
14
|
|
|
15
15
|
from ....chat.choices.services import ChatChoicesRequest
|
|
16
16
|
from ....chat.choices.services import ChatChoicesResponse
|
|
17
17
|
from ....chat.choices.services import static_check_is_chat_choices_service
|
|
18
|
+
from ....chat.choices.stream.services import ChatChoicesStreamRequest
|
|
19
|
+
from ....chat.choices.stream.services import ChatChoicesStreamResponse
|
|
20
|
+
from ....chat.choices.stream.services import static_check_is_chat_choices_stream_service
|
|
21
|
+
from ....chat.choices.stream.types import AiChoiceDeltas # noqa
|
|
22
|
+
from ....chat.choices.stream.types import AiChoicesDeltas # noqa
|
|
18
23
|
from ....chat.choices.types import AiChoice
|
|
24
|
+
from ....chat.choices.types import ChatChoicesOutputs
|
|
19
25
|
from ....chat.messages import AiMessage
|
|
20
26
|
from ....chat.messages import Message
|
|
21
27
|
from ....chat.messages import SystemMessage
|
|
22
28
|
from ....chat.messages import ToolUseMessage
|
|
23
29
|
from ....chat.messages import ToolUseResultMessage
|
|
24
30
|
from ....chat.messages import UserMessage
|
|
31
|
+
from ....chat.stream.types import ContentAiDelta # noqa
|
|
25
32
|
from ....completion import CompletionRequest
|
|
26
33
|
from ....completion import CompletionResponse
|
|
27
34
|
from ....completion import static_check_is_completion_service
|
|
28
35
|
from ....configs import Config
|
|
29
36
|
from ....models.configs import ModelPath
|
|
37
|
+
from ....resources import UseResources
|
|
38
|
+
from ....stream.services import StreamResponseSink
|
|
39
|
+
from ....stream.services import new_stream_response
|
|
30
40
|
from ...impls.huggingface.configs import HuggingfaceHubToken
|
|
31
41
|
|
|
32
42
|
|
|
43
|
+
with lang.auto_proxy_import(globals()):
|
|
44
|
+
import transformers as tfm
|
|
45
|
+
|
|
46
|
+
from .....backends import transformers as tfm_u
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
##
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
# @omlish-manifest $.minichain.backends.strings.manifests.BackendStringsManifest(
|
|
53
|
+
# ['ChatChoicesService', 'ChatChoicesStreamService'],
|
|
54
|
+
# 'transformers',
|
|
55
|
+
# )
|
|
56
|
+
|
|
57
|
+
|
|
33
58
|
##
|
|
34
59
|
|
|
35
60
|
|
|
@@ -128,13 +153,10 @@ def build_chat_message(m: Message) -> ta.Mapping[str, ta.Any]:
|
|
|
128
153
|
raise TypeError(m)
|
|
129
154
|
|
|
130
155
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
# )
|
|
136
|
-
@static_check_is_chat_choices_service
|
|
137
|
-
class TransformersChatChoicesService(lang.ExitStacked):
|
|
156
|
+
##
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class BaseTransformersChatChoicesService(lang.ExitStacked):
|
|
138
160
|
DEFAULT_MODEL: ta.ClassVar[str] = (
|
|
139
161
|
'meta-llama/Llama-3.2-1B-Instruct'
|
|
140
162
|
)
|
|
@@ -148,7 +170,7 @@ class TransformersChatChoicesService(lang.ExitStacked):
|
|
|
148
170
|
self._huggingface_hub_token = HuggingfaceHubToken.pop_secret(cc, env='HUGGINGFACE_HUB_TOKEN')
|
|
149
171
|
|
|
150
172
|
@lang.cached_function(transient=True)
|
|
151
|
-
def _load_pipeline(self) -> tfm.Pipeline:
|
|
173
|
+
def _load_pipeline(self) -> 'tfm.Pipeline':
|
|
152
174
|
# FIXME: unload
|
|
153
175
|
check.not_none(self._exit_stack)
|
|
154
176
|
|
|
@@ -161,21 +183,118 @@ class TransformersChatChoicesService(lang.ExitStacked):
|
|
|
161
183
|
for pkw_cfg in self._pipeline_kwargs:
|
|
162
184
|
pkw.update(pkw_cfg.v)
|
|
163
185
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
)
|
|
186
|
+
with tfm_u.file_cache_patch_context(
|
|
187
|
+
local_first=True,
|
|
188
|
+
local_config_present_is_authoritative=True,
|
|
189
|
+
):
|
|
190
|
+
return tfm.pipeline(
|
|
191
|
+
'text-generation',
|
|
192
|
+
**pkw,
|
|
193
|
+
)
|
|
168
194
|
|
|
195
|
+
|
|
196
|
+
##
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
# @omlish-manifest $.minichain.registries.manifests.RegistryManifest(
|
|
200
|
+
# name='transformers',
|
|
201
|
+
# aliases=['tfm'],
|
|
202
|
+
# type='ChatChoicesService',
|
|
203
|
+
# )
|
|
204
|
+
@static_check_is_chat_choices_service
|
|
205
|
+
class TransformersChatChoicesService(BaseTransformersChatChoicesService):
|
|
169
206
|
async def invoke(self, request: ChatChoicesRequest) -> ChatChoicesResponse:
|
|
170
207
|
check.empty(request.options)
|
|
171
208
|
|
|
172
209
|
pipeline = self._load_pipeline()
|
|
173
210
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
211
|
+
inputs = [
|
|
212
|
+
build_chat_message(m)
|
|
213
|
+
for m in request.v
|
|
214
|
+
]
|
|
215
|
+
|
|
216
|
+
outputs = pipeline(inputs)
|
|
217
|
+
|
|
218
|
+
gts = check.single(outputs)['generated_text']
|
|
219
|
+
ugt, agt = gts
|
|
220
|
+
check.state(ugt['role'] == 'user')
|
|
221
|
+
check.state(agt['role'] == 'assistant')
|
|
222
|
+
|
|
223
|
+
return ChatChoicesResponse([AiChoice([AiMessage(agt['content'])])])
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
##
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
# @omlish-manifest $.minichain.registries.manifests.RegistryManifest(
|
|
230
|
+
# name='transformers',
|
|
231
|
+
# type='ChatChoicesStreamService',
|
|
232
|
+
# )
|
|
233
|
+
@static_check_is_chat_choices_stream_service
|
|
234
|
+
class TransformersChatChoicesStreamService(BaseTransformersChatChoicesService):
|
|
235
|
+
async def invoke(self, request: ChatChoicesStreamRequest) -> ChatChoicesStreamResponse:
|
|
236
|
+
check.empty(request.options)
|
|
237
|
+
|
|
238
|
+
pipeline = self._load_pipeline() # noqa
|
|
239
|
+
|
|
240
|
+
inputs = [ # noqa
|
|
241
|
+
build_chat_message(m)
|
|
242
|
+
for m in request.v
|
|
243
|
+
]
|
|
244
|
+
|
|
245
|
+
relay: AsyncioBufferRelay = AsyncioBufferRelay()
|
|
246
|
+
|
|
247
|
+
def streamer_callback(text: str, *, stream_end: bool) -> None:
|
|
248
|
+
if text or stream_end:
|
|
249
|
+
relay.push(text, *([None] if stream_end else []))
|
|
250
|
+
|
|
251
|
+
streamer = tfm_u.CancellableTextStreamer(
|
|
252
|
+
check.not_none(pipeline.tokenizer), # type: ignore[arg-type]
|
|
253
|
+
streamer_callback, # noqa
|
|
254
|
+
skip_prompt=True,
|
|
255
|
+
skip_special_tokens=True,
|
|
179
256
|
)
|
|
180
257
|
|
|
181
|
-
|
|
258
|
+
async with UseResources.or_new(request.options) as rs:
|
|
259
|
+
thread = threading.Thread(
|
|
260
|
+
target=tfm_u.CancellableTextStreamer.ignoring_cancelled(pipeline),
|
|
261
|
+
args=(
|
|
262
|
+
inputs,
|
|
263
|
+
),
|
|
264
|
+
kwargs=dict(
|
|
265
|
+
streamer=streamer,
|
|
266
|
+
),
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
def stop_thread() -> None:
|
|
270
|
+
streamer.cancel()
|
|
271
|
+
# thread.join()
|
|
272
|
+
|
|
273
|
+
rs.enter_context(lang.defer(stop_thread))
|
|
274
|
+
|
|
275
|
+
thread.start()
|
|
276
|
+
|
|
277
|
+
async def inner(sink: StreamResponseSink[AiChoicesDeltas]) -> ta.Sequence[ChatChoicesOutputs] | None:
|
|
278
|
+
while True:
|
|
279
|
+
await relay.wait()
|
|
280
|
+
got = relay.swap()
|
|
281
|
+
|
|
282
|
+
if not got:
|
|
283
|
+
raise RuntimeError
|
|
284
|
+
|
|
285
|
+
if got[-1] is None:
|
|
286
|
+
out = ''.join(got[:-1])
|
|
287
|
+
end = True
|
|
288
|
+
else:
|
|
289
|
+
out = ''.join(got)
|
|
290
|
+
end = False
|
|
291
|
+
|
|
292
|
+
if out:
|
|
293
|
+
await sink.emit(AiChoicesDeltas([AiChoiceDeltas([ContentAiDelta(out)])]))
|
|
294
|
+
|
|
295
|
+
if end:
|
|
296
|
+
break
|
|
297
|
+
|
|
298
|
+
return []
|
|
299
|
+
|
|
300
|
+
return await new_stream_response(rs, inner)
|
|
@@ -11,7 +11,7 @@ from omlish import lang
|
|
|
11
11
|
|
|
12
12
|
@dc.dataclass(frozen=True, kw_only=True)
|
|
13
13
|
class ParsedBackendString:
|
|
14
|
-
backend: str | None = dc.xfield(None, repr_fn=
|
|
14
|
+
backend: str | None = dc.xfield(None, repr_fn=lang.opt_repr)
|
|
15
15
|
|
|
16
16
|
#
|
|
17
17
|
|
|
@@ -56,7 +56,7 @@ _REPO_MODEL_PAT = re.compile(
|
|
|
56
56
|
def parse_backend_string(s: str) -> ParsedBackendString:
|
|
57
57
|
backend: str | None
|
|
58
58
|
if ':' in s:
|
|
59
|
-
backend, s = s.
|
|
59
|
+
backend, _, s = s.partition(':')
|
|
60
60
|
else:
|
|
61
61
|
backend = None
|
|
62
62
|
|
|
@@ -4,9 +4,9 @@ TODO:
|
|
|
4
4
|
- interop with registry somehow, probably? or is it strictly a different concern?
|
|
5
5
|
"""
|
|
6
6
|
import abc
|
|
7
|
-
import dataclasses as dc
|
|
8
7
|
import typing as ta
|
|
9
8
|
|
|
9
|
+
from omlish import dataclasses as dc
|
|
10
10
|
from omlish import lang
|
|
11
11
|
from omlish.manifests.globals import GlobalManifestLoader
|
|
12
12
|
|
|
@@ -97,6 +97,8 @@ class ManifestBackendStringResolver(BackendStringResolver):
|
|
|
97
97
|
for scn in manifest.service_cls_names
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
__repr__ = lang.attr_ops('_manifest').repr
|
|
101
|
+
|
|
100
102
|
def _resolve_name_model(
|
|
101
103
|
self,
|
|
102
104
|
args: ResolveBackendStringArgs,
|
|
@@ -108,7 +110,10 @@ class ManifestBackendStringResolver(BackendStringResolver):
|
|
|
108
110
|
|
|
109
111
|
mn: str | None = mdl.name
|
|
110
112
|
|
|
111
|
-
if
|
|
113
|
+
if args.parsed.backend == m.backend_name and mn is not None:
|
|
114
|
+
pass
|
|
115
|
+
|
|
116
|
+
elif mn == m.backend_name:
|
|
112
117
|
if m.model_names is not None:
|
|
113
118
|
mn = m.model_names.resolved_default
|
|
114
119
|
else:
|
|
File without changes
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
from omlish import dataclasses as dc
|
|
2
2
|
|
|
3
|
-
from
|
|
4
|
-
from ..
|
|
5
|
-
from ..
|
|
6
|
-
from ..
|
|
7
|
-
from ..
|
|
8
|
-
from .joining import
|
|
3
|
+
from ....services import Response
|
|
4
|
+
from ..services import ChatChoicesRequest
|
|
5
|
+
from ..services import static_check_is_chat_choices_service
|
|
6
|
+
from ..types import AiChoice
|
|
7
|
+
from ..types import AiChoices
|
|
8
|
+
from .joining import AiChoicesDeltaJoiner
|
|
9
9
|
from .services import ChatChoicesOutputs
|
|
10
10
|
from .services import ChatChoicesStreamOutputs
|
|
11
11
|
from .services import ChatChoicesStreamService
|
|
@@ -23,7 +23,7 @@ class ChatChoicesStreamServiceChatChoicesService:
|
|
|
23
23
|
AiChoices,
|
|
24
24
|
ChatChoicesOutputs | ChatChoicesStreamOutputs,
|
|
25
25
|
]:
|
|
26
|
-
joiner =
|
|
26
|
+
joiner = AiChoicesDeltaJoiner()
|
|
27
27
|
|
|
28
28
|
async with (resp := await self.service.invoke(request)).v as it: # noqa
|
|
29
29
|
async for cs in it:
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import typing as ta
|
|
2
|
+
|
|
3
|
+
from omlish import check
|
|
4
|
+
|
|
5
|
+
from ...messages import AiChat
|
|
6
|
+
from ...stream.joining import AiDeltaJoiner
|
|
7
|
+
from .types import AiChoiceDeltas
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
##
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AiChoicesDeltaJoiner:
|
|
14
|
+
def __init__(self) -> None:
|
|
15
|
+
super().__init__()
|
|
16
|
+
|
|
17
|
+
self._seq = 0
|
|
18
|
+
self._channels: list[AiDeltaJoiner] = []
|
|
19
|
+
|
|
20
|
+
def add(self, choices: ta.Sequence[AiChoiceDeltas]) -> None:
|
|
21
|
+
if not self._seq:
|
|
22
|
+
check.empty(self._channels)
|
|
23
|
+
self._channels.extend(AiDeltaJoiner() for _ in range(len(choices)))
|
|
24
|
+
|
|
25
|
+
for chan, c in zip(self._channels, choices, strict=True):
|
|
26
|
+
chan.add(c.deltas)
|
|
27
|
+
|
|
28
|
+
self._seq += 1
|
|
29
|
+
|
|
30
|
+
def build(self) -> list[AiChat]:
|
|
31
|
+
return [list(chan.build()) for chan in self._channels]
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import abc
|
|
2
|
+
import typing as ta
|
|
3
|
+
|
|
4
|
+
from omlish import lang
|
|
5
|
+
|
|
6
|
+
from ....registries.globals import register_type
|
|
7
|
+
from ....services import Request
|
|
8
|
+
from ....services import Service
|
|
9
|
+
from ....stream.services import StreamResponse
|
|
10
|
+
from ...messages import Chat
|
|
11
|
+
from ..types import ChatChoicesOutputs
|
|
12
|
+
from .types import AiChoicesDeltas
|
|
13
|
+
from .types import ChatChoicesStreamOptions
|
|
14
|
+
from .types import ChatChoicesStreamOutputs
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
##
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
ChatChoicesStreamRequest: ta.TypeAlias = Request[Chat, ChatChoicesStreamOptions]
|
|
21
|
+
|
|
22
|
+
ChatChoicesStreamResponse: ta.TypeAlias = StreamResponse[
|
|
23
|
+
AiChoicesDeltas,
|
|
24
|
+
ChatChoicesOutputs,
|
|
25
|
+
ChatChoicesStreamOutputs,
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
# @omlish-manifest $.minichain.registries.manifests.RegistryTypeManifest
|
|
29
|
+
ChatChoicesStreamService: ta.TypeAlias = Service[ChatChoicesStreamRequest, ChatChoicesStreamResponse]
|
|
30
|
+
|
|
31
|
+
register_type(ChatChoicesStreamService, module=__name__)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def static_check_is_chat_choices_stream_service[T: ChatChoicesStreamService](t: type[T]) -> type[T]:
|
|
35
|
+
return t
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
##
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@static_check_is_chat_choices_stream_service
|
|
42
|
+
class AbstractChatChoicesStreamService(lang.Abstract):
|
|
43
|
+
@abc.abstractmethod
|
|
44
|
+
def invoke(self, request: ChatChoicesStreamRequest) -> ta.Awaitable[ChatChoicesStreamResponse]:
|
|
45
|
+
raise NotImplementedError
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import typing as ta
|
|
2
|
+
|
|
3
|
+
from omlish import dataclasses as dc
|
|
4
|
+
from omlish import lang
|
|
5
|
+
|
|
6
|
+
from ....stream.services import StreamOptions
|
|
7
|
+
from ....types import Option
|
|
8
|
+
from ....types import Output
|
|
9
|
+
from ...stream.types import AiDeltas
|
|
10
|
+
from ..types import ChatChoicesOptions
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
##
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ChatChoicesStreamOption(Option, lang.Abstract, lang.PackageSealed):
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
ChatChoicesStreamOptions: ta.TypeAlias = ChatChoicesStreamOption | StreamOptions | ChatChoicesOptions
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
##
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ChatChoicesStreamOutput(Output, lang.Abstract, lang.PackageSealed):
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
ChatChoicesStreamOutputs: ta.TypeAlias = ChatChoicesStreamOutput
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
##
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dc.dataclass(frozen=True)
|
|
37
|
+
class AiChoiceDeltas(lang.Final):
|
|
38
|
+
deltas: AiDeltas
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@dc.dataclass(frozen=True)
|
|
42
|
+
class AiChoicesDeltas(lang.Final):
|
|
43
|
+
choices: ta.Sequence[AiChoiceDeltas]
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import typing as ta
|
|
2
|
+
|
|
3
|
+
from ..content.content import Content
|
|
4
|
+
from ..content.transform.strings import transform_content_strings
|
|
5
|
+
from .messages import AiMessage
|
|
6
|
+
from .messages import Message
|
|
7
|
+
from .messages import SystemMessage
|
|
8
|
+
from .messages import ToolUseMessage
|
|
9
|
+
from .messages import ToolUseResultMessage
|
|
10
|
+
from .messages import UserMessage
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
MessageT = ta.TypeVar('MessageT', bound=Message)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
##
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def transform_message_content(fn: ta.Callable[[Content], Content], m: MessageT) -> MessageT:
|
|
20
|
+
if isinstance(m, UserMessage):
|
|
21
|
+
return m.replace(c=fn(m.c))
|
|
22
|
+
|
|
23
|
+
elif isinstance(m, AiMessage):
|
|
24
|
+
return m.replace(c=fn(m.c))
|
|
25
|
+
|
|
26
|
+
elif isinstance(m, SystemMessage):
|
|
27
|
+
return m.replace(c=fn(m.c))
|
|
28
|
+
|
|
29
|
+
elif isinstance(m, ToolUseMessage):
|
|
30
|
+
# TODO: m.tu.args?
|
|
31
|
+
return m
|
|
32
|
+
|
|
33
|
+
elif isinstance(m, ToolUseResultMessage):
|
|
34
|
+
# TODO: m.tur.c?
|
|
35
|
+
return m
|
|
36
|
+
|
|
37
|
+
else:
|
|
38
|
+
raise TypeError(m)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def transform_message_content_strings(fn: ta.Callable[[str], str], m: MessageT) -> MessageT:
|
|
42
|
+
return transform_message_content(lambda c: transform_content_strings(fn, c), m)
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
+
"""
|
|
2
|
+
TODO:
|
|
3
|
+
- channel? reasoning / thinking?
|
|
4
|
+
"""
|
|
1
5
|
import operator
|
|
2
6
|
import typing as ta
|
|
3
7
|
|
|
4
8
|
from omlish import check
|
|
5
9
|
from omlish import dataclasses as dc
|
|
6
|
-
from omlish import dispatch
|
|
7
10
|
from omlish import lang
|
|
8
11
|
from omlish import marshal as msh
|
|
9
|
-
from omlish import typedvalues as tv
|
|
10
12
|
|
|
11
|
-
from ..
|
|
12
|
-
from ..
|
|
13
|
-
from ..content.transforms.base import ContentTransform
|
|
14
|
-
from ..content.types import Content
|
|
15
|
-
from ..metadata import MetadataContainer
|
|
13
|
+
from ..content.content import Content
|
|
14
|
+
from ..metadata import MetadataContainerDataclass
|
|
16
15
|
from ..tools.types import ToolUse
|
|
17
16
|
from ..tools.types import ToolUseResult
|
|
17
|
+
from .metadata import MessageMetadata
|
|
18
18
|
from .metadata import MessageMetadatas
|
|
19
19
|
|
|
20
20
|
|
|
@@ -26,7 +26,7 @@ msh.register_global_module_import('._marshal', __package__)
|
|
|
26
26
|
|
|
27
27
|
@dc.dataclass(frozen=True)
|
|
28
28
|
class Message( # noqa
|
|
29
|
-
|
|
29
|
+
MetadataContainerDataclass[MessageMetadatas],
|
|
30
30
|
lang.Abstract,
|
|
31
31
|
lang.Sealed,
|
|
32
32
|
):
|
|
@@ -34,18 +34,14 @@ class Message( # noqa
|
|
|
34
34
|
default=(),
|
|
35
35
|
kw_only=True,
|
|
36
36
|
repr=False,
|
|
37
|
-
metadata=_tv_field_metadata(
|
|
38
|
-
MessageMetadatas,
|
|
39
|
-
marshal_name='metadata',
|
|
40
|
-
),
|
|
41
37
|
)
|
|
42
38
|
|
|
43
|
-
|
|
44
|
-
def metadata(self) -> tv.TypedValues[MessageMetadatas]:
|
|
45
|
-
return check.isinstance(self._metadata, tv.TypedValues)
|
|
39
|
+
MetadataContainerDataclass._configure_metadata_field(_metadata, MessageMetadatas) # noqa
|
|
46
40
|
|
|
47
|
-
def
|
|
48
|
-
|
|
41
|
+
def replace(self, **kwargs: ta.Any) -> ta.Self:
|
|
42
|
+
if (n := dc.replace_is_not(self, **kwargs)) is self:
|
|
43
|
+
return self
|
|
44
|
+
return n.with_metadata(MessageOriginal(self), discard=[MessageOriginal], override=True)
|
|
49
45
|
|
|
50
46
|
|
|
51
47
|
Chat: ta.TypeAlias = ta.Sequence[Message]
|
|
@@ -54,6 +50,14 @@ Chat: ta.TypeAlias = ta.Sequence[Message]
|
|
|
54
50
|
##
|
|
55
51
|
|
|
56
52
|
|
|
53
|
+
@dc.dataclass(frozen=True)
|
|
54
|
+
class MessageOriginal(MessageMetadata, lang.Final):
|
|
55
|
+
c: Message
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
##
|
|
59
|
+
|
|
60
|
+
|
|
57
61
|
@dc.dataclass(frozen=True)
|
|
58
62
|
class AnyUserMessage(Message, lang.Abstract):
|
|
59
63
|
pass
|
|
@@ -90,18 +94,18 @@ def check_ai_chat(chat: Chat) -> AiChat:
|
|
|
90
94
|
|
|
91
95
|
@dc.dataclass(frozen=True)
|
|
92
96
|
class SystemMessage(AnyUserMessage, lang.Final):
|
|
93
|
-
c:
|
|
97
|
+
c: Content
|
|
94
98
|
|
|
95
99
|
|
|
96
100
|
#
|
|
97
101
|
|
|
98
102
|
|
|
99
103
|
@dc.dataclass(frozen=True)
|
|
100
|
-
@msh.
|
|
104
|
+
@msh.update_fields_options(['name'], omit_if=operator.not_)
|
|
101
105
|
class UserMessage(AnyUserMessage, lang.Final):
|
|
102
|
-
c:
|
|
106
|
+
c: Content
|
|
103
107
|
|
|
104
|
-
name: str | None = dc.xfield(None, repr_fn=
|
|
108
|
+
name: str | None = dc.xfield(None, repr_fn=lang.opt_repr)
|
|
105
109
|
|
|
106
110
|
|
|
107
111
|
#
|
|
@@ -109,7 +113,7 @@ class UserMessage(AnyUserMessage, lang.Final):
|
|
|
109
113
|
|
|
110
114
|
@dc.dataclass(frozen=True)
|
|
111
115
|
class AiMessage(AnyAiMessage, lang.Final):
|
|
112
|
-
c: Content = dc.xfield(None, repr_fn=
|
|
116
|
+
c: Content = dc.xfield(None, repr_fn=lang.opt_repr) # TODO: non-null?
|
|
113
117
|
|
|
114
118
|
|
|
115
119
|
#
|
|
@@ -128,23 +132,23 @@ class ToolUseResultMessage(AnyUserMessage, lang.Final):
|
|
|
128
132
|
##
|
|
129
133
|
|
|
130
134
|
|
|
131
|
-
class _MessageContentTransform(ContentTransform, lang.Final, lang.NotInstantiable):
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
135
|
+
# class _MessageContentTransform(ContentTransform, lang.Final, lang.NotInstantiable):
|
|
136
|
+
# @dispatch.install_method(ContentTransform.apply)
|
|
137
|
+
# def apply_system_message(self, m: SystemMessage) -> SystemMessage:
|
|
138
|
+
# return dc.replace(m, c=self.apply(m.c))
|
|
139
|
+
#
|
|
140
|
+
# @dispatch.install_method(ContentTransform.apply)
|
|
141
|
+
# def apply_user_message(self, m: UserMessage) -> UserMessage:
|
|
142
|
+
# return dc.replace(m, c=self.apply(m.c))
|
|
143
|
+
#
|
|
144
|
+
# @dispatch.install_method(ContentTransform.apply)
|
|
145
|
+
# def apply_ai_message(self, m: AiMessage) -> AiMessage:
|
|
146
|
+
# return dc.replace(m, c=self.apply(m.c))
|
|
147
|
+
#
|
|
148
|
+
# @dispatch.install_method(ContentTransform.apply)
|
|
149
|
+
# def apply_tool_use_message(self, m: ToolUseMessage) -> ToolUseMessage:
|
|
150
|
+
# return dc.replace(m, tu=self.apply(m.tu))
|
|
151
|
+
#
|
|
152
|
+
# @dispatch.install_method(ContentTransform.apply)
|
|
153
|
+
# def apply_tool_use_result_message(self, m: ToolUseResultMessage) -> ToolUseResultMessage:
|
|
154
|
+
# return dc.replace(m, tur=self.apply(m.tur))
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from omlish import lang
|
|
2
2
|
from omlish import marshal as msh
|
|
3
3
|
|
|
4
|
-
from .types import
|
|
4
|
+
from .types import AiDelta
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
##
|
|
@@ -9,8 +9,8 @@ from .types import AiChoiceDelta
|
|
|
9
9
|
|
|
10
10
|
@lang.static_init
|
|
11
11
|
def _install_standard_marshaling() -> None:
|
|
12
|
-
|
|
12
|
+
ad_poly = msh.polymorphism_from_subclasses(AiDelta, naming=msh.Naming.SNAKE)
|
|
13
13
|
msh.install_standard_factories(
|
|
14
|
-
msh.PolymorphismMarshalerFactory(
|
|
15
|
-
msh.PolymorphismUnmarshalerFactory(
|
|
14
|
+
msh.PolymorphismMarshalerFactory(ad_poly),
|
|
15
|
+
msh.PolymorphismUnmarshalerFactory(ad_poly),
|
|
16
16
|
)
|