lionagi 0.16.1__py3-none-any.whl → 0.16.2__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/libs/file/save.py +8 -1
- lionagi/ln/__init__.py +6 -0
- lionagi/ln/_json_dump.py +322 -49
- lionagi/models/note.py +8 -4
- lionagi/operations/brainstorm/brainstorm.py +10 -10
- lionagi/protocols/generic/element.py +5 -14
- lionagi/protocols/generic/log.py +2 -2
- lionagi/protocols/messages/message.py +8 -1
- lionagi/service/connections/endpoint.py +7 -0
- lionagi/service/connections/providers/claude_code_.py +6 -1
- lionagi/session/branch.py +1 -101
- lionagi/session/session.py +9 -14
- lionagi/utils.py +2 -1
- lionagi/version.py +1 -1
- {lionagi-0.16.1.dist-info → lionagi-0.16.2.dist-info}/METADATA +1 -2
- {lionagi-0.16.1.dist-info → lionagi-0.16.2.dist-info}/RECORD +18 -44
- lionagi/libs/file/params.py +0 -175
- 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/operations/translate/__init__.py +0 -0
- lionagi/operations/translate/translate.py +0 -47
- lionagi/tools/memory/tools.py +0 -495
- {lionagi-0.16.1.dist-info → lionagi-0.16.2.dist-info}/WHEEL +0 -0
- {lionagi-0.16.1.dist-info → lionagi-0.16.2.dist-info}/licenses/LICENSE +0 -0
lionagi/libs/file/save.py
CHANGED
@@ -89,7 +89,14 @@ def save_chunks(
|
|
89
89
|
random_hash_digits=random_hash_digits,
|
90
90
|
)
|
91
91
|
save_to_file(
|
92
|
-
ln.json_dumps(
|
92
|
+
ln.json_dumps(
|
93
|
+
chunk,
|
94
|
+
pretty=True,
|
95
|
+
sort_keys=True,
|
96
|
+
append_newline=True,
|
97
|
+
deterministic_sets=True,
|
98
|
+
decimal_as_float=True,
|
99
|
+
),
|
93
100
|
directory=file_path.parent,
|
94
101
|
filename=file_path.name,
|
95
102
|
verbose=verbose,
|
lionagi/ln/__init__.py
CHANGED
@@ -4,7 +4,10 @@ from ._json_dump import (
|
|
4
4
|
DEFAULT_SERIALIZER,
|
5
5
|
DEFAULT_SERIALIZER_OPTION,
|
6
6
|
get_orjson_default,
|
7
|
+
json_dumpb,
|
7
8
|
json_dumps,
|
9
|
+
json_lines_iter,
|
10
|
+
make_options,
|
8
11
|
)
|
9
12
|
from ._list_call import lcall
|
10
13
|
from ._to_list import to_list
|
@@ -47,6 +50,9 @@ __all__ = (
|
|
47
50
|
"DEFAULT_SERIALIZER_OPTION",
|
48
51
|
"get_orjson_default",
|
49
52
|
"json_dumps",
|
53
|
+
"make_options",
|
54
|
+
"json_dumpb",
|
55
|
+
"json_lines_iter",
|
50
56
|
"lcall",
|
51
57
|
"to_list",
|
52
58
|
"acreate_path",
|
lionagi/ln/_json_dump.py
CHANGED
@@ -1,75 +1,348 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
1
3
|
import datetime as dt
|
2
4
|
import decimal
|
3
|
-
|
5
|
+
import re
|
6
|
+
from collections.abc import Callable, Iterable, Mapping
|
7
|
+
from enum import Enum
|
8
|
+
from functools import lru_cache
|
4
9
|
from pathlib import Path
|
10
|
+
from textwrap import shorten
|
11
|
+
from typing import Any
|
5
12
|
from uuid import UUID
|
6
13
|
|
7
14
|
import orjson
|
8
15
|
|
16
|
+
__all__ = [
|
17
|
+
"get_orjson_default",
|
18
|
+
"DEFAULT_SERIALIZER",
|
19
|
+
"DEFAULT_SERIALIZER_OPTION",
|
20
|
+
"make_options",
|
21
|
+
"json_dumpb",
|
22
|
+
"json_dumps",
|
23
|
+
"json_lines_iter",
|
24
|
+
]
|
25
|
+
|
26
|
+
# Types orjson already serializes natively at C/Rust speed.
|
27
|
+
# (We only route them through default() when passthrough is requested.)
|
28
|
+
_NATIVE = (dt.datetime, dt.date, dt.time, UUID)
|
29
|
+
|
30
|
+
# --------- helpers ------------------------------------------------------------
|
31
|
+
|
32
|
+
_ADDR_PAT = re.compile(r" at 0x[0-9A-Fa-f]+")
|
33
|
+
|
34
|
+
|
35
|
+
def _clip(s: str, limit: int = 2048) -> str:
|
36
|
+
return shorten(s, width=limit, placeholder=f"...(+{len(s) - limit} chars)") # type: ignore[arg-type]
|
37
|
+
|
38
|
+
|
39
|
+
def _normalize_for_sorting(x: Any) -> str:
|
40
|
+
"""Normalize repr/str to remove process-specific addresses."""
|
41
|
+
s = str(x)
|
42
|
+
return _ADDR_PAT.sub(" at 0x?", s)
|
43
|
+
|
44
|
+
|
45
|
+
def _stable_sorted_iterable(o: Iterable[Any]) -> list[Any]:
|
46
|
+
"""
|
47
|
+
Deterministic ordering for sets (including mixed types).
|
48
|
+
Key: (class name, normalized str) avoids comparisons across unlike types
|
49
|
+
and removes memory address variance in default reprs.
|
50
|
+
"""
|
51
|
+
return sorted(
|
52
|
+
o, key=lambda x: (x.__class__.__name__, _normalize_for_sorting(x))
|
53
|
+
)
|
54
|
+
|
55
|
+
|
56
|
+
def _safe_exception_payload(ex: Exception) -> dict[str, str]:
|
57
|
+
return {"type": ex.__class__.__name__, "message": str(ex)}
|
9
58
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
59
|
+
|
60
|
+
def _default_serializers(
|
61
|
+
deterministic_sets: bool,
|
62
|
+
decimal_as_float: bool,
|
63
|
+
enum_as_name: bool,
|
64
|
+
passthrough_datetime: bool,
|
65
|
+
) -> dict[type, Callable[[Any], Any]]:
|
66
|
+
ser: dict[type, Callable[[Any], Any]] = {
|
67
|
+
Path: str,
|
68
|
+
decimal.Decimal: (float if decimal_as_float else str),
|
69
|
+
set: (_stable_sorted_iterable if deterministic_sets else list),
|
70
|
+
frozenset: (_stable_sorted_iterable if deterministic_sets else list),
|
18
71
|
}
|
72
|
+
if enum_as_name:
|
73
|
+
ser[Enum] = lambda e: e.name
|
74
|
+
# Only needed if you also set OPT_PASSTHROUGH_DATETIME via options.
|
75
|
+
if passthrough_datetime:
|
76
|
+
ser[dt.datetime] = lambda o: o.isoformat()
|
77
|
+
return ser
|
19
78
|
|
20
79
|
|
21
|
-
|
22
|
-
return [dt.datetime, Path, UUID, decimal.Decimal, set, frozenset]
|
80
|
+
# --------- default() factory --------------------------------------------------
|
23
81
|
|
24
82
|
|
25
83
|
def get_orjson_default(
|
26
|
-
|
27
|
-
|
84
|
+
*,
|
85
|
+
order: list[type] | None = None,
|
86
|
+
additional: Mapping[type, Callable[[Any], Any]] | None = None,
|
28
87
|
extend_default: bool = True,
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
88
|
+
deterministic_sets: bool = False,
|
89
|
+
decimal_as_float: bool = False,
|
90
|
+
enum_as_name: bool = False,
|
91
|
+
passthrough_datetime: bool = False,
|
92
|
+
safe_fallback: bool = False,
|
93
|
+
fallback_clip: int = 2048,
|
94
|
+
) -> Callable[[Any], Any]:
|
35
95
|
"""
|
36
|
-
|
37
|
-
|
38
|
-
|
96
|
+
Build a fast, extensible `default=` callable for orjson.dumps.
|
97
|
+
|
98
|
+
- deterministic_sets: sort set/frozenset deterministically (slower).
|
99
|
+
- decimal_as_float: serialize Decimal as float (faster/smaller; precision loss).
|
100
|
+
- enum_as_name: serialize Enum as .name (else orjson uses .value by default).
|
101
|
+
- passthrough_datetime: if True, also pass OPT_PASSTHROUGH_DATETIME in options.
|
102
|
+
- safe_fallback: if True, unknown objects never raise (for logs);
|
103
|
+
Exceptions become a tiny dict; all else becomes clipped repr(str).
|
104
|
+
|
105
|
+
'order' and 'additional' preserve your override semantics.
|
106
|
+
"""
|
107
|
+
ser = _default_serializers(
|
108
|
+
deterministic_sets=deterministic_sets,
|
109
|
+
decimal_as_float=decimal_as_float,
|
110
|
+
enum_as_name=enum_as_name,
|
111
|
+
passthrough_datetime=passthrough_datetime,
|
112
|
+
)
|
113
|
+
if additional:
|
114
|
+
ser.update(additional)
|
115
|
+
|
116
|
+
base_order: list[type] = [Path, decimal.Decimal, set, frozenset]
|
117
|
+
if enum_as_name:
|
118
|
+
base_order.insert(0, Enum)
|
119
|
+
if passthrough_datetime:
|
120
|
+
base_order.insert(0, dt.datetime)
|
39
121
|
|
40
122
|
if order:
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
123
|
+
order_ = (
|
124
|
+
(base_order + [t for t in order if t not in base_order])
|
125
|
+
if extend_default
|
126
|
+
else list(order)
|
127
|
+
)
|
45
128
|
else:
|
46
|
-
|
47
|
-
|
129
|
+
order_ = base_order.copy()
|
130
|
+
|
131
|
+
if not passthrough_datetime:
|
132
|
+
# Avoid checks for types already on the orjson native fast path.
|
133
|
+
order_ = [t for t in order_ if t not in _NATIVE]
|
134
|
+
|
135
|
+
order_tuple = tuple(order_)
|
136
|
+
cache: dict[type, Callable[[Any], Any]] = {}
|
48
137
|
|
49
|
-
def default(obj):
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
138
|
+
def default(obj: Any) -> Any:
|
139
|
+
typ = obj.__class__
|
140
|
+
func = cache.get(typ)
|
141
|
+
if func is None:
|
142
|
+
for T in order_tuple:
|
143
|
+
if issubclass(typ, T):
|
144
|
+
f = ser.get(T)
|
145
|
+
if f:
|
146
|
+
cache[typ] = f
|
147
|
+
func = f
|
148
|
+
break
|
149
|
+
else:
|
150
|
+
# Duck-typed support for common data holders
|
151
|
+
md = getattr(obj, "model_dump", None)
|
152
|
+
if callable(md):
|
153
|
+
try:
|
154
|
+
return md()
|
155
|
+
except Exception:
|
156
|
+
pass
|
157
|
+
dd = getattr(obj, "dict", None)
|
158
|
+
if callable(dd):
|
159
|
+
try:
|
160
|
+
return dd()
|
161
|
+
except Exception:
|
162
|
+
pass
|
163
|
+
if safe_fallback:
|
164
|
+
if isinstance(obj, Exception):
|
165
|
+
return _safe_exception_payload(obj)
|
166
|
+
return _clip(repr(obj), fallback_clip)
|
167
|
+
raise TypeError(
|
168
|
+
f"Type is not JSON serializable: {typ.__name__}"
|
169
|
+
)
|
170
|
+
return func(obj)
|
54
171
|
|
55
172
|
return default
|
56
173
|
|
57
174
|
|
175
|
+
@lru_cache(maxsize=128)
|
176
|
+
def _cached_default(
|
177
|
+
deterministic_sets: bool,
|
178
|
+
decimal_as_float: bool,
|
179
|
+
enum_as_name: bool,
|
180
|
+
passthrough_datetime: bool,
|
181
|
+
safe_fallback: bool,
|
182
|
+
fallback_clip: int,
|
183
|
+
):
|
184
|
+
return get_orjson_default(
|
185
|
+
deterministic_sets=deterministic_sets,
|
186
|
+
decimal_as_float=decimal_as_float,
|
187
|
+
enum_as_name=enum_as_name,
|
188
|
+
passthrough_datetime=passthrough_datetime,
|
189
|
+
safe_fallback=safe_fallback,
|
190
|
+
fallback_clip=fallback_clip,
|
191
|
+
)
|
192
|
+
|
193
|
+
|
194
|
+
# --------- defaults & options -------------------------------------------------
|
195
|
+
|
196
|
+
# Compact, no newline, no sorting: neutral default for most use-cases.
|
197
|
+
DEFAULT_SERIALIZER_OPTION = 0
|
58
198
|
DEFAULT_SERIALIZER = get_orjson_default()
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
199
|
+
|
200
|
+
|
201
|
+
def make_options(
|
202
|
+
*,
|
203
|
+
pretty: bool = False,
|
204
|
+
sort_keys: bool = False,
|
205
|
+
naive_utc: bool = False,
|
206
|
+
utc_z: bool = False,
|
207
|
+
append_newline: bool = False,
|
208
|
+
passthrough_datetime: bool = False,
|
209
|
+
allow_non_str_keys: bool = False,
|
210
|
+
) -> int:
|
211
|
+
"""
|
212
|
+
Compose orjson 'option' bit flags succinctly.
|
213
|
+
"""
|
214
|
+
opt = 0
|
215
|
+
if append_newline:
|
216
|
+
opt |= orjson.OPT_APPEND_NEWLINE
|
217
|
+
if pretty:
|
218
|
+
opt |= orjson.OPT_INDENT_2
|
219
|
+
if sort_keys:
|
220
|
+
opt |= orjson.OPT_SORT_KEYS
|
221
|
+
if naive_utc:
|
222
|
+
opt |= orjson.OPT_NAIVE_UTC
|
223
|
+
if utc_z:
|
224
|
+
opt |= orjson.OPT_UTC_Z
|
225
|
+
if passthrough_datetime:
|
226
|
+
opt |= orjson.OPT_PASSTHROUGH_DATETIME
|
227
|
+
if allow_non_str_keys:
|
228
|
+
opt |= orjson.OPT_NON_STR_KEYS
|
229
|
+
return opt
|
230
|
+
|
231
|
+
|
232
|
+
# --------- dump helpers -------------------------------------------------------
|
233
|
+
|
234
|
+
|
235
|
+
def json_dumpb(
|
236
|
+
obj: Any,
|
237
|
+
*,
|
238
|
+
pretty: bool = False,
|
239
|
+
sort_keys: bool = False,
|
240
|
+
naive_utc: bool = False,
|
241
|
+
utc_z: bool = False,
|
242
|
+
append_newline: bool = False,
|
243
|
+
allow_non_str_keys: bool = False,
|
244
|
+
deterministic_sets: bool = False,
|
245
|
+
decimal_as_float: bool = False,
|
246
|
+
enum_as_name: bool = False,
|
247
|
+
passthrough_datetime: bool = False,
|
248
|
+
safe_fallback: bool = False,
|
249
|
+
fallback_clip: int = 2048,
|
250
|
+
default: Callable[[Any], Any] | None = None,
|
251
|
+
options: int | None = None,
|
252
|
+
) -> bytes:
|
253
|
+
"""
|
254
|
+
Serialize to **bytes** (fast path). Prefer this in hot code.
|
255
|
+
|
256
|
+
Notes:
|
257
|
+
- If you set passthrough_datetime=True, you likely also want it in options.
|
258
|
+
- safe_fallback=True is recommended for LOGGING ONLY.
|
259
|
+
"""
|
260
|
+
if default is None:
|
261
|
+
default = _cached_default(
|
262
|
+
deterministic_sets=deterministic_sets,
|
263
|
+
decimal_as_float=decimal_as_float,
|
264
|
+
enum_as_name=enum_as_name,
|
265
|
+
passthrough_datetime=passthrough_datetime,
|
266
|
+
safe_fallback=safe_fallback,
|
267
|
+
fallback_clip=fallback_clip,
|
268
|
+
)
|
269
|
+
opt = (
|
270
|
+
options
|
271
|
+
if options is not None
|
272
|
+
else make_options(
|
273
|
+
pretty=pretty,
|
274
|
+
sort_keys=sort_keys,
|
275
|
+
naive_utc=naive_utc,
|
276
|
+
utc_z=utc_z,
|
277
|
+
append_newline=append_newline,
|
278
|
+
passthrough_datetime=passthrough_datetime,
|
279
|
+
allow_non_str_keys=allow_non_str_keys,
|
280
|
+
)
|
72
281
|
)
|
73
|
-
|
74
|
-
|
75
|
-
|
282
|
+
return orjson.dumps(obj, default=default, option=opt)
|
283
|
+
|
284
|
+
|
285
|
+
def json_dumps(
|
286
|
+
obj: Any,
|
287
|
+
/,
|
288
|
+
*,
|
289
|
+
decode: bool = True,
|
290
|
+
**kwargs: Any,
|
291
|
+
) -> str | bytes:
|
292
|
+
"""
|
293
|
+
Serialize to str by default (decode=True), or bytes if decode=False.
|
294
|
+
"""
|
295
|
+
out = json_dumpb(obj, **kwargs)
|
296
|
+
return out.decode("utf-8") if decode else out
|
297
|
+
|
298
|
+
|
299
|
+
# --------- streaming for very large outputs ----------------------------------
|
300
|
+
|
301
|
+
|
302
|
+
def json_lines_iter(
|
303
|
+
it: Iterable[Any],
|
304
|
+
*,
|
305
|
+
# default() configuration for each line
|
306
|
+
deterministic_sets: bool = False,
|
307
|
+
decimal_as_float: bool = False,
|
308
|
+
enum_as_name: bool = False,
|
309
|
+
passthrough_datetime: bool = False,
|
310
|
+
safe_fallback: bool = False,
|
311
|
+
fallback_clip: int = 2048,
|
312
|
+
# options
|
313
|
+
naive_utc: bool = False,
|
314
|
+
utc_z: bool = False,
|
315
|
+
allow_non_str_keys: bool = False,
|
316
|
+
# advanced
|
317
|
+
default: Callable[[Any], Any] | None = None,
|
318
|
+
options: int | None = None,
|
319
|
+
) -> Iterable[bytes]:
|
320
|
+
"""
|
321
|
+
Stream an iterable as **NDJSON** (one JSON object per line) in **bytes**.
|
322
|
+
|
323
|
+
Always ensures a trailing newline per line (OPT_APPEND_NEWLINE).
|
324
|
+
"""
|
325
|
+
if default is None:
|
326
|
+
default = _cached_default(
|
327
|
+
deterministic_sets=deterministic_sets,
|
328
|
+
decimal_as_float=decimal_as_float,
|
329
|
+
enum_as_name=enum_as_name,
|
330
|
+
passthrough_datetime=passthrough_datetime,
|
331
|
+
safe_fallback=safe_fallback,
|
332
|
+
fallback_clip=fallback_clip,
|
333
|
+
)
|
334
|
+
if options is None:
|
335
|
+
opt = make_options(
|
336
|
+
pretty=False,
|
337
|
+
sort_keys=False,
|
338
|
+
naive_utc=naive_utc,
|
339
|
+
utc_z=utc_z,
|
340
|
+
append_newline=True, # enforce newline for NDJSON
|
341
|
+
passthrough_datetime=passthrough_datetime,
|
342
|
+
allow_non_str_keys=allow_non_str_keys,
|
343
|
+
)
|
344
|
+
else:
|
345
|
+
opt = options | orjson.OPT_APPEND_NEWLINE
|
346
|
+
|
347
|
+
for item in it:
|
348
|
+
yield orjson.dumps(item, default=default, option=opt)
|
lionagi/models/note.py
CHANGED
@@ -9,10 +9,6 @@ from pydantic import BaseModel, ConfigDict, Field, field_serializer
|
|
9
9
|
from typing_extensions import override
|
10
10
|
|
11
11
|
from lionagi.libs.nested.flatten import flatten
|
12
|
-
from lionagi.libs.nested.nget import nget
|
13
|
-
from lionagi.libs.nested.ninsert import ninsert
|
14
|
-
from lionagi.libs.nested.npop import npop
|
15
|
-
from lionagi.libs.nested.nset import nset
|
16
12
|
from lionagi.utils import UNDEFINED, copy, to_list
|
17
13
|
|
18
14
|
IndiceType: TypeAlias = str | list[str | int]
|
@@ -120,6 +116,8 @@ class Note(BaseModel):
|
|
120
116
|
Raises:
|
121
117
|
KeyError: If the path is not found and no default value is provided.
|
122
118
|
"""
|
119
|
+
from lionagi.libs.nested.npop import npop
|
120
|
+
|
123
121
|
indices = to_list(indices, flatten=True, dropna=True)
|
124
122
|
return npop(self.content, indices, default)
|
125
123
|
|
@@ -130,6 +128,8 @@ class Note(BaseModel):
|
|
130
128
|
indices: Path where to insert
|
131
129
|
value: Value to insert
|
132
130
|
"""
|
131
|
+
from lionagi.libs.nested.ninsert import ninsert
|
132
|
+
|
133
133
|
indices = to_list(indices, flatten=True, dropna=True)
|
134
134
|
ninsert(self.content, indices, value)
|
135
135
|
|
@@ -144,6 +144,8 @@ class Note(BaseModel):
|
|
144
144
|
if self.get(indices, None) is None:
|
145
145
|
self.insert(indices, value)
|
146
146
|
else:
|
147
|
+
from lionagi.libs.nested.nset import nset
|
148
|
+
|
147
149
|
nset(self.content, indices, value)
|
148
150
|
|
149
151
|
def get(
|
@@ -170,6 +172,8 @@ class Note(BaseModel):
|
|
170
172
|
Raises:
|
171
173
|
KeyError: If the path is not found and no default value is provided.
|
172
174
|
"""
|
175
|
+
from lionagi.libs.nested.nget import nget
|
176
|
+
|
173
177
|
indices = to_list(indices, flatten=True, dropna=True)
|
174
178
|
return nget(self.content, indices, default)
|
175
179
|
|
@@ -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
|
|
@@ -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
|
|
@@ -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):
|
@@ -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
|
@@ -266,7 +266,12 @@ def _verbose_output(res) -> str:
|
|
266
266
|
inp_ = None
|
267
267
|
|
268
268
|
if isinstance(block.input, dict | list):
|
269
|
-
inp_ = ln.json_dumps(
|
269
|
+
inp_ = ln.json_dumps(
|
270
|
+
block.input,
|
271
|
+
pretty=True,
|
272
|
+
sort_keys=True,
|
273
|
+
append_newline=True,
|
274
|
+
)
|
270
275
|
else:
|
271
276
|
inp_ = str(block.input)
|
272
277
|
|