ommlds 0.0.0.dev495__py3-none-any.whl → 0.0.0.dev496__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 (56) hide show
  1. ommlds/cli/backends/inject.py +2 -4
  2. ommlds/cli/content/messages.py +1 -1
  3. ommlds/cli/sessions/chat/drivers/user/inject.py +3 -2
  4. ommlds/minichain/__init__.py +67 -31
  5. ommlds/minichain/_dataclasses.py +2234 -1118
  6. ommlds/minichain/backends/impls/anthropic/protocol.py +2 -2
  7. ommlds/minichain/backends/impls/cerebras/protocol.py +2 -2
  8. ommlds/minichain/backends/impls/google/tools.py +2 -2
  9. ommlds/minichain/backends/impls/groq/protocol.py +2 -2
  10. ommlds/minichain/backends/impls/ollama/protocol.py +2 -2
  11. ommlds/minichain/backends/impls/openai/format.py +2 -2
  12. ommlds/minichain/chat/messages.py +22 -25
  13. ommlds/minichain/chat/templating.py +1 -1
  14. ommlds/minichain/content/__init__.py +9 -2
  15. ommlds/minichain/content/_marshal.py +159 -48
  16. ommlds/minichain/content/code.py +17 -0
  17. ommlds/minichain/content/dynamic.py +12 -0
  18. ommlds/minichain/content/images.py +3 -2
  19. ommlds/minichain/content/json.py +3 -2
  20. ommlds/minichain/content/namespaces.py +9 -0
  21. ommlds/minichain/content/placeholders.py +11 -9
  22. ommlds/minichain/content/quote.py +17 -0
  23. ommlds/minichain/content/raw.py +49 -0
  24. ommlds/minichain/content/section.py +14 -0
  25. ommlds/minichain/content/sequence.py +9 -4
  26. ommlds/minichain/content/{simple.py → standard.py} +3 -13
  27. ommlds/minichain/content/tag.py +4 -4
  28. ommlds/minichain/content/templates.py +14 -0
  29. ommlds/minichain/content/text.py +3 -2
  30. ommlds/minichain/content/transform/base.py +63 -0
  31. ommlds/minichain/content/transform/interleave.py +68 -0
  32. ommlds/minichain/content/transform/materialize.py +110 -0
  33. ommlds/minichain/content/{prepare.py → transform/prepare.py} +10 -11
  34. ommlds/minichain/content/transform/squeeze.py +59 -0
  35. ommlds/minichain/content/{transforms → transform}/stringify.py +0 -6
  36. ommlds/minichain/content/types.py +5 -17
  37. ommlds/minichain/lib/todo/tools/write.py +2 -1
  38. ommlds/minichain/tools/execution/errorhandling.py +2 -2
  39. ommlds/minichain/tools/execution/errors.py +2 -2
  40. ommlds/minichain/tools/jsonschema.py +2 -2
  41. ommlds/minichain/tools/reflect.py +3 -3
  42. ommlds/minichain/tools/types.py +11 -14
  43. {ommlds-0.0.0.dev495.dist-info → ommlds-0.0.0.dev496.dist-info}/METADATA +4 -4
  44. {ommlds-0.0.0.dev495.dist-info → ommlds-0.0.0.dev496.dist-info}/RECORD +50 -46
  45. ommlds/cli/sessions/chat/interfaces/bare/user.py +0 -31
  46. ommlds/minichain/content/cancontent.py +0 -32
  47. ommlds/minichain/content/materialize.py +0 -173
  48. ommlds/minichain/content/transforms/base.py +0 -46
  49. ommlds/minichain/content/transforms/interleave.py +0 -77
  50. ommlds/minichain/content/transforms/squeeze.py +0 -72
  51. /ommlds/minichain/content/{transforms → transform}/__init__.py +0 -0
  52. /ommlds/minichain/content/{transforms → transform}/strings.py +0 -0
  53. {ommlds-0.0.0.dev495.dist-info → ommlds-0.0.0.dev496.dist-info}/WHEEL +0 -0
  54. {ommlds-0.0.0.dev495.dist-info → ommlds-0.0.0.dev496.dist-info}/entry_points.txt +0 -0
  55. {ommlds-0.0.0.dev495.dist-info → ommlds-0.0.0.dev496.dist-info}/licenses/LICENSE +0 -0
  56. {ommlds-0.0.0.dev495.dist-info → ommlds-0.0.0.dev496.dist-info}/top_level.txt +0 -0
@@ -23,7 +23,7 @@ from omlish import metadata as md
23
23
  from omlish import reflect as rfl
24
24
  from omlish.lite.cached import cached_nullary
25
25
 
26
- from ..content.cancontent import CanContent
26
+ from ..content.types import Content
27
27
  from .types import EnumToolDtype
28
28
  from .types import MappingToolDtype
29
29
  from .types import NullableToolDtype
@@ -159,7 +159,7 @@ class ToolReflector:
159
159
 
160
160
  #
161
161
 
162
- def _prepare_desc(self, s: CanContent) -> CanContent:
162
+ def _prepare_desc(self, s: Content | None) -> Content | None:
163
163
  if s is None:
164
164
  return None
165
165
  if not self._raw_descs and isinstance(s, str):
@@ -240,7 +240,7 @@ class ToolReflector:
240
240
  ds_p = ds_p_dct.get(pn)
241
241
  sig_p = sig_p_dct.get(pn)
242
242
 
243
- p_desc: CanContent
243
+ p_desc: Content | None
244
244
  if (p_desc := ovr_p.get('desc')) is None:
245
245
  if ds_p is not None:
246
246
  p_desc = ds_p.description
@@ -6,13 +6,10 @@ from omlish import cached
6
6
  from omlish import check
7
7
  from omlish import collections as col
8
8
  from omlish import dataclasses as dc
9
- from omlish import dispatch
10
9
  from omlish import lang
11
10
  from omlish import marshal as msh
12
11
  from omlish import reflect as rfl
13
12
 
14
- from ..content.cancontent import CanContent
15
- from ..content.transforms.base import ContentTransform
16
13
  from ..content.types import Content
17
14
 
18
15
 
@@ -150,7 +147,7 @@ class ToolParam:
150
147
 
151
148
  _: dc.KW_ONLY
152
149
 
153
- desc: CanContent = None
150
+ desc: Content | None = None
154
151
 
155
152
  type: ToolDtype | None = None
156
153
 
@@ -168,12 +165,12 @@ class ToolSpec:
168
165
 
169
166
  _: dc.KW_ONLY
170
167
 
171
- desc: CanContent = None
168
+ desc: Content | None = None
172
169
 
173
170
  params: ta.Sequence[ToolParam] | None = None
174
171
  allow_additional_params: bool | None = None
175
172
 
176
- returns_desc: CanContent = None
173
+ returns_desc: Content | None = None
177
174
  returns_type: ToolDtype | None = None
178
175
 
179
176
  @cached.property
@@ -207,11 +204,11 @@ class ToolUseResult(lang.Final):
207
204
  ##
208
205
 
209
206
 
210
- class _ToolUseContentTransform(ContentTransform, lang.Final, lang.NotInstantiable):
211
- @dispatch.install_method(ContentTransform.apply)
212
- def apply_tool_use(self, tu: ToolUse) -> ToolUse:
213
- return tu # TODO: args are Content
214
-
215
- @dispatch.install_method(ContentTransform.apply)
216
- def apply_tool_use_result(self, tur: ToolUseResult) -> ToolUseResult:
217
- return dc.replace(tur, c=self.apply(tur.c)) # noqa
207
+ # class _ToolUseContentTransform(ContentTransform, lang.Final, lang.NotInstantiable):
208
+ # @dispatch.install_method(ContentTransform.apply)
209
+ # def apply_tool_use(self, tu: ToolUse) -> ToolUse:
210
+ # return tu # TODO: args are Content
211
+ #
212
+ # @dispatch.install_method(ContentTransform.apply)
213
+ # def apply_tool_use_result(self, tur: ToolUseResult) -> ToolUseResult:
214
+ # return dc.replace(tur, c=self.apply(tur.c)) # noqa
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ommlds
3
- Version: 0.0.0.dev495
3
+ Version: 0.0.0.dev496
4
4
  Summary: ommlds
5
5
  Author: wrmsr
6
6
  License-Expression: BSD-3-Clause
@@ -14,9 +14,9 @@ Classifier: Programming Language :: Python :: 3.13
14
14
  Requires-Python: >=3.13
15
15
  Description-Content-Type: text/markdown
16
16
  License-File: LICENSE
17
- Requires-Dist: omlish==0.0.0.dev495
17
+ Requires-Dist: omlish==0.0.0.dev496
18
18
  Provides-Extra: all
19
- Requires-Dist: omdev==0.0.0.dev495; extra == "all"
19
+ Requires-Dist: omdev==0.0.0.dev496; extra == "all"
20
20
  Requires-Dist: llama-cpp-python~=0.3; extra == "all"
21
21
  Requires-Dist: mlx~=0.30; sys_platform == "darwin" and extra == "all"
22
22
  Requires-Dist: mlx-lm~=0.29; sys_platform == "darwin" and extra == "all"
@@ -38,7 +38,7 @@ Requires-Dist: mwparserfromhell~=0.7; extra == "all"
38
38
  Requires-Dist: wikitextparser~=0.56; extra == "all"
39
39
  Requires-Dist: lxml>=5.3; python_version < "3.13" and extra == "all"
40
40
  Provides-Extra: omdev
41
- Requires-Dist: omdev==0.0.0.dev495; extra == "omdev"
41
+ Requires-Dist: omdev==0.0.0.dev496; extra == "omdev"
42
42
  Provides-Extra: backends
43
43
  Requires-Dist: llama-cpp-python~=0.3; extra == "backends"
44
44
  Requires-Dist: mlx~=0.30; sys_platform == "darwin" and extra == "backends"
@@ -109,12 +109,12 @@ ommlds/cli/secrets.py,sha256=8GHlewS3yeFDfFNekaYwRm4nG9l3nd-Mc8tKl9Ma_Uo,469
109
109
  ommlds/cli/backends/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
110
110
  ommlds/cli/backends/catalog.py,sha256=snQSdUyFiNJhvzVRShBqqp1bZpZlmoKvonypNMZz3HI,3002
111
111
  ommlds/cli/backends/configs.py,sha256=RvNWxsJDSsHc0eWA6hI1_3n__HU7rXAUmzS06ykMPh0,137
112
- ommlds/cli/backends/inject.py,sha256=xqf6wU6J5aWJJlFa3S2zxvcxocVJTqZLfjBRw0jArw4,4068
112
+ ommlds/cli/backends/inject.py,sha256=NBXfTNZiRD476FUn9TgzbaCTkm2RoOYSl97CoMLRYWE,3997
113
113
  ommlds/cli/backends/injection.py,sha256=aCscVcq0_gobzNgLEflGInFC9b_dtnuQgLZ0wX_iTWg,325
114
114
  ommlds/cli/backends/meta.py,sha256=wq10RYcUElF3Yudhky7bwte3EGk2ARk2odmRzDJQA_M,997
115
115
  ommlds/cli/backends/types.py,sha256=sut62bGJ3baDbQs3-AwnOwJrvw0VTysqQw8f3yJww8w,966
116
116
  ommlds/cli/content/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
117
- ommlds/cli/content/messages.py,sha256=njaZyEOglagkcmmB7TtoPoATIx5zgr5f6ijPQwMsfSA,937
117
+ ommlds/cli/content/messages.py,sha256=4qW8ac2umJxnehNI0eS0sqVWlzjv8BDDg4WBOOx-pkM,925
118
118
  ommlds/cli/content/strings.py,sha256=pSzQQFYP-RYlpVuVs8HXk_fGlOo-1IT1yAS8umidrzw,1053
119
119
  ommlds/cli/inputs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
120
120
  ommlds/cli/inputs/asyncs.py,sha256=V7f68qvYD_VFQPUXJPrytL-eqiC3rbUaaijAAjJrFRU,686
@@ -184,7 +184,7 @@ ommlds/cli/sessions/chat/drivers/tools/weather/inject.py,sha256=HSB6gCp23T2HME07
184
184
  ommlds/cli/sessions/chat/drivers/tools/weather/tools.py,sha256=tGkr97D-60Lgsnjs1nSqV5BEZrTNlcaU_TFCY4ZRQyE,304
185
185
  ommlds/cli/sessions/chat/drivers/user/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
186
186
  ommlds/cli/sessions/chat/drivers/user/configs.py,sha256=tBSP2j1Bynn0Qt_S0GNUuNniMWivVSCFad3H4UCS3qY,280
187
- ommlds/cli/sessions/chat/drivers/user/inject.py,sha256=eV6kcrxC-XR_rHLWsvIanxq5mMWvvwqhbF3O-REDdxM,1408
187
+ ommlds/cli/sessions/chat/drivers/user/inject.py,sha256=07l_ihIdFFnyG3IYq9LJZL9neTNgpFzf7Mf5nilWekI,1465
188
188
  ommlds/cli/sessions/chat/facades/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
189
189
  ommlds/cli/sessions/chat/facades/configs.py,sha256=883rajnBaJITfYSEhcZ405VMvoCO9a0gELjuj01Qg_Q,199
190
190
  ommlds/cli/sessions/chat/facades/facade.py,sha256=3O8IdcuPquCA8fKMjmaj3p0P-OpNAgNRMs5tyMfqcM8,614
@@ -208,7 +208,6 @@ ommlds/cli/sessions/chat/interfaces/bare/inject.py,sha256=GzeCBcwppVAUlXG61vSQZU
208
208
  ommlds/cli/sessions/chat/interfaces/bare/interactive.py,sha256=ZnYoePvXtUbhkDQ0jM5gldk-bBrFH_V5oc8O1fuiYcI,1229
209
209
  ommlds/cli/sessions/chat/interfaces/bare/oneshot.py,sha256=b758OIa0gf9I_0UdxYJ6re-g8-8xndgr3R0OotUOsmc,387
210
210
  ommlds/cli/sessions/chat/interfaces/bare/tools.py,sha256=_UsuoXLIvfpFP_We5DBBlhm6rwB3_cFA3lmFvpG9b-A,824
211
- ommlds/cli/sessions/chat/interfaces/bare/user.py,sha256=gZgfuQAnU_MH_Awb-Ut6sJE_Di4jvquKOkBT415NmR0,877
212
211
  ommlds/cli/sessions/chat/interfaces/textual/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
213
212
  ommlds/cli/sessions/chat/interfaces/textual/app.py,sha256=Ecn4qawdUId-fGhHUXrhEEDDkIUwzOnyKtlBnCrwf2o,9133
214
213
  ommlds/cli/sessions/chat/interfaces/textual/configs.py,sha256=HD8DlWXYJ1M94gr5TIT6oqsFCmOf5Gd6KkSBZUtySew,180
@@ -237,8 +236,8 @@ ommlds/cli/state/storage.py,sha256=Wr8DVuEGUxfFJn0tMWNTVdint6NBDdLKstNWSjx8sKw,3
237
236
  ommlds/datasets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
238
237
  ommlds/datasets/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
239
238
  ommlds/datasets/lib/movies.py,sha256=LmdfoXsZU9XMM_r-sxCLv_s06BFzwWO4xUj6sc9XVcI,1961
240
- ommlds/minichain/__init__.py,sha256=E4MOol7eWSbKgEZXfDaDJSz6Fj5Al7wAYh-42roYxMI,11656
241
- ommlds/minichain/_dataclasses.py,sha256=MqrzAPmI3L8wfrfluDKg0iLuY7VQXH3uPAPdxxKWy6k,861996
239
+ ommlds/minichain/__init__.py,sha256=wJMDzDh0qQfAMWC61VH8IOT6SIK4nNbG6YGubBuVueo,12311
240
+ ommlds/minichain/_dataclasses.py,sha256=vXkMx3Hip0mp5crdmrgAVwYwDoonwGGn4DJdiobl4wU,913466
242
241
  ommlds/minichain/_marshal.py,sha256=n9PGWrHhvAmGIc7KDOYt3IF9Z6G0ncXskyICTp3Ji6k,1923
243
242
  ommlds/minichain/_typedvalues.py,sha256=Vl1Edt5khC0e5RPFBPmPCxn0IzrfVd0NHzAjAN2E6Kc,2183
244
243
  ommlds/minichain/completion.py,sha256=lQ0LfCIYZsvDqteHhhDIv16D2_gn_xMfEL0ouywE5Yo,1033
@@ -263,12 +262,12 @@ ommlds/minichain/backends/impls/tavily.py,sha256=k67QQF4cL8vMtE5LOXxczNFMGlMeRWV
263
262
  ommlds/minichain/backends/impls/anthropic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
264
263
  ommlds/minichain/backends/impls/anthropic/chat.py,sha256=e4Kcbjvca_yaZsNB_-h335gSCbz4ma1lMUvuR4WzEFE,4874
265
264
  ommlds/minichain/backends/impls/anthropic/names.py,sha256=GPPeYt0CcDcDCR8I6BMd7bMjC_Zk_bjnLLpF9ClwXcg,1099
266
- ommlds/minichain/backends/impls/anthropic/protocol.py,sha256=whPVYuKShKiMCzasHl77sCIiymhzXj8mFZXEyhZvld8,3292
265
+ ommlds/minichain/backends/impls/anthropic/protocol.py,sha256=eMqkl7ML5btqJ27_9l6RY2zdTMsQe0k3Kn_keNq0-Mk,3337
267
266
  ommlds/minichain/backends/impls/anthropic/stream.py,sha256=jxKzytoYJLK9JftihGhWTcFIoXFgouQR7Yu5Q1j_ku8,8794
268
267
  ommlds/minichain/backends/impls/cerebras/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
269
268
  ommlds/minichain/backends/impls/cerebras/chat.py,sha256=FbwXrOMbHIIzO8gLZsyI3faYJYFYWPcxZTMxcpIaB4Y,2858
270
269
  ommlds/minichain/backends/impls/cerebras/names.py,sha256=NcJF7Py3y8EiQUJ5gL3KV2l25rpsi4Hc3_bwHv7lncQ,574
271
- ommlds/minichain/backends/impls/cerebras/protocol.py,sha256=nceKmwpwU9HCEVStPqrIa55pi86RiPokrsAs5r034lM,5221
270
+ ommlds/minichain/backends/impls/cerebras/protocol.py,sha256=9ldK0_XM7il0JX3jjcLL8svBiRANrgY65V1Dq4ANevw,5268
272
271
  ommlds/minichain/backends/impls/cerebras/stream.py,sha256=gMGlP_QNQ9h8qGZSoFwEZ-mpND7_hx86y3smrsLrUX8,5150
273
272
  ommlds/minichain/backends/impls/duckduckgo/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
274
273
  ommlds/minichain/backends/impls/duckduckgo/search.py,sha256=HA5UriBVvNw6-6vmeYJsm83LxsFsksLtzFxj-kdzoPE,1010
@@ -279,11 +278,11 @@ ommlds/minichain/backends/impls/google/chat.py,sha256=lGb5blGLlcBlt9xeDZJvbh5SlV
279
278
  ommlds/minichain/backends/impls/google/names.py,sha256=HxHJ31HeKZg6aW1C_Anqp-gamCXpq9pOdKj8_yVgE8Y,871
280
279
  ommlds/minichain/backends/impls/google/search.py,sha256=y5_6seSRU8CFnLA_Ja8XEMbIBWSgwBzE1iBf-qyz0tA,3427
281
280
  ommlds/minichain/backends/impls/google/stream.py,sha256=AT8qbP0EqJUnf-D45aTbEQ0h5lvgtIK6XKki0t8RkZE,8029
282
- ommlds/minichain/backends/impls/google/tools.py,sha256=Tty0gsyx7-PbeoNqMuql_ewQ6q-ZsDaDdsD5ShinGVY,5089
281
+ ommlds/minichain/backends/impls/google/tools.py,sha256=bP4bqHt1oZTvrcObkjQCNAUJEXrR9fFIRuvjsVFM910,5109
283
282
  ommlds/minichain/backends/impls/groq/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
284
283
  ommlds/minichain/backends/impls/groq/chat.py,sha256=XXJznM6h2fBBtrY8MggMUNJf8thyFTM3p1XzFImwkAk,2743
285
284
  ommlds/minichain/backends/impls/groq/names.py,sha256=RnvBSytxPF1a9Bj_OPVELuD1nAKJnJrG3ZwJfYo6Szs,1075
286
- ommlds/minichain/backends/impls/groq/protocol.py,sha256=FPydA4ftMhXFLEfYjmHsmNdBoM4gcEthvqmeX5yB3pc,5214
285
+ ommlds/minichain/backends/impls/groq/protocol.py,sha256=QNvqcfR9FbAIJv1fVerayws5gYU1am3oLFXmYMnQdX4,5261
287
286
  ommlds/minichain/backends/impls/groq/stream.py,sha256=5PZHrs_QNyKofJClKq5R5aOsq-H26UeWH7uncbJGrmI,5124
288
287
  ommlds/minichain/backends/impls/huggingface/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
289
288
  ommlds/minichain/backends/impls/huggingface/configs.py,sha256=6jsBtPNXOP57PcpxNTVLGWLc-18Iwn_lDbGouwCJTIQ,258
@@ -297,12 +296,12 @@ ommlds/minichain/backends/impls/mlx/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQ
297
296
  ommlds/minichain/backends/impls/mlx/chat.py,sha256=tmZZAmVg-XcbxZYGNHrKC0hiJbxW88pgEHqIEC5D2Xc,7536
298
297
  ommlds/minichain/backends/impls/ollama/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
299
298
  ommlds/minichain/backends/impls/ollama/chat.py,sha256=vCf_Pw9_4D-gNFD7OrIbWnEOqJE_Vxb_mxiZ0NgCP4c,6816
300
- ommlds/minichain/backends/impls/ollama/protocol.py,sha256=1G5B1dtLdfOQVI32fSgzMaqN0iPv_WZkn1p6KKVgUNM,4749
299
+ ommlds/minichain/backends/impls/ollama/protocol.py,sha256=zB0Q6PChiRlskDhjvpXIb3pSeLcH1wFg5QUqfo20R-s,4796
301
300
  ommlds/minichain/backends/impls/openai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
302
301
  ommlds/minichain/backends/impls/openai/chat.py,sha256=G1IK94PwB16rYCkRos9JEuiAu1GgCK4CnZFOIShhpig,2856
303
302
  ommlds/minichain/backends/impls/openai/completion.py,sha256=4Mi4Zvrq5fCqUd0asL3WiCbCdmxOdo0NFkoZMfdsYXY,1939
304
303
  ommlds/minichain/backends/impls/openai/embedding.py,sha256=BNtvKYLTsnQwQR9Tv3Fr8zCYN1kr1UNdJ15lcsjz6X0,1765
305
- ommlds/minichain/backends/impls/openai/format.py,sha256=dAvaqi3LhPu7N9S8BDBkuGSWdD_cxkBEIXPLChcGWdk,7414
304
+ ommlds/minichain/backends/impls/openai/format.py,sha256=wIAwgvCkzEP2HdTUMeaZqJhEV2UJddS462WpvK0oduU,7457
306
305
  ommlds/minichain/backends/impls/openai/names.py,sha256=M1spn4Yio6LEnKWEzPqXSrzJg3wsf2M1iZIYFAvxb80,1550
307
306
  ommlds/minichain/backends/impls/openai/stream.py,sha256=bsZeGUepqOl9AcN44kWk03V6q-v1ewBCfZqb_MJEfxg,5454
308
307
  ommlds/minichain/backends/impls/sentencepiece/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -323,10 +322,10 @@ ommlds/minichain/chat/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3h
323
322
  ommlds/minichain/chat/_marshal.py,sha256=M3p093nxzxITbznc--P-tyCXuWDHrq4JFKTZAx6XWdk,740
324
323
  ommlds/minichain/chat/formats.py,sha256=LmlU7iu8PMJuroFTmyWfP4tXvLjj5VNxdAp1Us9MSAA,562
325
324
  ommlds/minichain/chat/history.py,sha256=GI10mTCr8yv0mxJRK-YVtYqOuUjBvX5Su5FYYmLpPxU,1566
326
- ommlds/minichain/chat/messages.py,sha256=fAMbuwFv_rwuJSaYaGBN_B7jXeyZUSKek7gaPa8eYhQ,3577
325
+ ommlds/minichain/chat/messages.py,sha256=zTIMLvZM33_sFmRbl3ohEAy3jTgPGAIa1Fjg-_0Bi2w,3480
327
326
  ommlds/minichain/chat/metadata.py,sha256=V8EUqUsiAITtIae8SC_4YyyBBvciG34jRuSylql4AvU,248
328
327
  ommlds/minichain/chat/services.py,sha256=HzP35CLOz-vCptUUpuehI5yNJorTtY64gwrb6ZWNfwI,919
329
- ommlds/minichain/chat/templating.py,sha256=pUgYC6N9-IGr3TXWt-uN5pTQ5XVt5S0--xA2_7u-37E,3148
328
+ ommlds/minichain/chat/templating.py,sha256=3P46me6H_cY-hTqVW4jK7lFAbuUuwpsZX9QOYg5QB6s,3147
330
329
  ommlds/minichain/chat/types.py,sha256=tHYR1jRGEStNbcDebMrEuHQBNpYh8id2MS0-1Fzxwgs,430
331
330
  ommlds/minichain/chat/choices/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
332
331
  ommlds/minichain/chat/choices/adapters.py,sha256=Keroaj0B5YEYPF3k0fOQK6JUZnM1XVFThGB5Uv689Sc,629
@@ -351,27 +350,32 @@ ommlds/minichain/chat/transforms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRk
351
350
  ommlds/minichain/chat/transforms/base.py,sha256=V22SasLdnzvmSO7C19gigi8LKeWVtBHmhaSJbkj6b4Y,2923
352
351
  ommlds/minichain/chat/transforms/metadata.py,sha256=Gw1cUIk2cVzHMyFPwboY_HWEuV_Ts3R4AVmOuyH120A,1563
353
352
  ommlds/minichain/chat/transforms/services.py,sha256=wJw2eu-TU1sVXUYvg7rc7QNn93cCXhtEI_q-KZ5Dz0I,1016
354
- ommlds/minichain/content/__init__.py,sha256=nHXG5a6KSoM9xqlvA4jfwVNbCtqV88bg7298PmmNJKA,384
355
- ommlds/minichain/content/_marshal.py,sha256=_ND3TPg5DscnK8BuZNunAhLrmYLShGB-6KRGqH0oe2E,6122
356
- ommlds/minichain/content/cancontent.py,sha256=AlHvdCZqIqMe7sElTp3cHsDAZsk9muotdNaodszn6AE,549
357
- ommlds/minichain/content/images.py,sha256=d69MgAQm9DaslJJIqRJNY3f75t_Ti5aqkGG1Ypi5Iew,426
358
- ommlds/minichain/content/json.py,sha256=g4QjFLYJQUE38u5nd1QzNgruwl06efyaBjiq5ehftd0,250
359
- ommlds/minichain/content/materialize.py,sha256=9APT8cjkpd30g7e29Cj-PFThARnUPno2VaEXNQFGcWY,4880
353
+ ommlds/minichain/content/__init__.py,sha256=dQGwU7lJ2i1Khhm7vu-bgCXA-SSzZGbRSnED0YbJSSA,503
354
+ ommlds/minichain/content/_marshal.py,sha256=72XnBsUaYDsmjnYMNEeaU0g7LxMCpa4FU9qG9WbEvHY,9195
355
+ ommlds/minichain/content/code.py,sha256=lw-jc-U-op6lIdbzu9wz3HZpPKm6jx3RQvwLoGFpr1o,285
356
+ ommlds/minichain/content/dynamic.py,sha256=vXOdc7roBoL7C9DXPo9K4KZFeehJAH-Woq_YN3v13wU,197
357
+ ommlds/minichain/content/images.py,sha256=9q53vOsb2miAT_8xT-7G1DgrruELySzNXiLgT0VoabI,448
358
+ ommlds/minichain/content/json.py,sha256=OYwS_bW1RVyaenpetc_k-SXgGHxx9KJOxNzA_Xy9sv0,272
360
359
  ommlds/minichain/content/metadata.py,sha256=FcWW8YbtDEz5rmucvfqjMTC4aA6rO2WQJtP0lX_DShs,248
361
- ommlds/minichain/content/namespaces.py,sha256=KkIrwQZ_9bojw5ytkNX8-5FI4ZdCEAEnMAUElx6p51Y,95
362
- ommlds/minichain/content/placeholders.py,sha256=NMl2m5yVVv9fnNinyXP_UKoa7ZDUIArZqwbbj5f96yI,526
363
- ommlds/minichain/content/prepare.py,sha256=ZVXmFg2f0UULwrTjb5VjZygpird9Qox6JsI1QWcQHgw,1903
364
- ommlds/minichain/content/sequence.py,sha256=DkU0iRlxGchPa77-V7HZfzTXmLTaFqGIFBcjV2p3fmo,580
365
- ommlds/minichain/content/simple.py,sha256=8Psf7n50Z9uMVhxWesQVveHSFX78EKdPEGG5Wm3LDP8,1199
366
- ommlds/minichain/content/tag.py,sha256=VoLW3Yl66KpBaueyFRwtodXvWdbzHjtuGMXN6o8CcTI,379
367
- ommlds/minichain/content/text.py,sha256=kcadL2Ojq7AwNdT_vMk5EhOC3mZpFTFpKbMjdkfUoos,215
368
- ommlds/minichain/content/types.py,sha256=fJhf55HNJP-tTKf_yd_n_4XFBmJkoNF912NU0-QyQDU,575
369
- ommlds/minichain/content/transforms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
370
- ommlds/minichain/content/transforms/base.py,sha256=omdEId9FZbeCk8Aak-oMJpMiY4vK4nrQWAbhzmsHZkc,1054
371
- ommlds/minichain/content/transforms/interleave.py,sha256=sQRXk9M7g9iF4weJf71oD_kgJsCbg9clA0EIZgexhSc,2478
372
- ommlds/minichain/content/transforms/squeeze.py,sha256=Bf9lKjR3pRQBT0BabH8YRRlR31KO8tpHQX_mzWsxT3U,1672
373
- ommlds/minichain/content/transforms/stringify.py,sha256=-DhAkRQeRzh-ULQFP25HipyKdrR1lKooGEyw6BwEg-w,1237
374
- ommlds/minichain/content/transforms/strings.py,sha256=-uEZ8dXnl_5dNfkwedBeUGzCiAWJn-B4DGMeM0hX3dA,466
360
+ ommlds/minichain/content/namespaces.py,sha256=nr9KdKiL1DJyZF059QJGa7NJanAMBgwP5bo7ffnSles,325
361
+ ommlds/minichain/content/placeholders.py,sha256=CsGTYAPPu1COKLss5jzLpn0qeoN56yBpLJs3qr6f0F4,416
362
+ ommlds/minichain/content/quote.py,sha256=Cn03AYZEaK_wGZgPgdi1S9ffwJSCB8x8OZ4y_ZtZZVY,257
363
+ ommlds/minichain/content/raw.py,sha256=evB4Vv7Tk42tQrVf5-f78wdjeXEqwcdWEz0pt7z58WQ,676
364
+ ommlds/minichain/content/section.py,sha256=iYtNUYl5tV7qfyD1a2rxtAPn3VKCQ_zYqsJa95Su7J8,246
365
+ ommlds/minichain/content/sequence.py,sha256=cuTzM48Dgdn2wyfIPcN9-kL7jHM1sn0WHabeAokZ4Jw,649
366
+ ommlds/minichain/content/standard.py,sha256=uKECecSSiOVnNYXuVWPkAMkYa0-uLXRW2vumwDMOn50,995
367
+ ommlds/minichain/content/tag.py,sha256=1uA9kctmjYd-ftgSmVkOAebydKAj0EdgduvZP7erYaQ,358
368
+ ommlds/minichain/content/templates.py,sha256=S09GAjBX_qeRTIgtd7lXs4EFzM-ujsbEbJbsnuj9wO0,290
369
+ ommlds/minichain/content/text.py,sha256=BcptL8PETJc1f7bBLHf51949E_UOhzAn1MzvanjJEgg,237
370
+ ommlds/minichain/content/types.py,sha256=wgZRE164BkJAkRi3tcwEZGvSfw_15MIRy5mxah-v5gQ,361
371
+ ommlds/minichain/content/transform/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
372
+ ommlds/minichain/content/transform/base.py,sha256=6w2Uk-DpYyL0_I-jZ-qCz6Trw_R-wJTeE61T_bMxDQ0,1829
373
+ ommlds/minichain/content/transform/interleave.py,sha256=M3FkEyFBR6N51wBltrpoNGDyI6Cpj0sTUUiho73fD8c,2308
374
+ ommlds/minichain/content/transform/materialize.py,sha256=0MTzUmbJnTlvMoBXwBGjeHqGUNACZicUzjrapASKvWU,3078
375
+ ommlds/minichain/content/transform/prepare.py,sha256=Olh2cBckcq438h0NL2kGymrQLLNUO1cBVK3W7o2d07k,1818
376
+ ommlds/minichain/content/transform/squeeze.py,sha256=8TL2G0-pFxVk63IVhbGbFVoeuYkKQMunBQfgNRNFTEE,1415
377
+ ommlds/minichain/content/transform/stringify.py,sha256=PwA4T7qBUBDfSfuV6UXibBSDC5NwbgZt-A2rkXDx0Ts,1063
378
+ ommlds/minichain/content/transform/strings.py,sha256=-uEZ8dXnl_5dNfkwedBeUGzCiAWJn-B4DGMeM0hX3dA,466
375
379
  ommlds/minichain/docs/__init__.py,sha256=vNpT6sA5YDalFqsCFn0DjUvarxRtRl3w2V9liEU0CQk,364
376
380
  ommlds/minichain/docs/docs.py,sha256=Ex7hiqaiYDB9hQhUjuzot8MFktl3LIGG41YBFaNoC80,1340
377
381
  ommlds/minichain/docs/dtypes.py,sha256=BRZmLK9NfQwITBYmDOmRPDlFg1RP5BYWT0Xw04AinF8,499
@@ -398,7 +402,7 @@ ommlds/minichain/lib/todo/context.py,sha256=ne3kUvP2QRd9hCE9KbJIGI-ugA6fOKoqcK4V
398
402
  ommlds/minichain/lib/todo/types.py,sha256=oypIB9tIbMeZBk5MAl0uETqxJFsZ7hRrVOandLnS82I,1592
399
403
  ommlds/minichain/lib/todo/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
400
404
  ommlds/minichain/lib/todo/tools/read.py,sha256=7P8ohR-t9y9f_iF-kr0JA36ti0LhJCeBpMsnXeXwHoU,1501
401
- ommlds/minichain/lib/todo/tools/write.py,sha256=TGO-zuF62j61pB8tFxd9wdtMHrYuVvnwnjinMOOGabk,14734
405
+ ommlds/minichain/lib/todo/tools/write.py,sha256=AVLW9iEHrukFoPILDchb7qvJUP-CbEuUM9-GNFqXVyU,14804
402
406
  ommlds/minichain/llms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
403
407
  ommlds/minichain/llms/_marshal.py,sha256=YR7n2GVhS9I2rDvKe-VqzS-u1WbLcJT9DgFBO6oZ9fo,1518
404
408
  ommlds/minichain/llms/tokens.py,sha256=RPrAzf4Qx9xNPGj7_EkzcVOR9qIGkhQg8AM6qhr7gfw,292
@@ -444,14 +448,14 @@ ommlds/minichain/tokens/vocabs.py,sha256=-4WSCbeeoELLiAaRSzbi-z6Cv-hyTRK1T9HMm_i
444
448
  ommlds/minichain/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
445
449
  ommlds/minichain/tools/_marshal.py,sha256=9np2tuzGfRwL5BMCd6QYChzimtTBUfHxT4IoEA6v3Eg,410
446
450
  ommlds/minichain/tools/fns.py,sha256=UVgj9f0vnjFzP5uP4zpN4slOA5nEOD8Ob1aJwKrSggA,3930
447
- ommlds/minichain/tools/jsonschema.py,sha256=20i3Yrw91nzgYRcZfVfrDjtFEpGD1Gc_5iiFhq1KV8w,4233
448
- ommlds/minichain/tools/reflect.py,sha256=-fZE68XeUvDR7WTEKuMk3zurUFZ_undNH0b6aBtvesQ,8693
449
- ommlds/minichain/tools/types.py,sha256=_6LVw_iW7vcn6or29_vuBRYGdYM0FRsYgGmQRjwbYuY,4867
451
+ ommlds/minichain/tools/jsonschema.py,sha256=gipEyit6OmVAa02Azhk8xbFHlolWXd0Jp5x_fvAzdHg,4253
452
+ ommlds/minichain/tools/reflect.py,sha256=TdE9qyiRqKisf4VST9Cng-I_lsSNdSxSXJ1g1TOyXHE,8697
453
+ ommlds/minichain/tools/types.py,sha256=_8G7ZeHwF8buSTvl30bz0n3Pc0LX57G4F9YQViZaGGg,4767
450
454
  ommlds/minichain/tools/execution/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
451
455
  ommlds/minichain/tools/execution/catalog.py,sha256=sBde49FSClTreX8KO5pZ2-EE1NyTZOoagNdowN3n5pE,2002
452
456
  ommlds/minichain/tools/execution/context.py,sha256=Gdl1UNjzLQTeIc7m2BlNyLtNsdqCookQv12_WwDDkAI,1872
453
- ommlds/minichain/tools/execution/errorhandling.py,sha256=WLsr--DxMNkOfQinc6-Pn9XmHJfyH5AoXfy0U9KyZbE,930
454
- ommlds/minichain/tools/execution/errors.py,sha256=MEBdGERB3OO3fCjYa7dF2f7NnIo98gxYa3PUY4sKv-k,250
457
+ ommlds/minichain/tools/execution/errorhandling.py,sha256=6ZymDv9BmYpS9ERt7OD_h5mLcaHNtHaLjL3vRsyWhEk,934
458
+ ommlds/minichain/tools/execution/errors.py,sha256=rom0RTc2GUy1TbuJeA-aMagp_TMTIw33kH-1MMzOX2s,239
455
459
  ommlds/minichain/tools/execution/executors.py,sha256=cyx7JKKQfuqSVujNLXSo0qtXSkCDJ_plddvitmDUxeQ,1365
456
460
  ommlds/minichain/tools/execution/reflect.py,sha256=Oklzx5jlMyNj6ivecEQfP6Zt_ICxc-nk-x9xSsxswlg,1817
457
461
  ommlds/minichain/vectors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -493,9 +497,9 @@ ommlds/wiki/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
493
497
  ommlds/wiki/utils/io.py,sha256=UKgDJGtmpnWvIqVd2mJc2QNPOqlToEY1GEveNp6_pMo,7088
494
498
  ommlds/wiki/utils/progress.py,sha256=EhvKcMFYtsarCQhIahlO6f0SboyAKP3UwUyrnVnP-Vk,3222
495
499
  ommlds/wiki/utils/xml.py,sha256=sNJNkZ9rT8B-kJMO6bRz8J1USy4fyPx0m2PwTX7vxYY,3846
496
- ommlds-0.0.0.dev495.dist-info/licenses/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
497
- ommlds-0.0.0.dev495.dist-info/METADATA,sha256=cG4wdKEIMrlxFByBKtdbI5zNlvrI_fS7Gy5pM1EF3K0,3495
498
- ommlds-0.0.0.dev495.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
499
- ommlds-0.0.0.dev495.dist-info/entry_points.txt,sha256=Z5YWtX7ClfiCKdW-dd_CSVvM0h4yQpJPi-2G3q6gNFo,35
500
- ommlds-0.0.0.dev495.dist-info/top_level.txt,sha256=Rbnk5d5wi58vnAXx13WFZqdQ4VX8hBCS2hEL3WeXOhY,7
501
- ommlds-0.0.0.dev495.dist-info/RECORD,,
500
+ ommlds-0.0.0.dev496.dist-info/licenses/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
501
+ ommlds-0.0.0.dev496.dist-info/METADATA,sha256=Dd3WP3Uj6LhCcjwlsgJVmp13K6J7Q5j59328QOLpg80,3495
502
+ ommlds-0.0.0.dev496.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
503
+ ommlds-0.0.0.dev496.dist-info/entry_points.txt,sha256=Z5YWtX7ClfiCKdW-dd_CSVvM0h4yQpJPi-2G3q6gNFo,35
504
+ ommlds-0.0.0.dev496.dist-info/top_level.txt,sha256=Rbnk5d5wi58vnAXx13WFZqdQ4VX8hBCS2hEL3WeXOhY,7
505
+ ommlds-0.0.0.dev496.dist-info/RECORD,,
@@ -1,31 +0,0 @@
1
- import typing as ta
2
-
3
- from ...... import minichain as mc
4
- from .....inputs.asyncs import AsyncStringInput
5
- from .....inputs.asyncs import SyncAsyncStringInput
6
- from .....inputs.sync import InputSyncStringInput
7
- from ...drivers.user.types import UserChatInput
8
-
9
-
10
- ##
11
-
12
-
13
- class InteractiveUserChatInput(UserChatInput):
14
- DEFAULT_STRING_INPUT: ta.ClassVar[AsyncStringInput] = SyncAsyncStringInput(InputSyncStringInput())
15
-
16
- def __init__(
17
- self,
18
- string_input: AsyncStringInput | None = None,
19
- ) -> None:
20
- super().__init__()
21
-
22
- if string_input is None:
23
- string_input = self.DEFAULT_STRING_INPUT
24
- self._string_input = string_input
25
-
26
- async def get_next_user_messages(self) -> 'mc.UserChat':
27
- try:
28
- s = await self._string_input()
29
- except EOFError:
30
- return []
31
- return [mc.UserMessage(s)]
@@ -1,32 +0,0 @@
1
- import typing as ta
2
-
3
- from omlish.text import templating as tpl
4
-
5
- from .namespaces import ContentNamespace
6
- from .placeholders import ContentPlaceholder
7
- from .placeholders import ContentPlaceholderMarker
8
- from .types import ExtendedContent
9
-
10
-
11
- ##
12
-
13
-
14
- _InnerCanContent: ta.TypeAlias = ta.Union[ # noqa
15
- str,
16
- ExtendedContent,
17
-
18
- ContentPlaceholder,
19
- type[ContentPlaceholderMarker],
20
-
21
- type[ContentNamespace],
22
-
23
- tpl.Templater,
24
- ]
25
-
26
- CanContent: ta.TypeAlias = ta.Union[ # noqa
27
- ta.Iterable['CanContent'],
28
-
29
- None,
30
-
31
- _InnerCanContent,
32
- ]
@@ -1,173 +0,0 @@
1
- """
2
- TODO:
3
- - ExtendedCanContent
4
- """
5
- import typing as ta
6
-
7
- from omlish import check
8
- from omlish import dataclasses as dc
9
- from omlish import dispatch
10
- from omlish.text import templating as tpl
11
-
12
- from .cancontent import CanContent
13
- from .namespaces import ContentNamespace
14
- from .placeholders import ContentPlaceholder
15
- from .placeholders import ContentPlaceholderMarker
16
- from .types import Content
17
- from .types import ExtendedContent
18
-
19
-
20
- ##
21
-
22
-
23
- ContentPlaceholderKey: ta.TypeAlias = ContentPlaceholder | type[ContentPlaceholderMarker]
24
- ContentPlaceholderMap: ta.TypeAlias = ta.Mapping[ContentPlaceholderKey, CanContent]
25
- ContentPlaceholderFn: ta.TypeAlias = ta.Callable[[ContentPlaceholderKey], CanContent]
26
- ContentPlaceholders: ta.TypeAlias = ContentPlaceholderMap | ContentPlaceholderFn
27
-
28
-
29
- @dc.dataclass()
30
- class ContentPlaceholderMissingError(Exception):
31
- key: ContentPlaceholderKey
32
-
33
-
34
- def _make_content_placeholder_fn(cps: ContentPlaceholders | None = None) -> ContentPlaceholderFn:
35
- if cps is None:
36
- def none_fn(cpk: ContentPlaceholderKey) -> CanContent:
37
- raise ContentPlaceholderMissingError(cpk)
38
-
39
- return none_fn
40
-
41
- elif isinstance(cps, ta.Mapping):
42
- def mapping_fn(cpk: ContentPlaceholderKey) -> CanContent:
43
- try:
44
- return cps[cpk]
45
- except KeyError:
46
- raise ContentPlaceholderMissingError(cpk) from None
47
-
48
- return mapping_fn
49
-
50
- elif callable(cps):
51
- return cps
52
-
53
- else:
54
- raise TypeError(cps)
55
-
56
-
57
- ##
58
-
59
-
60
- class ContentDepthExceededError(Exception):
61
- pass
62
-
63
-
64
- class ContentMaterializer:
65
- DEFAULT_MAX_DEPTH: int = 100
66
-
67
- def __init__(
68
- self,
69
- *,
70
- content_placeholders: ContentPlaceholders | None = None,
71
- templater_context: tpl.Templater.Context | None = None,
72
- max_depth: int = DEFAULT_MAX_DEPTH,
73
- ) -> None:
74
- super().__init__()
75
-
76
- self._templater_context = templater_context
77
- self._content_placeholders_fn = _make_content_placeholder_fn(content_placeholders)
78
- self._max_depth = max_depth
79
-
80
- self._cur_depth = 0
81
-
82
- def materialize(self, o: CanContent) -> Content:
83
- if self._cur_depth >= self._max_depth:
84
- raise ContentDepthExceededError
85
-
86
- self._cur_depth += 1
87
- try:
88
- return self._materialize(o)
89
- finally:
90
- self._cur_depth -= 1
91
-
92
- @dispatch.method()
93
- def _materialize(self, o: CanContent) -> Content:
94
- raise TypeError(o)
95
-
96
- #
97
-
98
- @_materialize.register
99
- def _materialize_str(self, o: str) -> Content:
100
- return o
101
-
102
- @_materialize.register
103
- def _materialize_extended_content(self, o: ExtendedContent) -> Content:
104
- return o
105
-
106
- #
107
-
108
- @_materialize.register
109
- def _materialize_iterable(self, o: ta.Iterable) -> Content:
110
- # `collections.abc.Iterable` appears as a virtual base in the dispatch c3.mro for ContentNamespace before `type`
111
- # does (due to NamespaceMeta having `__iter__`), so handle that here too.
112
- if isinstance(o, type) and issubclass(o, ContentNamespace):
113
- return self._materialize_namespace_type(o)
114
-
115
- else:
116
- return [self.materialize(e) for e in o]
117
-
118
- @_materialize.register
119
- def _materialize_none(self, o: None) -> Content:
120
- return []
121
-
122
- #
123
-
124
- @_materialize.register
125
- def _materialize_placeholder(self, o: ContentPlaceholder) -> Content:
126
- return self.materialize(self._content_placeholders_fn(o))
127
-
128
- def _materialize_placeholder_marker_type(self, o: type[ContentPlaceholderMarker]) -> Content:
129
- check.issubclass(o, ContentPlaceholderMarker)
130
- return self.materialize(self._content_placeholders_fn(o))
131
-
132
- #
133
-
134
- def _materialize_namespace_type(self, o: type[ContentNamespace]) -> Content:
135
- check.issubclass(o, ContentNamespace)
136
-
137
- out: list[Content] = []
138
- for n, e in o:
139
- if n.startswith('_'):
140
- continue
141
- out.append(self.materialize(e))
142
- return out
143
-
144
- #
145
-
146
- @_materialize.register
147
- def _materialize_type(self, o: type) -> Content:
148
- if issubclass(o, ContentPlaceholderMarker):
149
- return self._materialize_placeholder_marker_type(o)
150
-
151
- elif issubclass(o, ContentNamespace):
152
- return self._materialize_namespace_type(o)
153
-
154
- else:
155
- raise TypeError(o)
156
-
157
- #
158
-
159
- @_materialize.register
160
- def _materialize_templater(self, o: tpl.Templater) -> Content:
161
- return o.render(check.not_none(self._templater_context))
162
-
163
-
164
- def materialize_content(
165
- o: CanContent,
166
- *,
167
- content_placeholders: ContentPlaceholders | None = None,
168
- templater_context: tpl.Templater.Context | None = None,
169
- ) -> Content:
170
- return ContentMaterializer(
171
- content_placeholders=content_placeholders,
172
- templater_context=templater_context,
173
- ).materialize(o)
@@ -1,46 +0,0 @@
1
- import collections.abc
2
- import typing as ta
3
-
4
- from omlish import dataclasses as dc
5
- from omlish import dispatch
6
- from omlish import lang
7
-
8
- from ..images import ImageContent
9
- from ..sequence import SequenceContent
10
- from ..text import TextContent
11
-
12
-
13
- T = ta.TypeVar('T')
14
-
15
-
16
- ##
17
-
18
-
19
- class ContentTransform(lang.Abstract):
20
- @dispatch.method(installable=True)
21
- def apply(self, o: T) -> T:
22
- raise TypeError(o)
23
-
24
- #
25
-
26
- @apply.register # noqa
27
- def apply_str(self, s: str) -> str:
28
- return s
29
-
30
- @apply.register # noqa
31
- def apply_sequence(self, l: collections.abc.Sequence[T]) -> collections.abc.Sequence[T]:
32
- return [self.apply(e) for e in l]
33
-
34
- #
35
-
36
- @apply.register
37
- def apply_image_content(self, c: ImageContent) -> ImageContent:
38
- return c
39
-
40
- @apply.register
41
- def apply_sequence_content(self, c: SequenceContent) -> SequenceContent:
42
- return dc.replace(c, l=self.apply(c.l))
43
-
44
- @apply.register
45
- def apply_text_content(self, c: TextContent) -> TextContent:
46
- return dc.replace(c, s=self.apply(c.s))