ommlds 0.0.0.dev495__py3-none-any.whl → 0.0.0.dev497__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 (60) hide show
  1. ommlds/.omlish-manifests.json +1 -1
  2. ommlds/cli/backends/inject.py +2 -4
  3. ommlds/cli/content/messages.py +1 -1
  4. ommlds/cli/main.py +2 -2
  5. ommlds/cli/secrets.py +1 -1
  6. ommlds/cli/sessions/chat/drivers/user/inject.py +3 -2
  7. ommlds/minichain/__init__.py +67 -31
  8. ommlds/minichain/_dataclasses.py +2234 -1118
  9. ommlds/minichain/backends/impls/anthropic/protocol.py +2 -2
  10. ommlds/minichain/backends/impls/cerebras/protocol.py +2 -2
  11. ommlds/minichain/backends/impls/google/tools.py +2 -2
  12. ommlds/minichain/backends/impls/groq/protocol.py +2 -2
  13. ommlds/minichain/backends/impls/ollama/protocol.py +2 -2
  14. ommlds/minichain/backends/impls/openai/format.py +2 -2
  15. ommlds/minichain/chat/messages.py +22 -25
  16. ommlds/minichain/chat/templating.py +1 -1
  17. ommlds/minichain/content/__init__.py +9 -2
  18. ommlds/minichain/content/_marshal.py +159 -48
  19. ommlds/minichain/content/code.py +17 -0
  20. ommlds/minichain/content/dynamic.py +12 -0
  21. ommlds/minichain/content/images.py +3 -2
  22. ommlds/minichain/content/json.py +3 -2
  23. ommlds/minichain/content/namespaces.py +9 -0
  24. ommlds/minichain/content/placeholders.py +11 -9
  25. ommlds/minichain/content/quote.py +17 -0
  26. ommlds/minichain/content/raw.py +49 -0
  27. ommlds/minichain/content/section.py +14 -0
  28. ommlds/minichain/content/sequence.py +9 -4
  29. ommlds/minichain/content/{simple.py → standard.py} +3 -13
  30. ommlds/minichain/content/tag.py +4 -4
  31. ommlds/minichain/content/templates.py +14 -0
  32. ommlds/minichain/content/text.py +3 -2
  33. ommlds/minichain/content/transform/base.py +63 -0
  34. ommlds/minichain/content/transform/interleave.py +68 -0
  35. ommlds/minichain/content/transform/materialize.py +110 -0
  36. ommlds/minichain/content/{prepare.py → transform/prepare.py} +10 -11
  37. ommlds/minichain/content/transform/squeeze.py +59 -0
  38. ommlds/minichain/content/{transforms → transform}/stringify.py +0 -6
  39. ommlds/minichain/content/types.py +5 -17
  40. ommlds/minichain/lib/todo/tools/write.py +2 -1
  41. ommlds/minichain/tools/execution/errorhandling.py +2 -2
  42. ommlds/minichain/tools/execution/errors.py +2 -2
  43. ommlds/minichain/tools/jsonschema.py +2 -2
  44. ommlds/minichain/tools/reflect.py +3 -3
  45. ommlds/minichain/tools/types.py +11 -14
  46. ommlds/tools/git.py +74 -63
  47. {ommlds-0.0.0.dev495.dist-info → ommlds-0.0.0.dev497.dist-info}/METADATA +4 -4
  48. {ommlds-0.0.0.dev495.dist-info → ommlds-0.0.0.dev497.dist-info}/RECORD +54 -50
  49. ommlds/cli/sessions/chat/interfaces/bare/user.py +0 -31
  50. ommlds/minichain/content/cancontent.py +0 -32
  51. ommlds/minichain/content/materialize.py +0 -173
  52. ommlds/minichain/content/transforms/base.py +0 -46
  53. ommlds/minichain/content/transforms/interleave.py +0 -77
  54. ommlds/minichain/content/transforms/squeeze.py +0 -72
  55. /ommlds/minichain/content/{transforms → transform}/__init__.py +0 -0
  56. /ommlds/minichain/content/{transforms → transform}/strings.py +0 -0
  57. {ommlds-0.0.0.dev495.dist-info → ommlds-0.0.0.dev497.dist-info}/WHEEL +0 -0
  58. {ommlds-0.0.0.dev495.dist-info → ommlds-0.0.0.dev497.dist-info}/entry_points.txt +0 -0
  59. {ommlds-0.0.0.dev495.dist-info → ommlds-0.0.0.dev497.dist-info}/licenses/LICENSE +0 -0
  60. {ommlds-0.0.0.dev495.dist-info → ommlds-0.0.0.dev497.dist-info}/top_level.txt +0 -0
@@ -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))
@@ -1,77 +0,0 @@
1
- import typing as ta
2
-
3
- from omlish import dataclasses as dc
4
- from omlish import dispatch
5
- from omlish import lang
6
-
7
- from ..cancontent import CanContent
8
- from ..sequence import BlockContent
9
- from ..sequence import InlineContent
10
- from ..types import Content
11
- from ..types import ExtendedContent
12
-
13
-
14
- ##
15
-
16
-
17
- class ContentInterleaver:
18
- def __init__(
19
- self,
20
- *,
21
- separator: Content | None = None,
22
- sequence_separator: Content | None = None,
23
- inline_separator: Content | None = None,
24
- block_separator: Content | None = None,
25
- ) -> None:
26
- super().__init__()
27
-
28
- self._sequence_separator = sequence_separator if sequence_separator is not None else separator
29
- self._inline_separator = inline_separator if inline_separator is not None else separator
30
- self._block_separator = block_separator if block_separator is not None else separator
31
-
32
- def _interleave(self, l: ta.Iterable[CanContent], separator: Content | None) -> ta.Sequence[Content]:
33
- cs: ta.Iterable[Content] = map(self.interleave, l)
34
- if separator is not None:
35
- cs = lang.interleave(cs, separator)
36
- return list(cs)
37
-
38
- @dispatch.method()
39
- def interleave(self, c: CanContent) -> Content:
40
- raise TypeError(c)
41
-
42
- @interleave.register
43
- def interleave_str(self, c: str) -> Content:
44
- return c
45
-
46
- @interleave.register
47
- def interleave_sequence(self, c: ta.Sequence) -> Content:
48
- return self._interleave(c, self._sequence_separator)
49
-
50
- @interleave.register
51
- def interleave_extended_content(self, c: ExtendedContent) -> Content:
52
- # FIXME:
53
- return c
54
-
55
- @interleave.register
56
- def interleave_inline_content(self, c: InlineContent) -> Content:
57
- return dc.replace(c, l=self._interleave(c.l, self._inline_separator))
58
-
59
- @interleave.register
60
- def interleave_block_content(self, c: BlockContent) -> Content:
61
- return dc.replace(c, l=self._interleave(c.l, self._block_separator))
62
-
63
-
64
- def interleave_content(
65
- c: Content,
66
- *,
67
- separator: Content | None = None,
68
- sequence_separator: Content | None = None,
69
- inline_separator: Content | None = None,
70
- block_separator: Content | None = None,
71
- ) -> Content:
72
- return ContentInterleaver(
73
- separator=separator,
74
- sequence_separator=sequence_separator,
75
- inline_separator=inline_separator,
76
- block_separator=block_separator,
77
- ).interleave(c)
@@ -1,72 +0,0 @@
1
- import typing as ta
2
-
3
- from omlish import dataclasses as dc
4
- from omlish import dispatch
5
-
6
- from ..sequence import SequenceContent
7
- from ..text import TextContent
8
- from ..types import Content
9
- from ..types import SingleContent
10
-
11
-
12
- ##
13
-
14
-
15
- class ContentSqueezer:
16
- def __init__(
17
- self,
18
- *,
19
- strip_strings: bool = False,
20
- ) -> None:
21
- super().__init__()
22
-
23
- self._strip_strings = strip_strings
24
-
25
- @dispatch.method()
26
- def squeeze(self, c: Content) -> ta.Iterable[SingleContent]:
27
- raise TypeError(c)
28
-
29
- #
30
-
31
- @squeeze.register
32
- def squeeze_str(self, c: str) -> ta.Iterable[SingleContent]:
33
- if self._strip_strings:
34
- c = c.strip()
35
-
36
- if c:
37
- yield c
38
-
39
- @squeeze.register
40
- def squeeze_sequence(self, c: ta.Sequence) -> ta.Iterable[SingleContent]:
41
- for e in c:
42
- yield from self.squeeze(e)
43
-
44
- #
45
-
46
- @squeeze.register
47
- def squeeze_single_content(self, c: SingleContent) -> ta.Iterable[SingleContent]:
48
- return [c]
49
-
50
- @squeeze.register
51
- def squeeze_text_content(self, c: TextContent) -> ta.Iterable[SingleContent]:
52
- if self._strip_strings:
53
- if (ss := c.s.strip()) != c.s:
54
- c = dc.replace(c, s=ss)
55
-
56
- if c.s:
57
- yield c.s
58
-
59
- @squeeze.register
60
- def squeeze_sequence_content(self, c: SequenceContent) -> ta.Iterable[SingleContent]:
61
- for e in c.l:
62
- yield from self.squeeze(e)
63
-
64
-
65
- def squeeze_content(
66
- c: Content,
67
- *,
68
- strip_strings: bool = False,
69
- ) -> ta.Sequence[SingleContent]:
70
- return list(ContentSqueezer(
71
- strip_strings=strip_strings,
72
- ).squeeze(c))