lionagi 0.16.1__py3-none-any.whl → 0.16.3__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.
- lionagi/adapters/_utils.py +0 -14
- lionagi/libs/file/save.py +8 -1
- lionagi/ln/__init__.py +10 -0
- lionagi/ln/_json_dump.py +322 -49
- lionagi/ln/fuzzy/__init__.py +4 -1
- lionagi/ln/fuzzy/_fuzzy_validate.py +109 -0
- lionagi/ln/fuzzy/_to_dict.py +388 -0
- lionagi/models/__init__.py +0 -2
- lionagi/operations/brainstorm/brainstorm.py +10 -10
- lionagi/operations/communicate/communicate.py +1 -1
- lionagi/operations/parse/parse.py +1 -1
- lionagi/protocols/generic/element.py +5 -14
- lionagi/protocols/generic/log.py +2 -2
- lionagi/protocols/generic/pile.py +1 -1
- lionagi/protocols/messages/message.py +8 -1
- lionagi/protocols/operatives/operative.py +2 -2
- lionagi/service/connections/endpoint.py +7 -0
- lionagi/service/connections/match_endpoint.py +2 -10
- lionagi/service/connections/providers/types.py +1 -3
- lionagi/service/hooks/hook_event.py +1 -1
- lionagi/service/hooks/hook_registry.py +1 -1
- lionagi/service/rate_limited_processor.py +1 -1
- lionagi/session/branch.py +1 -101
- lionagi/session/session.py +9 -14
- lionagi/utils.py +3 -334
- lionagi/version.py +1 -1
- {lionagi-0.16.1.dist-info → lionagi-0.16.3.dist-info}/METADATA +3 -13
- {lionagi-0.16.1.dist-info → lionagi-0.16.3.dist-info}/RECORD +30 -78
- lionagi/adapters/postgres_model_adapter.py +0 -131
- lionagi/libs/concurrency.py +0 -1
- lionagi/libs/file/params.py +0 -175
- lionagi/libs/nested/__init__.py +0 -3
- lionagi/libs/nested/flatten.py +0 -172
- lionagi/libs/nested/nfilter.py +0 -59
- lionagi/libs/nested/nget.py +0 -45
- lionagi/libs/nested/ninsert.py +0 -104
- lionagi/libs/nested/nmerge.py +0 -158
- lionagi/libs/nested/npop.py +0 -69
- lionagi/libs/nested/nset.py +0 -94
- lionagi/libs/nested/unflatten.py +0 -83
- lionagi/libs/nested/utils.py +0 -189
- lionagi/libs/parse.py +0 -31
- lionagi/libs/schema/json_schema.py +0 -231
- lionagi/libs/token_transform/__init__.py +0 -0
- lionagi/libs/token_transform/base.py +0 -54
- lionagi/libs/token_transform/llmlingua.py +0 -1
- lionagi/libs/token_transform/perplexity.py +0 -450
- lionagi/libs/token_transform/symbolic_compress_context.py +0 -152
- lionagi/libs/token_transform/synthlang.py +0 -9
- lionagi/libs/token_transform/synthlang_/base.py +0 -128
- lionagi/libs/token_transform/synthlang_/resources/frameworks/abstract_algebra.toml +0 -11
- lionagi/libs/token_transform/synthlang_/resources/frameworks/category_theory.toml +0 -11
- lionagi/libs/token_transform/synthlang_/resources/frameworks/complex_analysis.toml +0 -11
- lionagi/libs/token_transform/synthlang_/resources/frameworks/framework_options.json +0 -52
- lionagi/libs/token_transform/synthlang_/resources/frameworks/group_theory.toml +0 -11
- lionagi/libs/token_transform/synthlang_/resources/frameworks/math_logic.toml +0 -11
- lionagi/libs/token_transform/synthlang_/resources/frameworks/reflective_patterns.toml +0 -11
- lionagi/libs/token_transform/synthlang_/resources/frameworks/set_theory.toml +0 -11
- lionagi/libs/token_transform/synthlang_/resources/frameworks/topology_fundamentals.toml +0 -11
- lionagi/libs/token_transform/synthlang_/resources/mapping/lion_emoji_mapping.toml +0 -61
- lionagi/libs/token_transform/synthlang_/resources/mapping/python_math_mapping.toml +0 -41
- lionagi/libs/token_transform/synthlang_/resources/mapping/rust_chinese_mapping.toml +0 -60
- lionagi/libs/token_transform/synthlang_/resources/utility/base_synthlang_system_prompt.toml +0 -11
- lionagi/libs/token_transform/synthlang_/translate_to_synthlang.py +0 -140
- lionagi/libs/token_transform/types.py +0 -15
- lionagi/libs/unstructured/__init__.py +0 -0
- lionagi/libs/unstructured/pdf_to_image.py +0 -45
- lionagi/libs/unstructured/read_image_to_base64.py +0 -33
- lionagi/libs/validate/fuzzy_match_keys.py +0 -7
- lionagi/libs/validate/fuzzy_validate_mapping.py +0 -144
- lionagi/libs/validate/string_similarity.py +0 -7
- lionagi/libs/validate/xml_parser.py +0 -203
- lionagi/models/note.py +0 -383
- lionagi/operations/translate/__init__.py +0 -0
- lionagi/operations/translate/translate.py +0 -47
- lionagi/service/connections/providers/claude_code_.py +0 -294
- lionagi/tools/memory/tools.py +0 -495
- {lionagi-0.16.1.dist-info → lionagi-0.16.3.dist-info}/WHEEL +0 -0
- {lionagi-0.16.1.dist-info → lionagi-0.16.3.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,388 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
import contextlib
|
4
|
+
import dataclasses
|
5
|
+
import json
|
6
|
+
from collections.abc import Callable, Iterable, Mapping, Sequence
|
7
|
+
from enum import Enum as _Enum
|
8
|
+
from typing import Any, Literal
|
9
|
+
|
10
|
+
from ._fuzzy_json import fuzzy_json
|
11
|
+
|
12
|
+
# ----------------------------
|
13
|
+
# Helpers (small, tight, local)
|
14
|
+
# ----------------------------
|
15
|
+
|
16
|
+
|
17
|
+
def _is_na(obj: Any) -> bool:
|
18
|
+
"""None / Pydantic undefined sentinels -> treat as NA."""
|
19
|
+
if obj is None:
|
20
|
+
return True
|
21
|
+
# Avoid importing pydantic types; match by typename to stay lightweight
|
22
|
+
tname = type(obj).__name__
|
23
|
+
return tname in {
|
24
|
+
"Undefined",
|
25
|
+
"UndefinedType",
|
26
|
+
"PydanticUndefined",
|
27
|
+
"PydanticUndefinedType",
|
28
|
+
}
|
29
|
+
|
30
|
+
|
31
|
+
def _enum_class_to_dict(
|
32
|
+
enum_cls: type[_Enum], use_enum_values: bool
|
33
|
+
) -> dict[str, Any]:
|
34
|
+
members = dict(enum_cls.__members__) # cheap, stable
|
35
|
+
if use_enum_values:
|
36
|
+
return {k: v.value for k, v in members.items()}
|
37
|
+
return {k: v for k, v in members.items()}
|
38
|
+
|
39
|
+
|
40
|
+
def _parse_str(
|
41
|
+
s: str,
|
42
|
+
*,
|
43
|
+
fuzzy_parse: bool,
|
44
|
+
str_type: Literal["json", "xml"] | None,
|
45
|
+
parser: Callable[[str], Any] | None,
|
46
|
+
**kwargs: Any,
|
47
|
+
) -> Any:
|
48
|
+
"""Parse str -> Python object. Keep imports local to avoid cold start overhead."""
|
49
|
+
if parser is not None:
|
50
|
+
return parser(s, **kwargs)
|
51
|
+
|
52
|
+
if str_type == "xml":
|
53
|
+
# xmltodict is optional; import only if needed
|
54
|
+
import xmltodict
|
55
|
+
|
56
|
+
return xmltodict.parse(s, **kwargs)
|
57
|
+
|
58
|
+
# JSON path
|
59
|
+
if fuzzy_parse:
|
60
|
+
# If the caller supplied a fuzzy parser in scope, use it; otherwise fallback.
|
61
|
+
# We intentionally do not import anything heavy here.
|
62
|
+
with contextlib.suppress(NameError):
|
63
|
+
return fuzzy_json(s, **kwargs) # type: ignore[name-defined]
|
64
|
+
return json.loads(s, **kwargs)
|
65
|
+
|
66
|
+
|
67
|
+
def _object_to_mapping_like(
|
68
|
+
obj: Any,
|
69
|
+
*,
|
70
|
+
use_model_dump: bool,
|
71
|
+
**kwargs: Any,
|
72
|
+
) -> Mapping | dict | Any:
|
73
|
+
"""
|
74
|
+
Convert 'custom' objects to mapping-like, if possible.
|
75
|
+
Order:
|
76
|
+
1) Pydantic v2 'model_dump' (duck-typed)
|
77
|
+
2) Common methods: to_dict, dict, to_json/json (parsed if string)
|
78
|
+
3) Dataclass
|
79
|
+
4) __dict__
|
80
|
+
5) dict(obj)
|
81
|
+
"""
|
82
|
+
# 1) Pydantic v2
|
83
|
+
if use_model_dump and hasattr(obj, "model_dump"):
|
84
|
+
return obj.model_dump(**kwargs)
|
85
|
+
|
86
|
+
# 2) Common methods
|
87
|
+
for name in ("to_dict", "dict", "to_json", "json"):
|
88
|
+
if hasattr(obj, name):
|
89
|
+
res = getattr(obj, name)(**kwargs)
|
90
|
+
return json.loads(res) if isinstance(res, str) else res
|
91
|
+
|
92
|
+
# 3) Dataclass
|
93
|
+
if dataclasses.is_dataclass(obj):
|
94
|
+
# asdict is already recursive; keep it (fast enough & simple)
|
95
|
+
return dataclasses.asdict(obj)
|
96
|
+
|
97
|
+
# 4) __dict__
|
98
|
+
if hasattr(obj, "__dict__"):
|
99
|
+
return obj.__dict__
|
100
|
+
|
101
|
+
# 5) Try dict() fallback
|
102
|
+
return dict(obj) # may raise -> handled by caller
|
103
|
+
|
104
|
+
|
105
|
+
def _enumerate_iterable(it: Iterable) -> dict[int, Any]:
|
106
|
+
return {i: v for i, v in enumerate(it)}
|
107
|
+
|
108
|
+
|
109
|
+
# ---------------------------------------
|
110
|
+
# Recursive pre-processing (single pass)
|
111
|
+
# ---------------------------------------
|
112
|
+
|
113
|
+
|
114
|
+
def _preprocess_recursive(
|
115
|
+
obj: Any,
|
116
|
+
*,
|
117
|
+
depth: int,
|
118
|
+
max_depth: int,
|
119
|
+
recursive_custom_types: bool,
|
120
|
+
str_parse_opts: dict[str, Any],
|
121
|
+
use_model_dump: bool,
|
122
|
+
) -> Any:
|
123
|
+
"""
|
124
|
+
Recursively process nested structures:
|
125
|
+
- Parse strings (JSON/XML/custom parser)
|
126
|
+
- Recurse into dict/list/tuple/set/etc.
|
127
|
+
- If recursive_custom_types=True, convert custom objects to mapping-like then continue
|
128
|
+
Containers retain their original types (dict stays dict, list stays list, set stays set, etc.)
|
129
|
+
"""
|
130
|
+
if depth >= max_depth:
|
131
|
+
return obj
|
132
|
+
|
133
|
+
# Fast paths by exact type where possible
|
134
|
+
t = type(obj)
|
135
|
+
|
136
|
+
# Strings: try to parse; on failure, keep as-is
|
137
|
+
if t is str:
|
138
|
+
try:
|
139
|
+
parsed = _parse_str(obj, **str_parse_opts)
|
140
|
+
except Exception:
|
141
|
+
return obj
|
142
|
+
return _preprocess_recursive(
|
143
|
+
parsed,
|
144
|
+
depth=depth + 1,
|
145
|
+
max_depth=max_depth,
|
146
|
+
recursive_custom_types=recursive_custom_types,
|
147
|
+
str_parse_opts=str_parse_opts,
|
148
|
+
use_model_dump=use_model_dump,
|
149
|
+
)
|
150
|
+
|
151
|
+
# Dict-like
|
152
|
+
if isinstance(obj, Mapping):
|
153
|
+
# Recurse only into values (keys kept as-is)
|
154
|
+
return {
|
155
|
+
k: _preprocess_recursive(
|
156
|
+
v,
|
157
|
+
depth=depth + 1,
|
158
|
+
max_depth=max_depth,
|
159
|
+
recursive_custom_types=recursive_custom_types,
|
160
|
+
str_parse_opts=str_parse_opts,
|
161
|
+
use_model_dump=use_model_dump,
|
162
|
+
)
|
163
|
+
for k, v in obj.items()
|
164
|
+
}
|
165
|
+
|
166
|
+
# Sequence/Set-like (but not str)
|
167
|
+
if isinstance(obj, (list, tuple, set, frozenset)):
|
168
|
+
items = [
|
169
|
+
_preprocess_recursive(
|
170
|
+
v,
|
171
|
+
depth=depth + 1,
|
172
|
+
max_depth=max_depth,
|
173
|
+
recursive_custom_types=recursive_custom_types,
|
174
|
+
str_parse_opts=str_parse_opts,
|
175
|
+
use_model_dump=use_model_dump,
|
176
|
+
)
|
177
|
+
for v in obj
|
178
|
+
]
|
179
|
+
if t is list:
|
180
|
+
return items
|
181
|
+
if t is tuple:
|
182
|
+
return tuple(items)
|
183
|
+
if t is set:
|
184
|
+
return set(items)
|
185
|
+
if t is frozenset:
|
186
|
+
return frozenset(items)
|
187
|
+
|
188
|
+
# Enum *class* (rare in values, but preserve your original attempt)
|
189
|
+
if isinstance(obj, type) and issubclass(obj, _Enum):
|
190
|
+
try:
|
191
|
+
enum_map = _enum_class_to_dict(
|
192
|
+
obj,
|
193
|
+
use_enum_values=str_parse_opts.get("use_enum_values", True),
|
194
|
+
)
|
195
|
+
return _preprocess_recursive(
|
196
|
+
enum_map,
|
197
|
+
depth=depth + 1,
|
198
|
+
max_depth=max_depth,
|
199
|
+
recursive_custom_types=recursive_custom_types,
|
200
|
+
str_parse_opts=str_parse_opts,
|
201
|
+
use_model_dump=use_model_dump,
|
202
|
+
)
|
203
|
+
except Exception:
|
204
|
+
return obj
|
205
|
+
|
206
|
+
# Custom objects
|
207
|
+
if recursive_custom_types:
|
208
|
+
with contextlib.suppress(Exception):
|
209
|
+
mapped = _object_to_mapping_like(
|
210
|
+
obj, use_model_dump=use_model_dump
|
211
|
+
)
|
212
|
+
return _preprocess_recursive(
|
213
|
+
mapped,
|
214
|
+
depth=depth + 1,
|
215
|
+
max_depth=max_depth,
|
216
|
+
recursive_custom_types=recursive_custom_types,
|
217
|
+
str_parse_opts=str_parse_opts,
|
218
|
+
use_model_dump=use_model_dump,
|
219
|
+
)
|
220
|
+
|
221
|
+
return obj
|
222
|
+
|
223
|
+
|
224
|
+
# ---------------------------------------
|
225
|
+
# Top-level conversion (non-recursive)
|
226
|
+
# ---------------------------------------
|
227
|
+
|
228
|
+
|
229
|
+
def _convert_top_level_to_dict(
|
230
|
+
obj: Any,
|
231
|
+
*,
|
232
|
+
fuzzy_parse: bool,
|
233
|
+
str_type: Literal["json", "xml"] | None,
|
234
|
+
parser: Callable[[str], Any] | None,
|
235
|
+
use_model_dump: bool,
|
236
|
+
use_enum_values: bool,
|
237
|
+
**kwargs: Any,
|
238
|
+
) -> dict[str, Any]:
|
239
|
+
"""
|
240
|
+
Convert a *single* object to dict using the 'brute force' rules.
|
241
|
+
Mirrors your original order, with fixes & optimizations.
|
242
|
+
"""
|
243
|
+
# Set -> {v: v}
|
244
|
+
if isinstance(obj, set):
|
245
|
+
return {v: v for v in obj}
|
246
|
+
|
247
|
+
# Enum class -> members mapping
|
248
|
+
if isinstance(obj, type) and issubclass(obj, _Enum):
|
249
|
+
return _enum_class_to_dict(obj, use_enum_values)
|
250
|
+
|
251
|
+
# Mapping -> copy to plain dict (preserve your copy semantics)
|
252
|
+
if isinstance(obj, Mapping):
|
253
|
+
return dict(obj)
|
254
|
+
|
255
|
+
# None / pydantic undefined -> {}
|
256
|
+
if _is_na(obj):
|
257
|
+
return {}
|
258
|
+
|
259
|
+
# str -> parse (and return *as parsed*, which may be list, dict, etc.)
|
260
|
+
if isinstance(obj, str):
|
261
|
+
return _parse_str(
|
262
|
+
obj,
|
263
|
+
fuzzy_parse=fuzzy_parse,
|
264
|
+
str_type=str_type,
|
265
|
+
parser=parser,
|
266
|
+
**kwargs,
|
267
|
+
)
|
268
|
+
|
269
|
+
# Try "custom" object conversions
|
270
|
+
# (Covers BaseModel via model_dump, dataclasses, __dict__, json-strings, etc.)
|
271
|
+
try:
|
272
|
+
# If it's *not* a Sequence (e.g., numbers, objects) we try object conversion first,
|
273
|
+
# faithfully following your previous "non-Sequence -> model path" behavior.
|
274
|
+
if not isinstance(obj, Sequence):
|
275
|
+
converted = _object_to_mapping_like(
|
276
|
+
obj, use_model_dump=use_model_dump, **kwargs
|
277
|
+
)
|
278
|
+
# If conversion returned a string, try to parse JSON to mapping; else pass-through
|
279
|
+
if isinstance(converted, str):
|
280
|
+
return _parse_str(
|
281
|
+
converted,
|
282
|
+
fuzzy_parse=fuzzy_parse,
|
283
|
+
str_type="json",
|
284
|
+
parser=None,
|
285
|
+
)
|
286
|
+
if isinstance(converted, Mapping):
|
287
|
+
return dict(converted)
|
288
|
+
# If it's a list/tuple/etc., enumerate (your original did that after the fact)
|
289
|
+
if isinstance(converted, Iterable) and not isinstance(
|
290
|
+
converted, (str, bytes, bytearray)
|
291
|
+
):
|
292
|
+
return _enumerate_iterable(converted)
|
293
|
+
# Best effort final cast
|
294
|
+
return dict(converted)
|
295
|
+
|
296
|
+
except Exception:
|
297
|
+
# Fall through to other strategies
|
298
|
+
pass
|
299
|
+
|
300
|
+
# Iterable (list/tuple/namedtuple/frozenset/…): enumerate
|
301
|
+
if isinstance(obj, Iterable) and not isinstance(
|
302
|
+
obj, (str, bytes, bytearray)
|
303
|
+
):
|
304
|
+
return _enumerate_iterable(obj)
|
305
|
+
|
306
|
+
# Dataclass fallback (reachable only if it wasn't caught above)
|
307
|
+
with contextlib.suppress(Exception):
|
308
|
+
if dataclasses.is_dataclass(obj):
|
309
|
+
return dataclasses.asdict(obj)
|
310
|
+
|
311
|
+
# Last-ditch attempt
|
312
|
+
return dict(obj) # may raise, handled by top-level try/except
|
313
|
+
|
314
|
+
|
315
|
+
# ---------------
|
316
|
+
# Public function
|
317
|
+
# ---------------
|
318
|
+
|
319
|
+
|
320
|
+
def to_dict(
|
321
|
+
input_: Any,
|
322
|
+
/,
|
323
|
+
*,
|
324
|
+
use_model_dump: bool = True,
|
325
|
+
fuzzy_parse: bool = False,
|
326
|
+
suppress: bool = False,
|
327
|
+
str_type: Literal["json", "xml"] | None = "json",
|
328
|
+
parser: Callable[[str], Any] | None = None,
|
329
|
+
recursive: bool = False,
|
330
|
+
max_recursive_depth: int | None = None,
|
331
|
+
recursive_python_only: bool = True,
|
332
|
+
use_enum_values: bool = False,
|
333
|
+
**kwargs: Any,
|
334
|
+
) -> dict[str, Any]:
|
335
|
+
"""
|
336
|
+
Convert various input types to a dictionary, with optional recursive processing.
|
337
|
+
Semantics preserved from original implementation.
|
338
|
+
"""
|
339
|
+
try:
|
340
|
+
# Clamp recursion depth (match your constraints)
|
341
|
+
if not isinstance(max_recursive_depth, int):
|
342
|
+
max_depth = 5
|
343
|
+
else:
|
344
|
+
if max_recursive_depth < 0:
|
345
|
+
raise ValueError(
|
346
|
+
"max_recursive_depth must be a non-negative integer"
|
347
|
+
)
|
348
|
+
if max_recursive_depth > 10:
|
349
|
+
raise ValueError(
|
350
|
+
"max_recursive_depth must be less than or equal to 10"
|
351
|
+
)
|
352
|
+
max_depth = max_recursive_depth
|
353
|
+
|
354
|
+
# Prepare one small dict to avoid repeated arg passing and lookups
|
355
|
+
str_parse_opts = {
|
356
|
+
"fuzzy_parse": fuzzy_parse,
|
357
|
+
"str_type": str_type,
|
358
|
+
"parser": parser,
|
359
|
+
"use_enum_values": use_enum_values, # threaded for enum class in recursion
|
360
|
+
**kwargs,
|
361
|
+
}
|
362
|
+
|
363
|
+
obj = input_
|
364
|
+
if recursive:
|
365
|
+
obj = _preprocess_recursive(
|
366
|
+
obj,
|
367
|
+
depth=0,
|
368
|
+
max_depth=max_depth,
|
369
|
+
recursive_custom_types=not recursive_python_only,
|
370
|
+
str_parse_opts=str_parse_opts,
|
371
|
+
use_model_dump=use_model_dump,
|
372
|
+
)
|
373
|
+
|
374
|
+
# Final top-level conversion
|
375
|
+
return _convert_top_level_to_dict(
|
376
|
+
obj,
|
377
|
+
fuzzy_parse=fuzzy_parse,
|
378
|
+
str_type=str_type,
|
379
|
+
parser=parser,
|
380
|
+
use_model_dump=use_model_dump,
|
381
|
+
use_enum_values=use_enum_values,
|
382
|
+
**kwargs,
|
383
|
+
)
|
384
|
+
|
385
|
+
except Exception as e:
|
386
|
+
if suppress or input_ == "":
|
387
|
+
return {}
|
388
|
+
raise e
|
lionagi/models/__init__.py
CHANGED
@@ -5,7 +5,6 @@
|
|
5
5
|
from .field_model import FieldModel
|
6
6
|
from .hashable_model import HashableModel
|
7
7
|
from .model_params import ModelParams
|
8
|
-
from .note import Note
|
9
8
|
from .operable_model import OperableModel
|
10
9
|
from .schema_model import SchemaModel
|
11
10
|
|
@@ -13,7 +12,6 @@ __all__ = (
|
|
13
12
|
"FieldModel",
|
14
13
|
"ModelParams",
|
15
14
|
"OperableModel",
|
16
|
-
"Note",
|
17
15
|
"SchemaModel",
|
18
16
|
"HashableModel",
|
19
17
|
)
|
@@ -309,8 +309,8 @@ async def brainstormStream(
|
|
309
309
|
)
|
310
310
|
print(f"\n-----Exploring Idea-----\n{snippet}")
|
311
311
|
new_branch = session.split(branch)
|
312
|
-
resp = await new_branch.
|
313
|
-
ins_, **(explore_kwargs or {})
|
312
|
+
resp = await new_branch.operate(
|
313
|
+
**ins_.to_dict(), **(explore_kwargs or {})
|
314
314
|
)
|
315
315
|
return InstructResponse(instruct=ins_, response=resp)
|
316
316
|
|
@@ -357,8 +357,8 @@ async def brainstormStream(
|
|
357
357
|
else i.guidance
|
358
358
|
)
|
359
359
|
print(f"\n-----Exploring Idea-----\n{snippet}")
|
360
|
-
seq_res = await branch.
|
361
|
-
i, **(explore_kwargs or {})
|
360
|
+
seq_res = await branch.operate(
|
361
|
+
**i.to_dict(), **(explore_kwargs or {})
|
362
362
|
)
|
363
363
|
ins_res = InstructResponse(
|
364
364
|
instruct=i, response=seq_res
|
@@ -389,8 +389,8 @@ async def brainstormStream(
|
|
389
389
|
|
390
390
|
async def _explore(ins_: Instruct):
|
391
391
|
child_branch = session.split(base_branch)
|
392
|
-
child_resp = await child_branch.
|
393
|
-
ins_, **(explore_kwargs or {})
|
392
|
+
child_resp = await child_branch.operate(
|
393
|
+
**ins_.to_dict(), **(explore_kwargs or {})
|
394
394
|
)
|
395
395
|
return InstructResponse(
|
396
396
|
instruct=ins_, response=child_resp
|
@@ -453,8 +453,8 @@ async def brainstormStream(
|
|
453
453
|
f"\n-----Exploring Idea (sequential in chunk)-----\n{snippet}"
|
454
454
|
)
|
455
455
|
|
456
|
-
seq_resp = await local_branch.
|
457
|
-
ins_, **(explore_kwargs or {})
|
456
|
+
seq_resp = await local_branch.operate(
|
457
|
+
**ins_.to_dict(), **(explore_kwargs or {})
|
458
458
|
)
|
459
459
|
chunk_results.append(
|
460
460
|
InstructResponse(
|
@@ -468,8 +468,8 @@ async def brainstormStream(
|
|
468
468
|
all_responses = await alcall(
|
469
469
|
all_chunks,
|
470
470
|
explore_chunk_sequentially,
|
471
|
-
|
472
|
-
|
471
|
+
output_flatten=True,
|
472
|
+
output_dropna=True,
|
473
473
|
)
|
474
474
|
out.explore = all_responses
|
475
475
|
|
@@ -5,7 +5,7 @@
|
|
5
5
|
import logging
|
6
6
|
from typing import TYPE_CHECKING
|
7
7
|
|
8
|
-
from lionagi.
|
8
|
+
from lionagi.ln.fuzzy._fuzzy_validate import fuzzy_validate_mapping
|
9
9
|
from lionagi.utils import UNDEFINED
|
10
10
|
|
11
11
|
if TYPE_CHECKING:
|
@@ -6,7 +6,7 @@ from typing import TYPE_CHECKING, Any, Literal
|
|
6
6
|
|
7
7
|
from pydantic import BaseModel
|
8
8
|
|
9
|
-
from lionagi.
|
9
|
+
from lionagi.ln.fuzzy._fuzzy_validate import fuzzy_validate_mapping
|
10
10
|
from lionagi.protocols.types import Operative
|
11
11
|
from lionagi.utils import breakdown_pydantic_annotation
|
12
12
|
|
@@ -315,10 +315,6 @@ class Element(BaseModel, Observable):
|
|
315
315
|
dict_["node_metadata"] = dict_.pop("metadata", {})
|
316
316
|
return dict_
|
317
317
|
|
318
|
-
def as_jsonable(self) -> dict:
|
319
|
-
"""Converts this Element to a JSON-serializable dictionary."""
|
320
|
-
return self.to_dict(mode="json")
|
321
|
-
|
322
318
|
@classmethod
|
323
319
|
def from_dict(cls, data: dict) -> Element:
|
324
320
|
"""Deserializes a dictionary into an Element or subclass of Element.
|
@@ -363,19 +359,14 @@ class Element(BaseModel, Observable):
|
|
363
359
|
def to_json(self, decode: bool = True) -> str:
|
364
360
|
"""Converts this Element to a JSON string."""
|
365
361
|
dict_ = self._to_dict()
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
default=DEFAULT_ELEMENT_SERIALIZER,
|
370
|
-
option=ln.DEFAULT_SERIALIZER_OPTION,
|
371
|
-
).decode()
|
372
|
-
return orjson.dumps(dict_, default=DEFAULT_ELEMENT_SERIALIZER)
|
362
|
+
return ln.json_dumps(
|
363
|
+
dict_, default=DEFAULT_ELEMENT_SERIALIZER, decode=decode
|
364
|
+
)
|
373
365
|
|
374
366
|
@classmethod
|
375
|
-
def from_json(cls, json_str: str
|
367
|
+
def from_json(cls, json_str: str) -> Element:
|
376
368
|
"""Deserializes a JSON string into an Element or subclass of Element."""
|
377
|
-
|
378
|
-
return cls.from_dict(data, mode=mode)
|
369
|
+
return cls.from_dict(orjson.loads(json_str))
|
379
370
|
|
380
371
|
|
381
372
|
DEFAULT_ELEMENT_SERIALIZER = ln.get_orjson_default(
|
lionagi/protocols/generic/log.py
CHANGED
@@ -176,9 +176,9 @@ class DataLogger:
|
|
176
176
|
suffix = fp.suffix.lower()
|
177
177
|
try:
|
178
178
|
if suffix == ".csv":
|
179
|
-
self.logs.
|
179
|
+
self.logs.dump(fp, "csv")
|
180
180
|
elif suffix == ".json":
|
181
|
-
self.logs.
|
181
|
+
self.logs.dump(fp, "json")
|
182
182
|
else:
|
183
183
|
raise ValueError(f"Unsupported file extension: {suffix}")
|
184
184
|
|
@@ -25,7 +25,7 @@ from pydapter import Adaptable, AsyncAdaptable
|
|
25
25
|
from typing_extensions import Self, deprecated, override
|
26
26
|
|
27
27
|
from lionagi._errors import ItemExistsError, ItemNotFoundError, ValidationError
|
28
|
-
from lionagi.
|
28
|
+
from lionagi.ln.concurrency import Lock as ConcurrencyLock
|
29
29
|
from lionagi.utils import (
|
30
30
|
UNDEFINED,
|
31
31
|
is_same_dtype,
|
@@ -116,7 +116,14 @@ class RoledMessage(Node, Sendable):
|
|
116
116
|
if isinstance(self.template, Template):
|
117
117
|
return self.template.render(**self.content)
|
118
118
|
except Exception:
|
119
|
-
return ln.json_dumps(
|
119
|
+
return ln.json_dumps(
|
120
|
+
self.content,
|
121
|
+
pretty=True,
|
122
|
+
sort_keys=True,
|
123
|
+
append_newline=True,
|
124
|
+
deterministic_sets=True,
|
125
|
+
decimal_as_float=True,
|
126
|
+
)
|
120
127
|
|
121
128
|
@classmethod
|
122
129
|
def create(cls, **kwargs):
|
@@ -2,12 +2,12 @@
|
|
2
2
|
#
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
4
4
|
|
5
|
-
from typing import Any
|
5
|
+
from typing import Any
|
6
6
|
|
7
7
|
from pydantic import BaseModel
|
8
8
|
from pydantic.fields import FieldInfo
|
9
9
|
|
10
|
-
from lionagi.
|
10
|
+
from lionagi.ln.fuzzy._fuzzy_match import fuzzy_match_keys
|
11
11
|
from lionagi.models import FieldModel, ModelParams, OperableModel
|
12
12
|
from lionagi.utils import UNDEFINED, to_json
|
13
13
|
|
@@ -150,6 +150,13 @@ class Endpoint:
|
|
150
150
|
"branch",
|
151
151
|
"aggregation_sources",
|
152
152
|
"aggregation_count",
|
153
|
+
"action_strategy",
|
154
|
+
"parse_model",
|
155
|
+
"reason",
|
156
|
+
"actions",
|
157
|
+
"return_operative",
|
158
|
+
"operative_model",
|
159
|
+
"request_model",
|
153
160
|
}
|
154
161
|
payload = {
|
155
162
|
k: v for k, v in payload.items() if k not in non_api_params
|
@@ -57,17 +57,9 @@ def match_endpoint(
|
|
57
57
|
|
58
58
|
return NvidiaNimChatEndpoint(None, **kwargs)
|
59
59
|
if provider == "claude_code":
|
60
|
-
|
61
|
-
from .providers.claude_code_cli import ClaudeCodeCLIEndpoint
|
60
|
+
from .providers.claude_code_cli import ClaudeCodeCLIEndpoint
|
62
61
|
|
63
|
-
|
64
|
-
|
65
|
-
if "query" in endpoint or "code" in endpoint:
|
66
|
-
from lionagi.service.connections.providers.claude_code_ import (
|
67
|
-
ClaudeCodeEndpoint,
|
68
|
-
)
|
69
|
-
|
70
|
-
return ClaudeCodeEndpoint(None, **kwargs)
|
62
|
+
return ClaudeCodeCLIEndpoint(None, **kwargs)
|
71
63
|
|
72
64
|
from .providers.oai_ import OpenaiChatEndpoint
|
73
65
|
|
@@ -1,6 +1,5 @@
|
|
1
1
|
from .anthropic_ import AnthropicMessagesEndpoint
|
2
|
-
from .
|
3
|
-
from .claude_code_cli import ClaudeCodeCLIEndpoint
|
2
|
+
from .claude_code_cli import ClaudeCodeCLIEndpoint, ClaudeCodeRequest
|
4
3
|
from .exa_ import ExaSearchEndpoint, ExaSearchRequest
|
5
4
|
from .oai_ import (
|
6
5
|
GroqChatEndpoint,
|
@@ -14,7 +13,6 @@ from .perplexity_ import PerplexityChatEndpoint, PerplexityChatRequest
|
|
14
13
|
|
15
14
|
__all__ = (
|
16
15
|
"AnthropicMessagesEndpoint",
|
17
|
-
"ClaudeCodeEndpoint",
|
18
16
|
"ClaudeCodeRequest",
|
19
17
|
"ClaudeCodeCLIEndpoint",
|
20
18
|
"ExaSearchEndpoint",
|
@@ -8,7 +8,7 @@ from typing import Any
|
|
8
8
|
import anyio
|
9
9
|
from pydantic import Field, PrivateAttr
|
10
10
|
|
11
|
-
from lionagi.
|
11
|
+
from lionagi.ln.concurrency import fail_after, get_cancelled_exc_class
|
12
12
|
from lionagi.protocols.types import Event, EventStatus
|
13
13
|
|
14
14
|
from ._types import AssosiatedEventInfo, HookEventTypes
|
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|
5
5
|
|
6
6
|
from typing import Any, TypeVar
|
7
7
|
|
8
|
-
from lionagi.
|
8
|
+
from lionagi.ln.concurrency import get_cancelled_exc_class
|
9
9
|
from lionagi.protocols.types import Event, EventStatus
|
10
10
|
from lionagi.utils import UNDEFINED
|
11
11
|
|
@@ -8,7 +8,7 @@ from typing import Any
|
|
8
8
|
|
9
9
|
from typing_extensions import Self, override
|
10
10
|
|
11
|
-
from lionagi.
|
11
|
+
from lionagi.ln.concurrency import CapacityLimiter, Lock, move_on_after
|
12
12
|
from lionagi.protocols.types import Executor, Processor
|
13
13
|
|
14
14
|
from .connections.api_calling import APICalling
|