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
lionagi/models/note.py
DELETED
@@ -1,383 +0,0 @@
|
|
1
|
-
# Copyright (c) 2023 - 2025, HaiyangLi <quantocean.li at gmail dot com>
|
2
|
-
#
|
3
|
-
# SPDX-License-Identifier: Apache-2.0
|
4
|
-
|
5
|
-
from collections.abc import ItemsView, Iterator, ValuesView
|
6
|
-
from typing import Any, TypeAlias
|
7
|
-
|
8
|
-
from pydantic import BaseModel, ConfigDict, Field, field_serializer
|
9
|
-
from typing_extensions import override
|
10
|
-
|
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
|
-
from lionagi.utils import UNDEFINED, copy, to_list
|
17
|
-
|
18
|
-
IndiceType: TypeAlias = str | list[str | int]
|
19
|
-
|
20
|
-
|
21
|
-
class Note(BaseModel):
|
22
|
-
"""Container for managing nested dictionary data structures.
|
23
|
-
|
24
|
-
A flexible container that provides deep nested data access, dictionary-like
|
25
|
-
interface, flattening capabilities, and update operations for managing
|
26
|
-
complex nested data structures.
|
27
|
-
|
28
|
-
Args:
|
29
|
-
**kwargs: Key-value pairs for initial content.
|
30
|
-
|
31
|
-
Attributes:
|
32
|
-
content: Nested dictionary structure.
|
33
|
-
model_config: Configuration allowing arbitrary types.
|
34
|
-
|
35
|
-
Examples:
|
36
|
-
>>> note = Note(
|
37
|
-
... user={
|
38
|
-
... "name": "John",
|
39
|
-
... "settings": {
|
40
|
-
... "theme": "dark"
|
41
|
-
... }
|
42
|
-
... }
|
43
|
-
... )
|
44
|
-
>>>
|
45
|
-
>>> # Access nested data
|
46
|
-
>>> name = note.get(["user", "name"])
|
47
|
-
>>> theme = note["user"]["settings"]["theme"]
|
48
|
-
>>>
|
49
|
-
>>> # Update nested structure
|
50
|
-
>>> note.update(["user", "settings"], {"language": "en"})
|
51
|
-
"""
|
52
|
-
|
53
|
-
content: dict[str, Any] = Field(
|
54
|
-
default_factory=dict
|
55
|
-
) # Nested data structure
|
56
|
-
|
57
|
-
model_config = ConfigDict(
|
58
|
-
arbitrary_types_allowed=True,
|
59
|
-
use_enum_values=True,
|
60
|
-
populate_by_name=True,
|
61
|
-
)
|
62
|
-
|
63
|
-
def __init__(self, **kwargs: Any) -> None:
|
64
|
-
"""Initialize Note with dictionary data.
|
65
|
-
|
66
|
-
Args:
|
67
|
-
**kwargs: Key-value pairs that will form the initial nested
|
68
|
-
dictionary structure.
|
69
|
-
"""
|
70
|
-
super().__init__()
|
71
|
-
self.content = kwargs
|
72
|
-
|
73
|
-
@field_serializer("content")
|
74
|
-
def _serialize_content(self, value: Any) -> dict[str, Any]:
|
75
|
-
"""Serialize content to dictionary format.
|
76
|
-
|
77
|
-
Args:
|
78
|
-
value: Content to serialize
|
79
|
-
|
80
|
-
Returns:
|
81
|
-
Deep copy of content dictionary
|
82
|
-
"""
|
83
|
-
output_dict = copy(value, deep=True)
|
84
|
-
return output_dict
|
85
|
-
|
86
|
-
def to_dict(self) -> dict[str, Any]:
|
87
|
-
"""Convert Note to dictionary, excluding undefined values.
|
88
|
-
|
89
|
-
Returns:
|
90
|
-
Dictionary representation with UNDEFINED values removed
|
91
|
-
"""
|
92
|
-
out = copy(self.content)
|
93
|
-
for k, v in self.content.items():
|
94
|
-
if v is UNDEFINED:
|
95
|
-
out.pop(k)
|
96
|
-
return out
|
97
|
-
|
98
|
-
def pop(
|
99
|
-
self,
|
100
|
-
indices: IndiceType,
|
101
|
-
/,
|
102
|
-
default: Any = UNDEFINED,
|
103
|
-
) -> Any:
|
104
|
-
"""Remove and return item from nested structure.
|
105
|
-
|
106
|
-
Removes and returns the value at the specified path in the nested
|
107
|
-
structure. If the path doesn't exist and no default is provided,
|
108
|
-
raises KeyError.
|
109
|
-
|
110
|
-
Args:
|
111
|
-
indices: Path to the item to remove, can be a string for top-level
|
112
|
-
keys or a list for nested access.
|
113
|
-
default: Value to return if the path is not found. If not provided
|
114
|
-
and path is not found, raises KeyError.
|
115
|
-
|
116
|
-
Returns:
|
117
|
-
The value that was removed, or the default value if provided and
|
118
|
-
path not found.
|
119
|
-
|
120
|
-
Raises:
|
121
|
-
KeyError: If the path is not found and no default value is provided.
|
122
|
-
"""
|
123
|
-
indices = to_list(indices, flatten=True, dropna=True)
|
124
|
-
return npop(self.content, indices, default)
|
125
|
-
|
126
|
-
def insert(self, indices: IndiceType, value: Any, /) -> None:
|
127
|
-
"""Insert value into nested structure at specified indices.
|
128
|
-
|
129
|
-
Args:
|
130
|
-
indices: Path where to insert
|
131
|
-
value: Value to insert
|
132
|
-
"""
|
133
|
-
indices = to_list(indices, flatten=True, dropna=True)
|
134
|
-
ninsert(self.content, indices, value)
|
135
|
-
|
136
|
-
def set(self, indices: IndiceType, value: Any, /) -> None:
|
137
|
-
"""Set value in nested structure at specified indices.
|
138
|
-
|
139
|
-
Args:
|
140
|
-
indices: Path where to set
|
141
|
-
value: Value to set
|
142
|
-
"""
|
143
|
-
indices = to_list(indices, flatten=True, dropna=True)
|
144
|
-
if self.get(indices, None) is None:
|
145
|
-
self.insert(indices, value)
|
146
|
-
else:
|
147
|
-
nset(self.content, indices, value)
|
148
|
-
|
149
|
-
def get(
|
150
|
-
self,
|
151
|
-
indices: IndiceType,
|
152
|
-
/,
|
153
|
-
default: Any = UNDEFINED,
|
154
|
-
) -> Any:
|
155
|
-
"""Get value from nested structure at specified indices.
|
156
|
-
|
157
|
-
Retrieves the value at the specified path in the nested structure.
|
158
|
-
If the path doesn't exist and no default is provided, raises KeyError.
|
159
|
-
|
160
|
-
Args:
|
161
|
-
indices: Path to the value, can be a string for top-level keys
|
162
|
-
or a list for nested access.
|
163
|
-
default: Value to return if the path is not found. If not provided
|
164
|
-
and path is not found, raises KeyError.
|
165
|
-
|
166
|
-
Returns:
|
167
|
-
The value at the specified path, or the default value if provided
|
168
|
-
and path not found.
|
169
|
-
|
170
|
-
Raises:
|
171
|
-
KeyError: If the path is not found and no default value is provided.
|
172
|
-
"""
|
173
|
-
indices = to_list(indices, flatten=True, dropna=True)
|
174
|
-
return nget(self.content, indices, default)
|
175
|
-
|
176
|
-
def keys(self, /, flat: bool = False, **kwargs: Any) -> list:
|
177
|
-
"""Get keys of the Note.
|
178
|
-
|
179
|
-
Args:
|
180
|
-
flat: If True, return flattened keys
|
181
|
-
kwargs: Additional flattening options
|
182
|
-
|
183
|
-
Returns:
|
184
|
-
List of keys, optionally flattened
|
185
|
-
"""
|
186
|
-
if flat:
|
187
|
-
kwargs["coerce_keys"] = kwargs.get("coerce_keys", False)
|
188
|
-
kwargs["coerce_sequence"] = kwargs.get("coerce_sequence", "list")
|
189
|
-
return flatten(self.content, **kwargs).keys()
|
190
|
-
return list(self.content.keys())
|
191
|
-
|
192
|
-
def values(self, /, flat: bool = False, **kwargs: Any) -> ValuesView:
|
193
|
-
"""Get values of the Note.
|
194
|
-
|
195
|
-
Returns either a view of top-level values or, if flat=True, a view
|
196
|
-
of all values in the flattened nested structure.
|
197
|
-
|
198
|
-
Args:
|
199
|
-
flat: If True, returns values from all levels of the nested
|
200
|
-
structure. If False, returns only top-level values.
|
201
|
-
kwargs: Additional options for flattening behavior when flat=True.
|
202
|
-
Common options include coerce_keys and coerce_sequence.
|
203
|
-
|
204
|
-
Returns:
|
205
|
-
A ValuesView object containing either top-level values or all
|
206
|
-
values from the flattened structure if flat=True.
|
207
|
-
"""
|
208
|
-
if flat:
|
209
|
-
kwargs["coerce_keys"] = kwargs.get("coerce_keys", False)
|
210
|
-
kwargs["coerce_sequence"] = kwargs.get("coerce_sequence", "list")
|
211
|
-
return flatten(self.content, **kwargs).values()
|
212
|
-
return self.content.values()
|
213
|
-
|
214
|
-
def items(self, /, flat: bool = False, **kwargs: Any) -> ItemsView:
|
215
|
-
"""Get items of the Note.
|
216
|
-
|
217
|
-
Args:
|
218
|
-
flat: If True, return flattened items
|
219
|
-
kwargs: Additional flattening options
|
220
|
-
|
221
|
-
Returns:
|
222
|
-
View of items, optionally flattened
|
223
|
-
"""
|
224
|
-
if flat:
|
225
|
-
kwargs["coerce_keys"] = kwargs.get("coerce_keys", False)
|
226
|
-
kwargs["coerce_sequence"] = kwargs.get("coerce_sequence", "list")
|
227
|
-
return flatten(self.content, **kwargs).items()
|
228
|
-
return self.content.items()
|
229
|
-
|
230
|
-
def clear(self) -> None:
|
231
|
-
"""Clear all content."""
|
232
|
-
self.content.clear()
|
233
|
-
|
234
|
-
def update(
|
235
|
-
self,
|
236
|
-
indices: IndiceType,
|
237
|
-
value: Any,
|
238
|
-
) -> None:
|
239
|
-
"""Update nested structure at specified indices.
|
240
|
-
|
241
|
-
Updates the value at the specified path in the nested structure.
|
242
|
-
The behavior depends on the existing value and the update value:
|
243
|
-
- If path doesn't exist: creates it with value (wrapped in list if scalar)
|
244
|
-
- If existing is list: extends with value if list, appends if scalar
|
245
|
-
- If existing is dict: updates with value if dict, raises error if not
|
246
|
-
|
247
|
-
Args:
|
248
|
-
indices: Path to the location to update, can be a string for
|
249
|
-
top-level keys or a list for nested access.
|
250
|
-
value: The new value to set. Must be compatible with existing
|
251
|
-
value type (dict for dict, any value for list).
|
252
|
-
|
253
|
-
Raises:
|
254
|
-
ValueError: If trying to update a dictionary with a non-dictionary
|
255
|
-
value.
|
256
|
-
"""
|
257
|
-
existing = None
|
258
|
-
if not indices:
|
259
|
-
existing = self.content
|
260
|
-
else:
|
261
|
-
existing = self.get(indices, None)
|
262
|
-
|
263
|
-
if existing is None:
|
264
|
-
if not isinstance(value, (list, dict)):
|
265
|
-
value = [value]
|
266
|
-
self.set(indices, value)
|
267
|
-
|
268
|
-
if isinstance(existing, list):
|
269
|
-
if isinstance(value, list):
|
270
|
-
existing.extend(value)
|
271
|
-
else:
|
272
|
-
existing.append(value)
|
273
|
-
|
274
|
-
elif isinstance(existing, dict):
|
275
|
-
if isinstance(value, self.__class__):
|
276
|
-
value = value.content
|
277
|
-
|
278
|
-
if isinstance(value, dict):
|
279
|
-
existing.update(value)
|
280
|
-
else:
|
281
|
-
raise ValueError(
|
282
|
-
"Cannot update a dictionary with a non-dictionary value."
|
283
|
-
)
|
284
|
-
|
285
|
-
@classmethod
|
286
|
-
def from_dict(cls, kwargs: Any) -> "Note":
|
287
|
-
"""Create Note instance from dictionary.
|
288
|
-
|
289
|
-
Args:
|
290
|
-
kwargs: Dictionary to initialize with
|
291
|
-
|
292
|
-
Returns:
|
293
|
-
New Note instance
|
294
|
-
"""
|
295
|
-
return cls(**kwargs)
|
296
|
-
|
297
|
-
def __contains__(self, indices: IndiceType) -> bool:
|
298
|
-
"""Check if indices exist in content.
|
299
|
-
|
300
|
-
Implements the 'in' operator for checking path existence in the nested
|
301
|
-
structure.
|
302
|
-
|
303
|
-
Args:
|
304
|
-
indices: Path to check, can be a string for top-level keys or a
|
305
|
-
list for nested access.
|
306
|
-
|
307
|
-
Returns:
|
308
|
-
True if the path exists in the nested structure, False otherwise.
|
309
|
-
"""
|
310
|
-
return self.content.get(indices, UNDEFINED) is not UNDEFINED
|
311
|
-
|
312
|
-
def __len__(self) -> int:
|
313
|
-
"""Get length of content.
|
314
|
-
|
315
|
-
Implements len() function to return the number of top-level keys in
|
316
|
-
the nested structure.
|
317
|
-
|
318
|
-
Returns:
|
319
|
-
The number of top-level keys in the content dictionary.
|
320
|
-
"""
|
321
|
-
return len(self.content)
|
322
|
-
|
323
|
-
def __iter__(self) -> Iterator[str]:
|
324
|
-
"""Get iterator over content.
|
325
|
-
|
326
|
-
Returns:
|
327
|
-
Iterator over top-level keys
|
328
|
-
"""
|
329
|
-
return iter(self.content)
|
330
|
-
|
331
|
-
def __next__(self) -> str:
|
332
|
-
"""Get next item from content iterator.
|
333
|
-
|
334
|
-
Returns:
|
335
|
-
Next key in iteration
|
336
|
-
"""
|
337
|
-
return next(iter(self.content))
|
338
|
-
|
339
|
-
@override
|
340
|
-
def __str__(self) -> str:
|
341
|
-
"""Get string representation of content.
|
342
|
-
|
343
|
-
Implements str() function to provide a simple string representation
|
344
|
-
of the Note's content. Uses the standard dictionary string format.
|
345
|
-
|
346
|
-
Returns:
|
347
|
-
A string representation of the content dictionary, showing its
|
348
|
-
current state.
|
349
|
-
"""
|
350
|
-
return str(self.content)
|
351
|
-
|
352
|
-
@override
|
353
|
-
def __repr__(self) -> str:
|
354
|
-
"""Get detailed string representation of content.
|
355
|
-
|
356
|
-
Returns:
|
357
|
-
Detailed string representation of content dict
|
358
|
-
"""
|
359
|
-
return repr(self.content)
|
360
|
-
|
361
|
-
def __getitem__(self, indices: IndiceType) -> Any:
|
362
|
-
"""Get item using index notation.
|
363
|
-
|
364
|
-
Args:
|
365
|
-
indices: Path to value
|
366
|
-
|
367
|
-
Returns:
|
368
|
-
Value at path
|
369
|
-
|
370
|
-
Raises:
|
371
|
-
KeyError: If path not found
|
372
|
-
"""
|
373
|
-
indices = to_list(indices, flatten=True, dropna=True)
|
374
|
-
return self.get(indices)
|
375
|
-
|
376
|
-
def __setitem__(self, indices: IndiceType, value: Any) -> None:
|
377
|
-
"""Set item using index notation.
|
378
|
-
|
379
|
-
Args:
|
380
|
-
indices: Path where to set
|
381
|
-
value: Value to set
|
382
|
-
"""
|
383
|
-
self.set(indices, value)
|
File without changes
|
@@ -1,47 +0,0 @@
|
|
1
|
-
from typing import TYPE_CHECKING, Literal
|
2
|
-
|
3
|
-
from lionagi.service.imodel import iModel
|
4
|
-
|
5
|
-
if TYPE_CHECKING:
|
6
|
-
from lionagi.session.branch import Branch
|
7
|
-
|
8
|
-
|
9
|
-
async def translate(
|
10
|
-
branch: "Branch",
|
11
|
-
text: str,
|
12
|
-
technique: Literal["SynthLang"] = "SynthLang",
|
13
|
-
technique_kwargs: dict = None,
|
14
|
-
compress: bool = False,
|
15
|
-
chat_model: iModel = None,
|
16
|
-
compress_model: iModel = None,
|
17
|
-
compression_ratio: float = 0.2,
|
18
|
-
compress_kwargs=None,
|
19
|
-
verbose: bool = True,
|
20
|
-
new_branch: bool = True,
|
21
|
-
**kwargs,
|
22
|
-
):
|
23
|
-
if technique == "SynthLang":
|
24
|
-
from lionagi.libs.token_transform.synthlang import (
|
25
|
-
translate_to_synthlang,
|
26
|
-
)
|
27
|
-
|
28
|
-
if not technique_kwargs:
|
29
|
-
technique_kwargs = {}
|
30
|
-
if not technique_kwargs.get("template_name"):
|
31
|
-
technique_kwargs["template_name"] = "symbolic_systems"
|
32
|
-
|
33
|
-
technique_kwargs = {**technique_kwargs, **kwargs}
|
34
|
-
|
35
|
-
return await translate_to_synthlang(
|
36
|
-
text=text,
|
37
|
-
compress=compress,
|
38
|
-
chat_model=chat_model or branch.chat_model,
|
39
|
-
compress_model=compress_model,
|
40
|
-
compression_ratio=compression_ratio,
|
41
|
-
compress_kwargs=compress_kwargs,
|
42
|
-
verbose=verbose,
|
43
|
-
branch=branch if not new_branch else None,
|
44
|
-
**technique_kwargs,
|
45
|
-
)
|
46
|
-
|
47
|
-
raise ValueError(f"Technique {technique} is not supported.")
|