ommlds 0.0.0.dev440__py3-none-any.whl → 0.0.0.dev480__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. ommlds/.omlish-manifests.json +332 -35
  2. ommlds/__about__.py +15 -9
  3. ommlds/_hacks/__init__.py +4 -0
  4. ommlds/_hacks/funcs.py +110 -0
  5. ommlds/_hacks/names.py +158 -0
  6. ommlds/_hacks/params.py +73 -0
  7. ommlds/_hacks/patches.py +0 -3
  8. ommlds/backends/anthropic/protocol/_marshal.py +2 -2
  9. ommlds/backends/anthropic/protocol/sse/_marshal.py +1 -1
  10. ommlds/backends/anthropic/protocol/sse/assemble.py +23 -7
  11. ommlds/backends/anthropic/protocol/sse/events.py +13 -0
  12. ommlds/backends/anthropic/protocol/types.py +30 -9
  13. ommlds/backends/google/protocol/__init__.py +3 -0
  14. ommlds/backends/google/protocol/_marshal.py +16 -0
  15. ommlds/backends/google/protocol/types.py +626 -0
  16. ommlds/backends/groq/_marshal.py +23 -0
  17. ommlds/backends/groq/protocol.py +249 -0
  18. ommlds/backends/mlx/generation.py +1 -1
  19. ommlds/backends/mlx/loading.py +58 -1
  20. ommlds/backends/ollama/__init__.py +0 -0
  21. ommlds/backends/ollama/protocol.py +170 -0
  22. ommlds/backends/openai/protocol/__init__.py +9 -28
  23. ommlds/backends/openai/protocol/_common.py +18 -0
  24. ommlds/backends/openai/protocol/_marshal.py +27 -0
  25. ommlds/backends/openai/protocol/chatcompletion/chunk.py +58 -31
  26. ommlds/backends/openai/protocol/chatcompletion/contentpart.py +49 -44
  27. ommlds/backends/openai/protocol/chatcompletion/message.py +55 -43
  28. ommlds/backends/openai/protocol/chatcompletion/request.py +114 -66
  29. ommlds/backends/openai/protocol/chatcompletion/response.py +71 -45
  30. ommlds/backends/openai/protocol/chatcompletion/responseformat.py +27 -20
  31. ommlds/backends/openai/protocol/chatcompletion/tokenlogprob.py +16 -7
  32. ommlds/backends/openai/protocol/completionusage.py +24 -15
  33. ommlds/backends/tavily/__init__.py +0 -0
  34. ommlds/backends/tavily/protocol.py +301 -0
  35. ommlds/backends/tinygrad/models/llama3/__init__.py +22 -14
  36. ommlds/backends/transformers/__init__.py +0 -0
  37. ommlds/backends/transformers/filecache.py +109 -0
  38. ommlds/backends/transformers/streamers.py +73 -0
  39. ommlds/cli/asyncs.py +30 -0
  40. ommlds/cli/backends/catalog.py +93 -0
  41. ommlds/cli/backends/configs.py +9 -0
  42. ommlds/cli/backends/inject.py +31 -36
  43. ommlds/cli/backends/injection.py +16 -0
  44. ommlds/cli/backends/types.py +46 -0
  45. ommlds/cli/content/__init__.py +0 -0
  46. ommlds/cli/content/messages.py +34 -0
  47. ommlds/cli/content/strings.py +42 -0
  48. ommlds/cli/inject.py +15 -32
  49. ommlds/cli/inputs/__init__.py +0 -0
  50. ommlds/cli/inputs/asyncs.py +32 -0
  51. ommlds/cli/inputs/sync.py +75 -0
  52. ommlds/cli/main.py +270 -110
  53. ommlds/cli/rendering/__init__.py +0 -0
  54. ommlds/cli/rendering/configs.py +9 -0
  55. ommlds/cli/rendering/inject.py +31 -0
  56. ommlds/cli/rendering/markdown.py +52 -0
  57. ommlds/cli/rendering/raw.py +73 -0
  58. ommlds/cli/rendering/types.py +21 -0
  59. ommlds/cli/secrets.py +21 -0
  60. ommlds/cli/sessions/base.py +1 -1
  61. ommlds/cli/sessions/chat/chat/__init__.py +0 -0
  62. ommlds/cli/sessions/chat/chat/ai/__init__.py +0 -0
  63. ommlds/cli/sessions/chat/chat/ai/configs.py +11 -0
  64. ommlds/cli/sessions/chat/chat/ai/inject.py +74 -0
  65. ommlds/cli/sessions/chat/chat/ai/injection.py +14 -0
  66. ommlds/cli/sessions/chat/chat/ai/rendering.py +70 -0
  67. ommlds/cli/sessions/chat/chat/ai/services.py +79 -0
  68. ommlds/cli/sessions/chat/chat/ai/tools.py +44 -0
  69. ommlds/cli/sessions/chat/chat/ai/types.py +28 -0
  70. ommlds/cli/sessions/chat/chat/state/__init__.py +0 -0
  71. ommlds/cli/sessions/chat/chat/state/configs.py +11 -0
  72. ommlds/cli/sessions/chat/chat/state/inject.py +36 -0
  73. ommlds/cli/sessions/chat/chat/state/inmemory.py +33 -0
  74. ommlds/cli/sessions/chat/chat/state/storage.py +52 -0
  75. ommlds/cli/sessions/chat/chat/state/types.py +38 -0
  76. ommlds/cli/sessions/chat/chat/user/__init__.py +0 -0
  77. ommlds/cli/sessions/chat/chat/user/configs.py +17 -0
  78. ommlds/cli/sessions/chat/chat/user/inject.py +62 -0
  79. ommlds/cli/sessions/chat/chat/user/interactive.py +31 -0
  80. ommlds/cli/sessions/chat/chat/user/oneshot.py +25 -0
  81. ommlds/cli/sessions/chat/chat/user/types.py +15 -0
  82. ommlds/cli/sessions/chat/configs.py +27 -0
  83. ommlds/cli/sessions/chat/driver.py +43 -0
  84. ommlds/cli/sessions/chat/inject.py +33 -65
  85. ommlds/cli/sessions/chat/phases/__init__.py +0 -0
  86. ommlds/cli/sessions/chat/phases/inject.py +27 -0
  87. ommlds/cli/sessions/chat/phases/injection.py +14 -0
  88. ommlds/cli/sessions/chat/phases/manager.py +29 -0
  89. ommlds/cli/sessions/chat/phases/types.py +29 -0
  90. ommlds/cli/sessions/chat/session.py +27 -0
  91. ommlds/cli/sessions/chat/tools/__init__.py +0 -0
  92. ommlds/cli/sessions/chat/tools/configs.py +22 -0
  93. ommlds/cli/sessions/chat/tools/confirmation.py +46 -0
  94. ommlds/cli/sessions/chat/tools/execution.py +66 -0
  95. ommlds/cli/sessions/chat/tools/fs/__init__.py +0 -0
  96. ommlds/cli/sessions/chat/tools/fs/configs.py +12 -0
  97. ommlds/cli/sessions/chat/tools/fs/inject.py +35 -0
  98. ommlds/cli/sessions/chat/tools/inject.py +88 -0
  99. ommlds/cli/sessions/chat/tools/injection.py +44 -0
  100. ommlds/cli/sessions/chat/tools/rendering.py +58 -0
  101. ommlds/cli/sessions/chat/tools/todo/__init__.py +0 -0
  102. ommlds/cli/sessions/chat/tools/todo/configs.py +12 -0
  103. ommlds/cli/sessions/chat/tools/todo/inject.py +31 -0
  104. ommlds/cli/sessions/chat/tools/weather/__init__.py +0 -0
  105. ommlds/cli/sessions/chat/tools/weather/configs.py +12 -0
  106. ommlds/cli/sessions/chat/tools/weather/inject.py +22 -0
  107. ommlds/cli/{tools/weather.py → sessions/chat/tools/weather/tools.py} +1 -1
  108. ommlds/cli/sessions/completion/configs.py +21 -0
  109. ommlds/cli/sessions/completion/inject.py +42 -0
  110. ommlds/cli/sessions/completion/session.py +35 -0
  111. ommlds/cli/sessions/embedding/configs.py +21 -0
  112. ommlds/cli/sessions/embedding/inject.py +42 -0
  113. ommlds/cli/sessions/embedding/session.py +33 -0
  114. ommlds/cli/sessions/inject.py +28 -11
  115. ommlds/cli/state/__init__.py +0 -0
  116. ommlds/cli/state/inject.py +28 -0
  117. ommlds/cli/{state.py → state/storage.py} +41 -24
  118. ommlds/minichain/__init__.py +84 -24
  119. ommlds/minichain/_marshal.py +49 -9
  120. ommlds/minichain/_typedvalues.py +2 -4
  121. ommlds/minichain/backends/catalogs/base.py +20 -1
  122. ommlds/minichain/backends/catalogs/simple.py +2 -2
  123. ommlds/minichain/backends/catalogs/strings.py +10 -8
  124. ommlds/minichain/backends/impls/anthropic/chat.py +65 -27
  125. ommlds/minichain/backends/impls/anthropic/names.py +10 -8
  126. ommlds/minichain/backends/impls/anthropic/protocol.py +109 -0
  127. ommlds/minichain/backends/impls/anthropic/stream.py +111 -43
  128. ommlds/minichain/backends/impls/duckduckgo/search.py +1 -1
  129. ommlds/minichain/backends/impls/dummy/__init__.py +0 -0
  130. ommlds/minichain/backends/impls/dummy/chat.py +69 -0
  131. ommlds/minichain/backends/impls/google/chat.py +114 -22
  132. ommlds/minichain/backends/impls/google/search.py +7 -2
  133. ommlds/minichain/backends/impls/google/stream.py +219 -0
  134. ommlds/minichain/backends/impls/google/tools.py +149 -0
  135. ommlds/minichain/backends/impls/groq/__init__.py +0 -0
  136. ommlds/minichain/backends/impls/groq/chat.py +75 -0
  137. ommlds/minichain/backends/impls/groq/names.py +48 -0
  138. ommlds/minichain/backends/impls/groq/protocol.py +143 -0
  139. ommlds/minichain/backends/impls/groq/stream.py +125 -0
  140. ommlds/minichain/backends/impls/llamacpp/chat.py +33 -18
  141. ommlds/minichain/backends/impls/llamacpp/completion.py +1 -1
  142. ommlds/minichain/backends/impls/llamacpp/format.py +4 -2
  143. ommlds/minichain/backends/impls/llamacpp/stream.py +37 -20
  144. ommlds/minichain/backends/impls/mistral.py +20 -5
  145. ommlds/minichain/backends/impls/mlx/chat.py +96 -22
  146. ommlds/minichain/backends/impls/ollama/__init__.py +0 -0
  147. ommlds/minichain/backends/impls/ollama/chat.py +199 -0
  148. ommlds/minichain/backends/impls/openai/chat.py +18 -8
  149. ommlds/minichain/backends/impls/openai/completion.py +10 -3
  150. ommlds/minichain/backends/impls/openai/embedding.py +10 -3
  151. ommlds/minichain/backends/impls/openai/format.py +131 -106
  152. ommlds/minichain/backends/impls/openai/names.py +31 -5
  153. ommlds/minichain/backends/impls/openai/stream.py +43 -25
  154. ommlds/minichain/backends/impls/tavily.py +66 -0
  155. ommlds/minichain/backends/impls/tinygrad/chat.py +23 -16
  156. ommlds/minichain/backends/impls/transformers/sentence.py +1 -1
  157. ommlds/minichain/backends/impls/transformers/tokens.py +1 -1
  158. ommlds/minichain/backends/impls/transformers/transformers.py +155 -34
  159. ommlds/minichain/backends/strings/parsing.py +1 -1
  160. ommlds/minichain/backends/strings/resolving.py +4 -1
  161. ommlds/minichain/chat/_marshal.py +16 -9
  162. ommlds/minichain/chat/choices/adapters.py +4 -4
  163. ommlds/minichain/chat/choices/services.py +1 -1
  164. ommlds/minichain/chat/choices/stream/__init__.py +0 -0
  165. ommlds/minichain/chat/choices/stream/adapters.py +35 -0
  166. ommlds/minichain/chat/choices/stream/joining.py +31 -0
  167. ommlds/minichain/chat/choices/stream/services.py +45 -0
  168. ommlds/minichain/chat/choices/stream/types.py +43 -0
  169. ommlds/minichain/chat/choices/types.py +2 -2
  170. ommlds/minichain/chat/history.py +3 -3
  171. ommlds/minichain/chat/messages.py +55 -19
  172. ommlds/minichain/chat/services.py +3 -3
  173. ommlds/minichain/chat/stream/_marshal.py +16 -0
  174. ommlds/minichain/chat/stream/joining.py +85 -0
  175. ommlds/minichain/chat/stream/services.py +15 -21
  176. ommlds/minichain/chat/stream/types.py +32 -19
  177. ommlds/minichain/chat/tools/execution.py +8 -7
  178. ommlds/minichain/chat/tools/ids.py +9 -15
  179. ommlds/minichain/chat/tools/parsing.py +17 -26
  180. ommlds/minichain/chat/transforms/base.py +29 -38
  181. ommlds/minichain/chat/transforms/metadata.py +30 -4
  182. ommlds/minichain/chat/transforms/services.py +9 -11
  183. ommlds/minichain/content/_marshal.py +44 -20
  184. ommlds/minichain/content/json.py +13 -0
  185. ommlds/minichain/content/materialize.py +14 -21
  186. ommlds/minichain/content/prepare.py +4 -0
  187. ommlds/minichain/content/transforms/interleave.py +1 -1
  188. ommlds/minichain/content/transforms/squeeze.py +1 -1
  189. ommlds/minichain/content/transforms/stringify.py +1 -1
  190. ommlds/minichain/json.py +20 -0
  191. ommlds/minichain/lib/code/__init__.py +0 -0
  192. ommlds/minichain/lib/code/prompts.py +6 -0
  193. ommlds/minichain/lib/fs/binfiles.py +108 -0
  194. ommlds/minichain/lib/fs/context.py +126 -0
  195. ommlds/minichain/lib/fs/errors.py +101 -0
  196. ommlds/minichain/lib/fs/suggestions.py +36 -0
  197. ommlds/minichain/lib/fs/tools/__init__.py +0 -0
  198. ommlds/minichain/lib/fs/tools/edit.py +104 -0
  199. ommlds/minichain/lib/fs/tools/ls.py +38 -0
  200. ommlds/minichain/lib/fs/tools/read.py +115 -0
  201. ommlds/minichain/lib/fs/tools/recursivels/__init__.py +0 -0
  202. ommlds/minichain/lib/fs/tools/recursivels/execution.py +40 -0
  203. ommlds/minichain/lib/todo/__init__.py +0 -0
  204. ommlds/minichain/lib/todo/context.py +54 -0
  205. ommlds/minichain/lib/todo/tools/__init__.py +0 -0
  206. ommlds/minichain/lib/todo/tools/read.py +44 -0
  207. ommlds/minichain/lib/todo/tools/write.py +335 -0
  208. ommlds/minichain/lib/todo/types.py +60 -0
  209. ommlds/minichain/llms/_marshal.py +25 -17
  210. ommlds/minichain/llms/types.py +4 -0
  211. ommlds/minichain/registries/globals.py +18 -4
  212. ommlds/minichain/resources.py +66 -43
  213. ommlds/minichain/search.py +1 -1
  214. ommlds/minichain/services/_marshal.py +46 -39
  215. ommlds/minichain/services/facades.py +3 -3
  216. ommlds/minichain/services/services.py +1 -1
  217. ommlds/minichain/standard.py +8 -0
  218. ommlds/minichain/stream/services.py +152 -38
  219. ommlds/minichain/stream/wrap.py +22 -24
  220. ommlds/minichain/tools/_marshal.py +1 -1
  221. ommlds/minichain/tools/execution/catalog.py +2 -1
  222. ommlds/minichain/tools/execution/context.py +34 -14
  223. ommlds/minichain/tools/execution/errors.py +15 -0
  224. ommlds/minichain/tools/execution/executors.py +8 -3
  225. ommlds/minichain/tools/execution/reflect.py +40 -5
  226. ommlds/minichain/tools/fns.py +46 -9
  227. ommlds/minichain/tools/jsonschema.py +14 -5
  228. ommlds/minichain/tools/reflect.py +54 -18
  229. ommlds/minichain/tools/types.py +33 -1
  230. ommlds/minichain/utils.py +27 -0
  231. ommlds/minichain/vectors/_marshal.py +11 -10
  232. ommlds/nanochat/LICENSE +21 -0
  233. ommlds/nanochat/__init__.py +0 -0
  234. ommlds/nanochat/rustbpe/LICENSE +21 -0
  235. ommlds/nanochat/tokenizers.py +406 -0
  236. ommlds/server/server.py +3 -3
  237. ommlds/specs/__init__.py +0 -0
  238. ommlds/specs/mcp/__init__.py +0 -0
  239. ommlds/specs/mcp/_marshal.py +23 -0
  240. ommlds/specs/mcp/protocol.py +266 -0
  241. ommlds/tools/git.py +27 -10
  242. ommlds/tools/ocr.py +8 -9
  243. ommlds/wiki/analyze.py +2 -2
  244. ommlds/wiki/text/mfh.py +1 -5
  245. ommlds/wiki/text/wtp.py +1 -3
  246. ommlds/wiki/utils/xml.py +5 -5
  247. {ommlds-0.0.0.dev440.dist-info → ommlds-0.0.0.dev480.dist-info}/METADATA +24 -21
  248. ommlds-0.0.0.dev480.dist-info/RECORD +427 -0
  249. ommlds/cli/backends/standard.py +0 -20
  250. ommlds/cli/sessions/chat/base.py +0 -42
  251. ommlds/cli/sessions/chat/interactive.py +0 -73
  252. ommlds/cli/sessions/chat/printing.py +0 -96
  253. ommlds/cli/sessions/chat/prompt.py +0 -143
  254. ommlds/cli/sessions/chat/state.py +0 -109
  255. ommlds/cli/sessions/chat/tools.py +0 -91
  256. ommlds/cli/sessions/completion/completion.py +0 -44
  257. ommlds/cli/sessions/embedding/embedding.py +0 -42
  258. ommlds/cli/tools/config.py +0 -13
  259. ommlds/cli/tools/inject.py +0 -64
  260. ommlds/minichain/chat/stream/adapters.py +0 -69
  261. ommlds/minichain/lib/fs/ls/execution.py +0 -32
  262. ommlds-0.0.0.dev440.dist-info/RECORD +0 -303
  263. /ommlds/{cli/tools → backends/google}/__init__.py +0 -0
  264. /ommlds/{minichain/lib/fs/ls → backends/groq}/__init__.py +0 -0
  265. /ommlds/{huggingface.py → backends/huggingface.py} +0 -0
  266. /ommlds/minichain/lib/fs/{ls → tools/recursivels}/rendering.py +0 -0
  267. /ommlds/minichain/lib/fs/{ls → tools/recursivels}/running.py +0 -0
  268. {ommlds-0.0.0.dev440.dist-info → ommlds-0.0.0.dev480.dist-info}/WHEEL +0 -0
  269. {ommlds-0.0.0.dev440.dist-info → ommlds-0.0.0.dev480.dist-info}/entry_points.txt +0 -0
  270. {ommlds-0.0.0.dev440.dist-info → ommlds-0.0.0.dev480.dist-info}/licenses/LICENSE +0 -0
  271. {ommlds-0.0.0.dev440.dist-info → ommlds-0.0.0.dev480.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,249 @@
1
+ """
2
+ https://console.groq.com/docs/api-reference#chat-create
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
+ @dc.dataclass(frozen=True, kw_only=True)
31
+ @_set_class_marshal_options
32
+ class ChatCompletionRequest(lang.Final):
33
+ @dc.dataclass(frozen=True, kw_only=True)
34
+ class Message(lang.Sealed, lang.Abstract):
35
+ pass
36
+
37
+ @dc.dataclass(frozen=True, kw_only=True)
38
+ @_set_class_marshal_options
39
+ class SystemMessage(Message, lang.Final):
40
+ content: str | ta.Sequence[str]
41
+ name: str | None = None
42
+ role: ta.Literal['system'] = 'system'
43
+
44
+ @dc.dataclass(frozen=True, kw_only=True)
45
+ @_set_class_marshal_options
46
+ class UserMessage(Message, lang.Final):
47
+ content: str | ta.Sequence[str]
48
+ name: str | None = None
49
+ role: ta.Literal['user'] = 'user'
50
+
51
+ @dc.dataclass(frozen=True, kw_only=True)
52
+ @_set_class_marshal_options
53
+ class AssistantMessage(Message, lang.Final):
54
+ content: str | ta.Sequence[str] | None = None
55
+ name: str | None = None
56
+ reasoning: str | None = None
57
+ role: ta.Literal['assistant'] = 'assistant'
58
+
59
+ @dc.dataclass(frozen=True, kw_only=True)
60
+ @_set_class_marshal_options
61
+ class ToolCall(lang.Final):
62
+ @dc.dataclass(frozen=True, kw_only=True)
63
+ @_set_class_marshal_options
64
+ class Function(lang.Final):
65
+ arguments: str
66
+ name: str
67
+
68
+ function: Function
69
+ id: str
70
+ type: ta.Literal['function'] = 'function'
71
+
72
+ tool_calls: ta.Sequence[ToolCall] | None = None
73
+
74
+ @dc.dataclass(frozen=True, kw_only=True)
75
+ @_set_class_marshal_options
76
+ class ToolMessage(Message, lang.Final):
77
+ content: str | ta.Sequence[str]
78
+ role: ta.Literal['tool'] = 'tool'
79
+ tool_call_id: str
80
+
81
+ messages: ta.Sequence[Message]
82
+ model: str
83
+ citation_options: ta.Literal['enabled', 'disabled'] | None = None
84
+ compound_custom: ta.Mapping[str, ta.Any] | None = None
85
+ disable_tool_validation: bool | None = None
86
+ documents: ta.Sequence[ta.Mapping[str, ta.Any]] | None = None
87
+ frequency_penalty: float | None = None
88
+ include_reasoning: bool | None = None
89
+ logit_bias: ta.Mapping[str, ta.Any] | None = None
90
+ logprobs: bool | None = None
91
+ max_completion_tokens: int | None = None
92
+ n: int | None = None
93
+ parallel_tool_calls: bool | None = None
94
+ presence_penalty: float | None = None
95
+ reasoning_effort: ta.Literal['none', 'default', 'low', 'medium', 'high'] | None = None
96
+ reasoning_format: ta.Literal['hidden', 'raw', 'parsed'] | None = None
97
+ response_format: ta.Any | None = None
98
+ search_settings: ta.Mapping[str, ta.Any] | None = None
99
+ seed: int | None = None
100
+ service_tier: ta.Literal['auto', 'on_demand', 'flex', 'performance', 'null'] | None = None
101
+ stop: str | ta.Sequence[str] | None = None
102
+ store: bool | None = None
103
+ stream: bool | None = None
104
+ stream_options: ta.Mapping[str, ta.Any] | None = None
105
+ temperature: float | None = None
106
+ ool_choice: str | None = None
107
+
108
+ @dc.dataclass(frozen=True, kw_only=True)
109
+ @_set_class_marshal_options
110
+ class Tool(lang.Final):
111
+ @dc.dataclass(frozen=True, kw_only=True)
112
+ @_set_class_marshal_options
113
+ class Function(lang.Final):
114
+ description: str | None = None
115
+ name: str
116
+ parameters: ta.Mapping[str, ta.Any] | None = None # json schema
117
+ strict: bool | None = None
118
+
119
+ function: Function
120
+ type: ta.Literal['function', 'browser_search', 'code_interpreter'] = 'function'
121
+
122
+ tools: ta.Sequence[Tool] | None = None
123
+
124
+ top_logprobs: int | None = None
125
+ top_p: float | None = None
126
+ user: str | None = None
127
+
128
+
129
+ @dc.dataclass(frozen=True, kw_only=True)
130
+ @_set_class_marshal_options
131
+ class ExecutedTool(lang.Final):
132
+ arguments: str
133
+ index: int
134
+ type: str
135
+ browser_results: ta.Sequence[ta.Any] | None = None
136
+ code_results: ta.Sequence[ta.Any] | None = None
137
+ output: str | None = None
138
+ search_results: ta.Any | None = None
139
+
140
+
141
+ @dc.dataclass(frozen=True, kw_only=True)
142
+ @_set_class_marshal_options
143
+ class ChatCompletionResponse(lang.Final):
144
+ @dc.dataclass(frozen=True, kw_only=True)
145
+ @_set_class_marshal_options
146
+ class Choice(lang.Final):
147
+ finish_reason: ta.Literal['stop', 'length', 'tool_calls', 'function_call']
148
+ index: int
149
+ logprobs: ta.Mapping[str, ta.Any] | None = None
150
+
151
+ @dc.dataclass(frozen=True, kw_only=True)
152
+ @_set_class_marshal_options
153
+ class Message(lang.Final):
154
+ annotations: ta.Sequence[ta.Mapping[str, ta.Any]] | None = None
155
+ content: str | None = None
156
+
157
+ executed_tools: ta.Sequence[ExecutedTool] | None = None
158
+
159
+ reasoning: str | None = None
160
+ role: ta.Literal['assistant'] = 'assistant'
161
+
162
+ @dc.dataclass(frozen=True, kw_only=True)
163
+ @_set_class_marshal_options
164
+ class ToolCall(lang.Final):
165
+ id: str
166
+
167
+ @dc.dataclass(frozen=True, kw_only=True)
168
+ @_set_class_marshal_options
169
+ class Function(lang.Final):
170
+ arguments: str
171
+ name: str
172
+
173
+ function: Function
174
+ type: ta.Literal['function'] = 'function'
175
+
176
+ tool_calls: ta.Sequence[ToolCall] | None = None
177
+
178
+ message: Message
179
+
180
+ choices: ta.Sequence[Choice]
181
+ created: int
182
+ id: str
183
+ model: str
184
+ object: ta.Literal['chat.completion'] = 'chat.completion'
185
+ system_fingerprint: str
186
+ usage: ta.Mapping[str, ta.Any] | None = None
187
+ usage_breakdown: ta.Mapping[str, ta.Any] | None = None
188
+ x_groq: ta.Mapping[str, ta.Any] | None = None
189
+ service_tier: str | None = None
190
+
191
+
192
+ @dc.dataclass(frozen=True, kw_only=True)
193
+ @_set_class_marshal_options
194
+ class ChatCompletionChunk(lang.Final):
195
+ id: str
196
+ object: ta.Literal['chat.completion.chunk'] = 'chat.completion.chunk'
197
+ created: int
198
+ model: str
199
+ system_fingerprint: str
200
+
201
+ @dc.dataclass(frozen=True, kw_only=True)
202
+ @_set_class_marshal_options
203
+ class Choice(lang.Final):
204
+ index: int
205
+
206
+ @dc.dataclass(frozen=True, kw_only=True)
207
+ @_set_class_marshal_options
208
+ class Delta(lang.Final):
209
+ role: str | None = None
210
+ content: str | None = None
211
+
212
+ channel: str | None = None
213
+ reasoning: str | None = None
214
+
215
+ @dc.dataclass(frozen=True, kw_only=True)
216
+ @_set_class_marshal_options
217
+ class ToolCall(lang.Final):
218
+ index: int
219
+ id: str | None = None
220
+
221
+ @dc.dataclass(frozen=True, kw_only=True)
222
+ @_set_class_marshal_options
223
+ class Function(lang.Final):
224
+ arguments: str | None = None
225
+ name: str | None = None
226
+
227
+ function: Function | None = None
228
+
229
+ type: ta.Literal['function'] = 'function'
230
+
231
+ tool_calls: ta.Sequence[ToolCall] | None = None
232
+
233
+ executed_tools: ta.Sequence[ExecutedTool] | None = None
234
+
235
+ delta: Delta
236
+ logprobs: ta.Mapping[str, ta.Any] | None = None
237
+ finish_reason: ta.Literal['stop', 'length', 'tool_calls', 'function_call'] | None = None
238
+
239
+ choices: ta.Sequence[Choice]
240
+
241
+ x_groq: ta.Mapping[str, ta.Any] | None = None
242
+ service_tier: str | None = None
243
+ usage: ta.Mapping[str, ta.Any] | None = None
244
+
245
+
246
+ ##
247
+
248
+
249
+ msh.register_global_module_import('._marshal', __package__)
@@ -254,7 +254,7 @@ def stream_generate(
254
254
  add_special_tokens=add_special_tokens,
255
255
  )
256
256
 
257
- prompt = mx.array(prompt) # type: ignore[arg-type]
257
+ prompt = mx.array(ta.cast(ta.Any, prompt))
258
258
 
259
259
  detokenizer = tokenization.detokenizer
260
260
  detokenizer.reset()
@@ -15,6 +15,63 @@ from .tokenization import load_tokenization
15
15
  ##
16
16
 
17
17
 
18
+ def get_model_path(
19
+ path_or_hf_repo: str,
20
+ revision: str | None = None,
21
+ ) -> tuple[pathlib.Path, str | None]:
22
+ """
23
+ Ensures the model is available locally. If the path does not exist locally,
24
+ it is downloaded from the Hugging Face Hub.
25
+
26
+ Args:
27
+ path_or_hf_repo (str): The local path or Hugging Face repository ID of the model.
28
+ revision (str, optional): A revision id which can be a branch name, a tag, or a commit hash.
29
+
30
+ Returns:
31
+ Tuple[Path, str]: A tuple containing the local file path and the Hugging Face repo ID.
32
+ """
33
+
34
+ model_path = pathlib.Path(path_or_hf_repo)
35
+
36
+ if not model_path.exists():
37
+ from huggingface_hub import snapshot_download
38
+ hf_path = path_or_hf_repo
39
+ model_path = pathlib.Path(
40
+ snapshot_download(
41
+ path_or_hf_repo,
42
+ revision=revision,
43
+ allow_patterns=[
44
+ '*.jinja',
45
+ '*.json',
46
+ '*.jsonl',
47
+ '*.py',
48
+ '*.txt',
49
+
50
+ 'model*.safetensors',
51
+
52
+ '*.tiktoken',
53
+ 'tiktoken.model',
54
+ 'tokenizer.model',
55
+ ],
56
+ ),
57
+ )
58
+
59
+ else:
60
+ from huggingface_hub import ModelCard
61
+
62
+ card_path = model_path / 'README.md'
63
+ if card_path.is_file():
64
+ card = ModelCard.load(card_path)
65
+ hf_path = card.data.base_model
66
+ else:
67
+ hf_path = None
68
+
69
+ return model_path, hf_path
70
+
71
+
72
+ ##
73
+
74
+
18
75
  @dc.dataclass(frozen=True, kw_only=True)
19
76
  class LoadedModel:
20
77
  path: pathlib.Path
@@ -46,7 +103,7 @@ def load_model(
46
103
  ) -> LoadedModel:
47
104
  # FIXME: get_model_path return annotation is wrong:
48
105
  # https://github.com/ml-explore/mlx-lm/blob/9ee2b7358f5e258af7b31a8561acfbbe56ad5085/mlx_lm/utils.py#L82
49
- model_path_res = ta.cast(ta.Any, mlx_lm.utils.get_model_path(path_or_hf_repo))
106
+ model_path_res = ta.cast(ta.Any, get_model_path(path_or_hf_repo))
50
107
  if isinstance(model_path_res, tuple):
51
108
  model_path = check.isinstance(model_path_res[0], pathlib.Path)
52
109
  else:
File without changes
@@ -0,0 +1,170 @@
1
+ """
2
+ https://docs.ollama.com/api
3
+ """
4
+ import typing as ta
5
+
6
+ from omlish import dataclasses as dc
7
+ from omlish import lang
8
+
9
+
10
+ ##
11
+
12
+
13
+ @dc.dataclass(frozen=True, kw_only=True)
14
+ @dc.extra_class_params(default_repr_fn=dc.opt_repr)
15
+ class Options:
16
+ # loading
17
+ numa: bool | None = None
18
+ num_ctx: int | None = None
19
+ num_batch: int | None = None
20
+ num_gpu: int | None = None
21
+ main_gpu: int | None = None
22
+ low_vram: bool | None = None
23
+ f16_kv: bool | None = None
24
+ logits_all: bool | None = None
25
+ vocab_only: bool | None = None
26
+ use_mmap: bool | None = None
27
+ use_mlock: bool | None = None
28
+ embedding_only: bool | None = None
29
+ num_thread: int | None = None
30
+
31
+ # querying
32
+ num_keep: int | None = None
33
+ seed: int | None = None
34
+ num_predict: int | None = None
35
+ top_k: int | None = None
36
+ top_p: float | None = None
37
+ tfs_z: float | None = None
38
+ typical_p: float | None = None
39
+ repeat_last_n: int | None = None
40
+ temperature: float | None = None
41
+ repeat_penalty: float | None = None
42
+ presence_penalty: float | None = None
43
+ frequency_penalty: float | None = None
44
+ mirostat: int | None = None
45
+ mirostat_tau: float | None = None
46
+ mirostat_eta: float | None = None
47
+ penalize_newline: bool | None = None
48
+ stop: ta.Sequence[str] | None = None
49
+
50
+
51
+ ##
52
+
53
+
54
+ @dc.dataclass(frozen=True, kw_only=True)
55
+ class BaseRequest(lang.Abstract):
56
+ model: str
57
+
58
+
59
+ @dc.dataclass(frozen=True, kw_only=True)
60
+ class BaseStreamableRequest(BaseRequest, lang.Abstract):
61
+ stream: bool | None = None
62
+
63
+
64
+ ##
65
+
66
+
67
+ @dc.dataclass(frozen=True, kw_only=True)
68
+ class BaseGenerateRequest(BaseStreamableRequest, lang.Abstract):
69
+ options: Options | None = None
70
+ format: ta.Literal['', 'json'] | None = None # TODO: jsonschema
71
+ keep_alive: float | str | None = None
72
+
73
+
74
+ @dc.dataclass(frozen=True, kw_only=True)
75
+ @dc.extra_class_params(default_repr_fn=dc.opt_repr)
76
+ class GenerateRequest(BaseGenerateRequest):
77
+ prompt: str | None = None
78
+ suffix: str | None = None
79
+ system: str | None = None
80
+ template: str | None = None
81
+ context: ta.Sequence[int] | None = None
82
+ raw: bool | None = None
83
+ images: ta.Sequence[bytes] | None = None
84
+ think: bool | ta.Literal['low', 'medium', 'high'] | None = None
85
+
86
+
87
+ #
88
+
89
+
90
+ @dc.dataclass(frozen=True, kw_only=True)
91
+ class BaseGenerateResponse(lang.Abstract):
92
+ model: str | None = None
93
+ created_at: str | None = None
94
+ done: bool | None = None
95
+ done_reason: str | None = None
96
+ total_duration: int | None = None
97
+ load_duration: int | None = None
98
+ prompt_eval_count: int | None = None
99
+ prompt_eval_duration: int | None = None
100
+ eval_count: int | None = None
101
+ eval_duration: int | None = None
102
+
103
+
104
+ @dc.dataclass(frozen=True, kw_only=True)
105
+ @dc.extra_class_params(default_repr_fn=dc.opt_repr)
106
+ class GenerateResponse(BaseGenerateResponse):
107
+ response: str
108
+ thinking: str | None = None
109
+ context: ta.Sequence[int] | None = None
110
+
111
+
112
+ ##
113
+
114
+
115
+ Role: ta.TypeAlias = ta.Literal[
116
+ 'system',
117
+ 'user',
118
+ 'assistant',
119
+ 'tool',
120
+ ]
121
+
122
+
123
+ @dc.dataclass(frozen=True, kw_only=True)
124
+ @dc.extra_class_params(default_repr_fn=dc.opt_repr)
125
+ class Message:
126
+ role: Role
127
+ content: str | None = None
128
+ thinking: str | None = None
129
+ images: ta.Sequence[bytes] | None = None
130
+ tool_name: str | None = None
131
+
132
+ @dc.dataclass(frozen=True, kw_only=True)
133
+ class ToolCall:
134
+ @dc.dataclass(frozen=True, kw_only=True)
135
+ class Function:
136
+ name: str
137
+ arguments: ta.Mapping[str, ta.Any]
138
+
139
+ function: Function
140
+
141
+ tool_calls: ta.Sequence[ToolCall] | None = None
142
+
143
+
144
+ @dc.dataclass(frozen=True, kw_only=True)
145
+ @dc.extra_class_params(default_repr_fn=dc.opt_repr)
146
+ class Tool:
147
+ type: str | None = 'function'
148
+
149
+ @dc.dataclass(frozen=True, kw_only=True)
150
+ @dc.extra_class_params(default_repr_fn=dc.opt_repr)
151
+ class Function:
152
+ name: str | None = None
153
+ description: str | None = None
154
+ parameters: ta.Any | None = None
155
+
156
+ function: Function | None = None
157
+
158
+
159
+ @dc.dataclass(frozen=True, kw_only=True)
160
+ @dc.extra_class_params(default_repr_fn=dc.opt_repr)
161
+ class ChatRequest(BaseGenerateRequest):
162
+ messages: ta.Sequence[Message] | None = None
163
+ tools: ta.Sequence[Tool] | None = None
164
+ think: bool | ta.Literal['low', 'medium', 'high'] | None = None
165
+
166
+
167
+ @dc.dataclass(frozen=True, kw_only=True)
168
+ @dc.extra_class_params(default_repr_fn=dc.opt_repr)
169
+ class ChatResponse(BaseGenerateResponse):
170
+ message: Message
@@ -5,11 +5,8 @@ https://github.com/openai/openai-openapi/blob/master/openapi.yaml
5
5
  # ruff: noqa: I001
6
6
 
7
7
  from .chatcompletion.chunk import ( # noqa
8
- ChatCompletionChunkChoiceDeltaToolCallFunction,
9
- ChatCompletionChunkChoiceDeltaToolCall,
10
8
  ChatCompletionChunkChoiceDelta,
11
9
 
12
- ChatCompletionChunkChoiceLogprobs,
13
10
  ChatCompletionChunkChoice,
14
11
 
15
12
  ChatCompletionChunk,
@@ -18,13 +15,10 @@ from .chatcompletion.chunk import ( # noqa
18
15
  from .chatcompletion.contentpart import ( # noqa
19
16
  TextChatCompletionContentPart,
20
17
 
21
- ImageChatCompletionContentPartImageUrl,
22
- ImageChatCompletionContentPart,
18
+ ImageUrlChatCompletionContentPart,
23
19
 
24
- FileChatCompletionContentPartFileInfo,
25
20
  FileChatCompletionContentPart,
26
21
 
27
- InputAudioChatCompletionContentPartInputAudio,
28
22
  InputAudioChatCompletionContentPart,
29
23
 
30
24
  RefusalChatCompletionContentPart,
@@ -39,9 +33,6 @@ from .chatcompletion.message import ( # noqa
39
33
 
40
34
  UserChatCompletionMessage,
41
35
 
42
- AssistantChatCompletionMessageAudio,
43
- AssistantChatCompletionMessageToolCallFunction,
44
- AssistantChatCompletionMessageToolCall,
45
36
  AssistantChatCompletionMessage,
46
37
 
47
38
  ToolChatCompletionMessage,
@@ -52,18 +43,12 @@ from .chatcompletion.message import ( # noqa
52
43
  )
53
44
 
54
45
  from .chatcompletion.request import ( # noqa
55
- ChatCompletionRequestWebSearchOptionsUserLocationApproximate,
56
- ChatCompletionRequestWebSearchOptionsUserLocation,
57
46
  ChatCompletionRequestWebSearchOptions,
58
47
 
59
48
  ChatCompletionRequestPrediction,
60
49
 
61
- ChatCompletionRequestToolFunction,
62
50
  ChatCompletionRequestTool,
63
51
 
64
- ChatCompletionRequestStreamOptions,
65
-
66
- ChatCompletionRequestNamedToolChoiceFunction,
67
52
  ChatCompletionRequestNamedToolChoice,
68
53
 
69
54
  ChatCompletionRequestAudio,
@@ -72,16 +57,8 @@ from .chatcompletion.request import ( # noqa
72
57
  )
73
58
 
74
59
  from .chatcompletion.response import ( # noqa
75
- ChatCompletionResponseAnnotationUrlCitation,
76
- ChatCompletionResponseAnnotation,
77
-
78
- ChatCompletionResponseAudio,
79
-
80
- ChatCompletionResponseMessageToolCallFunction,
81
- ChatCompletionResponseMessageToolCall,
82
60
  ChatCompletionResponseMessage,
83
61
 
84
- ChatCompletionResponseChoiceLogprobs,
85
62
  ChatCompletionResponseChoice,
86
63
 
87
64
  ChatCompletionResponse,
@@ -90,7 +67,6 @@ from .chatcompletion.response import ( # noqa
90
67
  from .chatcompletion.responseformat import ( # noqa
91
68
  TextChatCompletionResponseFormat,
92
69
 
93
- JsonSchemaChatCompletionResponseFormatJsonSchema,
94
70
  JsonSchemaChatCompletionResponseFormat,
95
71
 
96
72
  JsonObjectChatCompletionResponseFormat,
@@ -99,12 +75,17 @@ from .chatcompletion.responseformat import ( # noqa
99
75
  )
100
76
 
101
77
  from .chatcompletion.tokenlogprob import ( # noqa
102
- ChatCompletionTokenLogprobTopLogprob,
103
78
  ChatCompletionTokenLogprob,
104
79
  )
105
80
 
106
81
  from .completionusage import ( # noqa
107
- CompletionUsageCompletionTokensDetails,
108
- CompletionUsagePromptTokensDetails,
109
82
  CompletionUsage,
110
83
  )
84
+
85
+
86
+ ##
87
+
88
+
89
+ from omlish import marshal as _msh # noqa
90
+
91
+ _msh.register_global_module_import('._marshal', __package__)
@@ -0,0 +1,18 @@
1
+ from omlish import lang
2
+ from omlish import marshal as msh
3
+
4
+
5
+ ##
6
+
7
+
8
+ def _set_class_marshal_options(cls):
9
+ msh.update_object_metadata(
10
+ cls,
11
+ field_defaults=msh.FieldMetadata(
12
+ options=msh.FieldOptions(
13
+ omit_if=lang.is_none,
14
+ ),
15
+ ),
16
+ )
17
+
18
+ return cls
@@ -0,0 +1,27 @@
1
+ from omlish import lang
2
+ from omlish import marshal as msh
3
+
4
+ from .chatcompletion.contentpart import ChatCompletionContentPart
5
+ from .chatcompletion.message import ChatCompletionMessage
6
+ from .chatcompletion.responseformat import ChatCompletionResponseFormat
7
+
8
+
9
+ ##
10
+
11
+
12
+ @lang.static_init
13
+ def _install_standard_marshaling() -> None:
14
+ for root_cls, tag_field in [
15
+ (ChatCompletionContentPart, 'type'),
16
+ (ChatCompletionMessage, 'role'),
17
+ (ChatCompletionResponseFormat, 'type'),
18
+ ]:
19
+ msh.install_standard_factories(*msh.standard_polymorphism_factories(
20
+ msh.polymorphism_from_subclasses(
21
+ root_cls,
22
+ naming=msh.Naming.SNAKE,
23
+ strip_suffix=msh.AutoStripSuffix,
24
+ ),
25
+ msh.FieldTypeTagging(tag_field),
26
+ unions='partial',
27
+ ))