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
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"""
|
|
2
|
+
https://docs.tavily.com/documentation/api-reference/endpoint/search
|
|
3
|
+
"""
|
|
4
|
+
import typing as ta
|
|
5
|
+
|
|
6
|
+
from omlish import dataclasses as dc
|
|
7
|
+
from omlish import lang
|
|
8
|
+
from omlish import marshal as msh
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
##
|
|
12
|
+
|
|
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
|
+
|
|
30
|
+
KNOWN_COUNTRIES = frozenset([
|
|
31
|
+
'afghanistan',
|
|
32
|
+
'albania',
|
|
33
|
+
'algeria',
|
|
34
|
+
'andorra',
|
|
35
|
+
'angola',
|
|
36
|
+
'argentina',
|
|
37
|
+
'armenia',
|
|
38
|
+
'australia',
|
|
39
|
+
'austria',
|
|
40
|
+
'azerbaijan',
|
|
41
|
+
'bahamas',
|
|
42
|
+
'bahrain',
|
|
43
|
+
'bangladesh',
|
|
44
|
+
'barbados',
|
|
45
|
+
'belarus',
|
|
46
|
+
'belgium',
|
|
47
|
+
'belize',
|
|
48
|
+
'benin',
|
|
49
|
+
'bhutan',
|
|
50
|
+
'bolivia',
|
|
51
|
+
'bosnia and herzegovina',
|
|
52
|
+
'botswana',
|
|
53
|
+
'brazil',
|
|
54
|
+
'brunei',
|
|
55
|
+
'bulgaria',
|
|
56
|
+
'burkina faso',
|
|
57
|
+
'burundi',
|
|
58
|
+
'cambodia',
|
|
59
|
+
'cameroon',
|
|
60
|
+
'canada',
|
|
61
|
+
'cape verde',
|
|
62
|
+
'central african republic',
|
|
63
|
+
'chad',
|
|
64
|
+
'chile',
|
|
65
|
+
'china',
|
|
66
|
+
'colombia',
|
|
67
|
+
'comoros',
|
|
68
|
+
'congo',
|
|
69
|
+
'costa rica',
|
|
70
|
+
'croatia',
|
|
71
|
+
'cuba',
|
|
72
|
+
'cyprus',
|
|
73
|
+
'czech republic',
|
|
74
|
+
'denmark',
|
|
75
|
+
'djibouti',
|
|
76
|
+
'dominican republic',
|
|
77
|
+
'ecuador',
|
|
78
|
+
'egypt',
|
|
79
|
+
'el salvador',
|
|
80
|
+
'equatorial guinea',
|
|
81
|
+
'eritrea',
|
|
82
|
+
'estonia',
|
|
83
|
+
'ethiopia',
|
|
84
|
+
'fiji',
|
|
85
|
+
'finland',
|
|
86
|
+
'france',
|
|
87
|
+
'gabon',
|
|
88
|
+
'gambia',
|
|
89
|
+
'georgia',
|
|
90
|
+
'germany',
|
|
91
|
+
'ghana',
|
|
92
|
+
'greece',
|
|
93
|
+
'guatemala',
|
|
94
|
+
'guinea',
|
|
95
|
+
'haiti',
|
|
96
|
+
'honduras',
|
|
97
|
+
'hungary',
|
|
98
|
+
'iceland',
|
|
99
|
+
'india',
|
|
100
|
+
'indonesia',
|
|
101
|
+
'iran',
|
|
102
|
+
'iraq',
|
|
103
|
+
'ireland',
|
|
104
|
+
'israel',
|
|
105
|
+
'italy',
|
|
106
|
+
'jamaica',
|
|
107
|
+
'japan',
|
|
108
|
+
'jordan',
|
|
109
|
+
'kazakhstan',
|
|
110
|
+
'kenya',
|
|
111
|
+
'kuwait',
|
|
112
|
+
'kyrgyzstan',
|
|
113
|
+
'latvia',
|
|
114
|
+
'lebanon',
|
|
115
|
+
'lesotho',
|
|
116
|
+
'liberia',
|
|
117
|
+
'libya',
|
|
118
|
+
'liechtenstein',
|
|
119
|
+
'lithuania',
|
|
120
|
+
'luxembourg',
|
|
121
|
+
'madagascar',
|
|
122
|
+
'malawi',
|
|
123
|
+
'malaysia',
|
|
124
|
+
'maldives',
|
|
125
|
+
'mali',
|
|
126
|
+
'malta',
|
|
127
|
+
'mauritania',
|
|
128
|
+
'mauritius',
|
|
129
|
+
'mexico',
|
|
130
|
+
'moldova',
|
|
131
|
+
'monaco',
|
|
132
|
+
'mongolia',
|
|
133
|
+
'montenegro',
|
|
134
|
+
'morocco',
|
|
135
|
+
'mozambique',
|
|
136
|
+
'myanmar',
|
|
137
|
+
'namibia',
|
|
138
|
+
'nepal',
|
|
139
|
+
'netherlands',
|
|
140
|
+
'new zealand',
|
|
141
|
+
'nicaragua',
|
|
142
|
+
'niger',
|
|
143
|
+
'nigeria',
|
|
144
|
+
'north korea',
|
|
145
|
+
'north macedonia',
|
|
146
|
+
'norway',
|
|
147
|
+
'oman',
|
|
148
|
+
'pakistan',
|
|
149
|
+
'panama',
|
|
150
|
+
'papua new guinea',
|
|
151
|
+
'paraguay',
|
|
152
|
+
'peru',
|
|
153
|
+
'philippines',
|
|
154
|
+
'poland',
|
|
155
|
+
'portugal',
|
|
156
|
+
'qatar',
|
|
157
|
+
'romania',
|
|
158
|
+
'russia',
|
|
159
|
+
'rwanda',
|
|
160
|
+
'saudi arabia',
|
|
161
|
+
'senegal',
|
|
162
|
+
'serbia',
|
|
163
|
+
'singapore',
|
|
164
|
+
'slovakia',
|
|
165
|
+
'slovenia',
|
|
166
|
+
'somalia',
|
|
167
|
+
'south africa',
|
|
168
|
+
'south korea',
|
|
169
|
+
'south sudan',
|
|
170
|
+
'spain',
|
|
171
|
+
'sri lanka',
|
|
172
|
+
'sudan',
|
|
173
|
+
'sweden',
|
|
174
|
+
'switzerland',
|
|
175
|
+
'syria',
|
|
176
|
+
'taiwan',
|
|
177
|
+
'tajikistan',
|
|
178
|
+
'tanzania',
|
|
179
|
+
'thailand',
|
|
180
|
+
'togo',
|
|
181
|
+
'trinidad and tobago',
|
|
182
|
+
'tunisia',
|
|
183
|
+
'turkey',
|
|
184
|
+
'turkmenistan',
|
|
185
|
+
'uganda',
|
|
186
|
+
'ukraine',
|
|
187
|
+
'united arab emirates',
|
|
188
|
+
'united kingdom',
|
|
189
|
+
'united states',
|
|
190
|
+
'uruguay',
|
|
191
|
+
'uzbekistan',
|
|
192
|
+
'venezuela',
|
|
193
|
+
'vietnam',
|
|
194
|
+
'yemen',
|
|
195
|
+
'zambia',
|
|
196
|
+
'zimbabwe',
|
|
197
|
+
])
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
##
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
204
|
+
@_set_class_marshal_options
|
|
205
|
+
class SearchRequest:
|
|
206
|
+
query: str
|
|
207
|
+
|
|
208
|
+
# optional
|
|
209
|
+
auto_parameters: bool | None = None
|
|
210
|
+
|
|
211
|
+
topic: ta.Literal['general', 'news', 'finance'] | None = None
|
|
212
|
+
search_depth: ta.Literal['basic', 'advanced'] | None = None
|
|
213
|
+
|
|
214
|
+
chunks_per_source: int | None = None
|
|
215
|
+
max_results: int | None = None
|
|
216
|
+
|
|
217
|
+
time_range: ta.Literal['day', 'week', 'month', 'year', 'd', 'w', 'm', 'y'] | None = None
|
|
218
|
+
start_date: str | None = None # YYYY-MM-DD
|
|
219
|
+
end_date: str | None = None # YYYY-MM-DD
|
|
220
|
+
|
|
221
|
+
# Booleans with extra enum-like modes per docs
|
|
222
|
+
include_answer: bool | ta.Literal['basic', 'advanced'] | None = None
|
|
223
|
+
include_raw_content: bool | ta.Literal['markdown', 'text'] | None = None
|
|
224
|
+
|
|
225
|
+
include_images: bool | None = None
|
|
226
|
+
include_image_descriptions: bool | None = None
|
|
227
|
+
include_favicon: bool | None = None
|
|
228
|
+
|
|
229
|
+
include_domains: ta.Sequence[str] | None = None
|
|
230
|
+
exclude_domains: ta.Sequence[str] | None = None
|
|
231
|
+
|
|
232
|
+
country: str | None = None
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
236
|
+
@_set_class_marshal_options
|
|
237
|
+
class SearchResponse:
|
|
238
|
+
query: str
|
|
239
|
+
answer: str
|
|
240
|
+
|
|
241
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
242
|
+
@_set_class_marshal_options
|
|
243
|
+
class Image:
|
|
244
|
+
url: str | None = None
|
|
245
|
+
description: str | None = None
|
|
246
|
+
|
|
247
|
+
images: ta.Sequence[Image] | None = None
|
|
248
|
+
|
|
249
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
250
|
+
@_set_class_marshal_options
|
|
251
|
+
class Result:
|
|
252
|
+
title: str | None = None
|
|
253
|
+
url: str | None = None
|
|
254
|
+
content: str | None = None
|
|
255
|
+
score: float | None = None
|
|
256
|
+
raw_content: str | None = None
|
|
257
|
+
favicon: str | None = None
|
|
258
|
+
|
|
259
|
+
results: ta.Sequence[Result] | None = None
|
|
260
|
+
|
|
261
|
+
follow_up_questions: ta.Sequence[str] | None = None
|
|
262
|
+
|
|
263
|
+
auto_parameters: ta.Mapping[str, ta.Any] | None = None
|
|
264
|
+
|
|
265
|
+
response_time: str | None = None # seconds
|
|
266
|
+
request_id: str | None = None
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
##
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
273
|
+
class ExtractRequest:
|
|
274
|
+
urls: str | ta.Sequence[str]
|
|
275
|
+
include_images: bool | None = None
|
|
276
|
+
include_favicon: bool | None = None
|
|
277
|
+
extract_depth: ta.Literal['basic', 'advanced'] | None = None
|
|
278
|
+
format: ta.Literal['markdown', 'text'] | None = None
|
|
279
|
+
timeout: str | None = None # seconds
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
283
|
+
class ExtractResponse:
|
|
284
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
285
|
+
class Result:
|
|
286
|
+
url: str
|
|
287
|
+
raw_content: str
|
|
288
|
+
images: ta.Sequence[str] | None = None
|
|
289
|
+
favicon: str | None = None
|
|
290
|
+
|
|
291
|
+
results: ta.Sequence[Result]
|
|
292
|
+
|
|
293
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
294
|
+
class FailedResult:
|
|
295
|
+
url: str
|
|
296
|
+
error: str
|
|
297
|
+
|
|
298
|
+
failed_results: ta.Sequence[FailedResult] | None = None
|
|
299
|
+
|
|
300
|
+
response_time: str | None = None
|
|
301
|
+
request_id: str | None = None
|
|
@@ -4,17 +4,25 @@
|
|
|
4
4
|
# https://github.com/tinygrad/tinygrad/blob/ef17af85c6d3f84d1e1cc084d6dee8ced3d1a33e/extra/models/llama.py
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
from
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
)
|
|
7
|
+
from omlish import lang as _lang
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
with _lang.auto_proxy_init(globals()):
|
|
11
|
+
from .fetch import ( # noqa
|
|
12
|
+
fetch_model,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
from .llm import ( # noqa
|
|
16
|
+
Llama3Llm,
|
|
17
|
+
run_llm,
|
|
18
|
+
run_llm_to_stop,
|
|
19
|
+
RunLlmToStopResult,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
from .tokenization import ( # noqa
|
|
23
|
+
Tokenizer,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
from .transformer import ( # noqa
|
|
27
|
+
Transformer,
|
|
28
|
+
)
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import contextlib
|
|
2
|
+
import dataclasses as dc
|
|
3
|
+
import os
|
|
4
|
+
import threading
|
|
5
|
+
import typing as ta
|
|
6
|
+
|
|
7
|
+
import transformers as tfm
|
|
8
|
+
|
|
9
|
+
from omlish import lang
|
|
10
|
+
|
|
11
|
+
from ..._hacks.funcs import create_detour
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
##
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dc.dataclass(frozen=True, kw_only=True)
|
|
18
|
+
class _FileCachePatchContext:
|
|
19
|
+
local_first: bool = False
|
|
20
|
+
local_config_present_is_authoritative: bool = False
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
_FILE_CACHE_PATCH_CONTEXT_TLS = threading.local()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _get_file_cache_patch_context() -> _FileCachePatchContext:
|
|
27
|
+
try:
|
|
28
|
+
return _FILE_CACHE_PATCH_CONTEXT_TLS.context
|
|
29
|
+
except AttributeError:
|
|
30
|
+
ctx = _FILE_CACHE_PATCH_CONTEXT_TLS.context = _FileCachePatchContext()
|
|
31
|
+
return ctx
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
_FILE_CACHE_PATCH_LOCK = threading.Lock()
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@lang.cached_function(lock=_FILE_CACHE_PATCH_LOCK)
|
|
38
|
+
def patch_file_cache() -> None:
|
|
39
|
+
"""
|
|
40
|
+
I tried to make a `local_first_pipeline` function to be called instead of `tfm.pipeline`, I really did, but the
|
|
41
|
+
transformers code is such a disgusting rat's nest full of direct static calls to the caching code strewn about at
|
|
42
|
+
every layer with no concern whatsoever for forwarding kwargs where they need to go.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
from transformers.utils.hub import cached_files
|
|
46
|
+
|
|
47
|
+
orig_cached_files: ta.Callable[..., str | None] = lang.copy_function(cached_files) # type: ignore
|
|
48
|
+
|
|
49
|
+
get_file_cache_patch_context = _get_file_cache_patch_context
|
|
50
|
+
|
|
51
|
+
def new_cached_files(
|
|
52
|
+
path_or_repo_id: str | os.PathLike,
|
|
53
|
+
filenames: list[str],
|
|
54
|
+
**kwargs: ta.Any,
|
|
55
|
+
) -> str | None:
|
|
56
|
+
ctx = get_file_cache_patch_context()
|
|
57
|
+
|
|
58
|
+
if ctx.local_first and not kwargs.get('local_files_only'):
|
|
59
|
+
try:
|
|
60
|
+
local = orig_cached_files(
|
|
61
|
+
path_or_repo_id,
|
|
62
|
+
filenames,
|
|
63
|
+
**{**kwargs, 'local_files_only': True},
|
|
64
|
+
)
|
|
65
|
+
except OSError as e: # noqa
|
|
66
|
+
pass
|
|
67
|
+
else:
|
|
68
|
+
return local
|
|
69
|
+
|
|
70
|
+
if ctx.local_config_present_is_authoritative:
|
|
71
|
+
try:
|
|
72
|
+
local_config = orig_cached_files(
|
|
73
|
+
path_or_repo_id,
|
|
74
|
+
[tfm.CONFIG_NAME],
|
|
75
|
+
**{**kwargs, 'local_files_only': True},
|
|
76
|
+
)
|
|
77
|
+
except OSError as e: # noqa
|
|
78
|
+
pass
|
|
79
|
+
else:
|
|
80
|
+
raise OSError(
|
|
81
|
+
f'Files {filenames!r} requested under local_first '
|
|
82
|
+
f'but local_config present at {local_config!r}, '
|
|
83
|
+
f'assuming files do not exist.',
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
return orig_cached_files(path_or_repo_id, filenames, **kwargs)
|
|
87
|
+
|
|
88
|
+
cached_files.__code__ = create_detour(cached_files, new_cached_files, as_kwargs=True)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@contextlib.contextmanager
|
|
92
|
+
def file_cache_patch_context(
|
|
93
|
+
*,
|
|
94
|
+
local_first: bool = False,
|
|
95
|
+
local_config_present_is_authoritative: bool = False,
|
|
96
|
+
) -> ta.Generator[None]:
|
|
97
|
+
patch_file_cache()
|
|
98
|
+
|
|
99
|
+
new_ctx = dc.replace(
|
|
100
|
+
old_ctx := _get_file_cache_patch_context(),
|
|
101
|
+
local_first=local_first,
|
|
102
|
+
local_config_present_is_authoritative=local_config_present_is_authoritative,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
_FILE_CACHE_PATCH_CONTEXT_TLS.context = new_ctx
|
|
106
|
+
try:
|
|
107
|
+
yield
|
|
108
|
+
finally:
|
|
109
|
+
_FILE_CACHE_PATCH_CONTEXT_TLS.context = old_ctx
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
import typing as ta
|
|
3
|
+
|
|
4
|
+
import transformers as tfm
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
T = ta.TypeVar('T')
|
|
8
|
+
P = ta.ParamSpec('P')
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
##
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class CancellableTextStreamer(tfm.TextStreamer):
|
|
15
|
+
class Callback(ta.Protocol):
|
|
16
|
+
def __call__(self, text: str, *, stream_end: bool) -> None: ...
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
tokenizer: tfm.AutoTokenizer,
|
|
21
|
+
callback: Callback,
|
|
22
|
+
*,
|
|
23
|
+
skip_prompt: bool = False,
|
|
24
|
+
**decode_kwargs: ta.Any,
|
|
25
|
+
) -> None:
|
|
26
|
+
super().__init__(
|
|
27
|
+
tokenizer,
|
|
28
|
+
skip_prompt=skip_prompt,
|
|
29
|
+
**decode_kwargs,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
self.callback = callback
|
|
33
|
+
|
|
34
|
+
_cancelled: bool = False
|
|
35
|
+
|
|
36
|
+
#
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def cancelled(self) -> bool:
|
|
40
|
+
return self._cancelled
|
|
41
|
+
|
|
42
|
+
def cancel(self) -> None:
|
|
43
|
+
self._cancelled = True
|
|
44
|
+
|
|
45
|
+
class Cancelled(BaseException): # noqa
|
|
46
|
+
pass
|
|
47
|
+
|
|
48
|
+
@staticmethod
|
|
49
|
+
def ignoring_cancelled(fn: ta.Callable[P, T]) -> ta.Callable[P, T | None]:
|
|
50
|
+
@functools.wraps(fn)
|
|
51
|
+
def inner(*args, **kwargs):
|
|
52
|
+
try:
|
|
53
|
+
return fn(*args, **kwargs)
|
|
54
|
+
except CancellableTextStreamer.Cancelled:
|
|
55
|
+
pass
|
|
56
|
+
|
|
57
|
+
return inner
|
|
58
|
+
|
|
59
|
+
def _maybe_raise_cancelled(self) -> None:
|
|
60
|
+
if self._cancelled:
|
|
61
|
+
raise CancellableTextStreamer.Cancelled
|
|
62
|
+
|
|
63
|
+
#
|
|
64
|
+
|
|
65
|
+
def put(self, value: ta.Any) -> None:
|
|
66
|
+
self._maybe_raise_cancelled()
|
|
67
|
+
super().put(value)
|
|
68
|
+
self._maybe_raise_cancelled()
|
|
69
|
+
|
|
70
|
+
def on_finalized_text(self, text: str, stream_end: bool = False) -> None:
|
|
71
|
+
self._maybe_raise_cancelled()
|
|
72
|
+
self.callback(text, stream_end=stream_end)
|
|
73
|
+
self._maybe_raise_cancelled()
|