lionagi 0.12.3__py3-none-any.whl → 0.12.5__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/config.py +123 -0
- lionagi/libs/schema/load_pydantic_model_from_schema.py +259 -0
- lionagi/libs/token_transform/perplexity.py +2 -4
- lionagi/libs/token_transform/synthlang_/translate_to_synthlang.py +1 -1
- lionagi/operations/chat/chat.py +2 -2
- lionagi/operations/communicate/communicate.py +20 -5
- lionagi/operations/parse/parse.py +131 -43
- lionagi/protocols/generic/pile.py +94 -33
- lionagi/protocols/graph/node.py +25 -19
- lionagi/protocols/messages/assistant_response.py +20 -1
- lionagi/service/connections/__init__.py +15 -0
- lionagi/service/connections/api_calling.py +230 -0
- lionagi/service/connections/endpoint.py +410 -0
- lionagi/service/connections/endpoint_config.py +137 -0
- lionagi/service/connections/header_factory.py +56 -0
- lionagi/service/connections/match_endpoint.py +49 -0
- lionagi/service/connections/providers/__init__.py +3 -0
- lionagi/service/connections/providers/anthropic_.py +87 -0
- lionagi/service/connections/providers/exa_.py +33 -0
- lionagi/service/connections/providers/oai_.py +166 -0
- lionagi/service/connections/providers/ollama_.py +122 -0
- lionagi/service/connections/providers/perplexity_.py +29 -0
- lionagi/service/imodel.py +36 -144
- lionagi/service/manager.py +1 -7
- lionagi/service/{endpoints/rate_limited_processor.py → rate_limited_processor.py} +4 -2
- lionagi/service/resilience.py +545 -0
- lionagi/service/third_party/README.md +71 -0
- lionagi/service/third_party/anthropic_models.py +159 -0
- lionagi/service/{providers/exa_/models.py → third_party/exa_models.py} +18 -13
- lionagi/service/third_party/openai_models.py +18241 -0
- lionagi/service/third_party/pplx_models.py +156 -0
- lionagi/service/types.py +5 -4
- lionagi/session/branch.py +12 -7
- lionagi/tools/file/reader.py +1 -1
- lionagi/tools/memory/tools.py +497 -0
- lionagi/version.py +1 -1
- {lionagi-0.12.3.dist-info → lionagi-0.12.5.dist-info}/METADATA +17 -19
- {lionagi-0.12.3.dist-info → lionagi-0.12.5.dist-info}/RECORD +43 -54
- lionagi/adapters/__init__.py +0 -1
- lionagi/adapters/adapter.py +0 -120
- lionagi/adapters/json_adapter.py +0 -181
- lionagi/adapters/pandas_/csv_adapter.py +0 -94
- lionagi/adapters/pandas_/excel_adapter.py +0 -94
- lionagi/adapters/pandas_/pd_dataframe_adapter.py +0 -81
- lionagi/adapters/pandas_/pd_series_adapter.py +0 -57
- lionagi/adapters/toml_adapter.py +0 -204
- lionagi/adapters/types.py +0 -21
- lionagi/service/endpoints/__init__.py +0 -3
- lionagi/service/endpoints/base.py +0 -706
- lionagi/service/endpoints/chat_completion.py +0 -116
- lionagi/service/endpoints/match_endpoint.py +0 -72
- lionagi/service/providers/__init__.py +0 -3
- lionagi/service/providers/anthropic_/__init__.py +0 -3
- lionagi/service/providers/anthropic_/messages.py +0 -99
- lionagi/service/providers/exa_/search.py +0 -80
- lionagi/service/providers/exa_/types.py +0 -7
- lionagi/service/providers/groq_/__init__.py +0 -3
- lionagi/service/providers/groq_/chat_completions.py +0 -56
- lionagi/service/providers/ollama_/__init__.py +0 -3
- lionagi/service/providers/ollama_/chat_completions.py +0 -134
- lionagi/service/providers/openai_/__init__.py +0 -3
- lionagi/service/providers/openai_/chat_completions.py +0 -101
- lionagi/service/providers/openai_/spec.py +0 -14
- lionagi/service/providers/openrouter_/__init__.py +0 -3
- lionagi/service/providers/openrouter_/chat_completions.py +0 -62
- lionagi/service/providers/perplexity_/__init__.py +0 -3
- lionagi/service/providers/perplexity_/chat_completions.py +0 -44
- lionagi/service/providers/perplexity_/models.py +0 -144
- lionagi/service/providers/types.py +0 -17
- /lionagi/{adapters/pandas_/__init__.py → py.typed} +0 -0
- /lionagi/service/{providers/exa_ → third_party}/__init__.py +0 -0
- /lionagi/service/{endpoints/token_calculator.py → token_calculator.py} +0 -0
- {lionagi-0.12.3.dist-info → lionagi-0.12.5.dist-info}/WHEEL +0 -0
- {lionagi-0.12.3.dist-info → lionagi-0.12.5.dist-info}/licenses/LICENSE +0 -0
@@ -1,81 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Defines a `PandasDataFrameAdapter` that converts between
|
3
|
-
a DataFrame and a list of dictionary-based elements.
|
4
|
-
"""
|
5
|
-
|
6
|
-
from datetime import datetime
|
7
|
-
|
8
|
-
import pandas as pd
|
9
|
-
|
10
|
-
from ..adapter import Adapter, T
|
11
|
-
|
12
|
-
|
13
|
-
class PandasDataFrameAdapter(Adapter):
|
14
|
-
"""
|
15
|
-
Converts a set of objects to a single `pd.DataFrame`, or
|
16
|
-
a DataFrame to a list of dictionaries. Typically used in memory,
|
17
|
-
not for saving to file.
|
18
|
-
"""
|
19
|
-
|
20
|
-
obj_key = "pd_dataframe"
|
21
|
-
alias = ("pandas_dataframe", "pd.DataFrame", "pd_dataframe")
|
22
|
-
|
23
|
-
@classmethod
|
24
|
-
def from_obj(
|
25
|
-
cls, subj_cls: type[T], obj: pd.DataFrame, /, **kwargs
|
26
|
-
) -> list[dict]:
|
27
|
-
"""
|
28
|
-
Convert an existing DataFrame into a list of dicts.
|
29
|
-
|
30
|
-
Parameters
|
31
|
-
----------
|
32
|
-
subj_cls : type[T]
|
33
|
-
The internal class to which we might parse.
|
34
|
-
obj : pd.DataFrame
|
35
|
-
The DataFrame to convert.
|
36
|
-
**kwargs
|
37
|
-
Additional args for DataFrame.to_dict (like `orient`).
|
38
|
-
|
39
|
-
Returns
|
40
|
-
-------
|
41
|
-
list[dict]
|
42
|
-
Each row as a dictionary.
|
43
|
-
"""
|
44
|
-
return obj.to_dict(orient="records", **kwargs)
|
45
|
-
|
46
|
-
@classmethod
|
47
|
-
def to_obj(cls, subj: list[T], /, **kwargs) -> pd.DataFrame:
|
48
|
-
"""
|
49
|
-
Convert multiple items into a DataFrame, adjusting `created_at` to datetime.
|
50
|
-
|
51
|
-
Parameters
|
52
|
-
----------
|
53
|
-
subj : list[T]
|
54
|
-
The items to convert. Each item must have `to_dict()`.
|
55
|
-
**kwargs
|
56
|
-
Additional arguments for `pd.DataFrame(...)`.
|
57
|
-
|
58
|
-
Returns
|
59
|
-
-------
|
60
|
-
pd.DataFrame
|
61
|
-
The resulting DataFrame.
|
62
|
-
"""
|
63
|
-
out_ = []
|
64
|
-
for i in subj:
|
65
|
-
_dict = i.to_dict()
|
66
|
-
# Attempt to parse timestamps
|
67
|
-
if "created_at" in _dict:
|
68
|
-
try:
|
69
|
-
_dict["created_at"] = datetime.fromtimestamp(
|
70
|
-
_dict["created_at"]
|
71
|
-
)
|
72
|
-
except Exception:
|
73
|
-
pass
|
74
|
-
out_.append(_dict)
|
75
|
-
df = pd.DataFrame(out_, **kwargs)
|
76
|
-
# Convert created_at to datetime if present
|
77
|
-
if "created_at" in df.columns:
|
78
|
-
df["created_at"] = pd.to_datetime(
|
79
|
-
df["created_at"], errors="coerce"
|
80
|
-
)
|
81
|
-
return df
|
@@ -1,57 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Defines a `PandasSeriesAdapter` that converts a single object
|
3
|
-
to/from a `pd.Series`.
|
4
|
-
"""
|
5
|
-
|
6
|
-
import pandas as pd
|
7
|
-
|
8
|
-
from ..adapter import Adapter, T
|
9
|
-
|
10
|
-
|
11
|
-
class PandasSeriesAdapter(Adapter):
|
12
|
-
"""
|
13
|
-
Converts a single item to a Pandas Series and vice versa.
|
14
|
-
Great for 1-row data or simpler key-value pairs.
|
15
|
-
"""
|
16
|
-
|
17
|
-
obj_key = "pd_series"
|
18
|
-
alias = ("pandas_series", "pd.series", "pd_series")
|
19
|
-
|
20
|
-
@classmethod
|
21
|
-
def from_obj(cls, subj_cls: type[T], obj: pd.Series, /, **kwargs) -> dict:
|
22
|
-
"""
|
23
|
-
Convert a Pandas Series into a dictionary.
|
24
|
-
|
25
|
-
Parameters
|
26
|
-
----------
|
27
|
-
subj_cls : type[T]
|
28
|
-
Possibly the class we might use to rehydrate the item.
|
29
|
-
obj : pd.Series
|
30
|
-
The series to interpret.
|
31
|
-
**kwargs
|
32
|
-
Additional arguments for `Series.to_dict`.
|
33
|
-
|
34
|
-
Returns
|
35
|
-
-------
|
36
|
-
dict
|
37
|
-
The data from the Series as a dictionary.
|
38
|
-
"""
|
39
|
-
return obj.to_dict(**kwargs)
|
40
|
-
|
41
|
-
@classmethod
|
42
|
-
def to_obj(cls, subj: T, /, **kwargs) -> pd.Series:
|
43
|
-
"""
|
44
|
-
Convert a single item to a Series.
|
45
|
-
|
46
|
-
Parameters
|
47
|
-
----------
|
48
|
-
subj : T
|
49
|
-
The item, which must have `to_dict()`.
|
50
|
-
**kwargs
|
51
|
-
Extra args passed to `pd.Series`.
|
52
|
-
|
53
|
-
Returns
|
54
|
-
-------
|
55
|
-
pd.Series
|
56
|
-
"""
|
57
|
-
return pd.Series(subj.to_dict(), **kwargs)
|
lionagi/adapters/toml_adapter.py
DELETED
@@ -1,204 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Implements two adapters:
|
3
|
-
- `TomlAdapter` for in-memory TOML strings
|
4
|
-
- `TomlFileAdapter` for reading/writing TOML files
|
5
|
-
"""
|
6
|
-
|
7
|
-
import logging
|
8
|
-
from pathlib import Path
|
9
|
-
|
10
|
-
import toml
|
11
|
-
|
12
|
-
from lionagi.protocols._concepts import Collective
|
13
|
-
|
14
|
-
from .adapter import Adapter, T
|
15
|
-
|
16
|
-
|
17
|
-
class TomlAdapter(Adapter):
|
18
|
-
"""
|
19
|
-
Adapter that converts to/from TOML **strings** in memory.
|
20
|
-
Example usage: taking a Python dictionary and making TOML,
|
21
|
-
or parsing TOML string to a dict.
|
22
|
-
"""
|
23
|
-
|
24
|
-
obj_key = "toml"
|
25
|
-
|
26
|
-
@classmethod
|
27
|
-
def from_obj(
|
28
|
-
cls,
|
29
|
-
subj_cls: type[T],
|
30
|
-
obj: str,
|
31
|
-
/,
|
32
|
-
*,
|
33
|
-
many: bool = False,
|
34
|
-
**kwargs,
|
35
|
-
) -> dict | list[dict]:
|
36
|
-
"""
|
37
|
-
Convert a TOML string into a dict or list of dicts.
|
38
|
-
|
39
|
-
Parameters
|
40
|
-
----------
|
41
|
-
subj_cls : type[T]
|
42
|
-
The target class for context (not always used).
|
43
|
-
obj : str
|
44
|
-
The TOML string.
|
45
|
-
many : bool, optional
|
46
|
-
If True, expects a TOML array of tables (returns list[dict]).
|
47
|
-
Otherwise returns a single dict.
|
48
|
-
**kwargs
|
49
|
-
Extra arguments for toml.loads().
|
50
|
-
|
51
|
-
Returns
|
52
|
-
-------
|
53
|
-
dict | list[dict]
|
54
|
-
The loaded TOML data.
|
55
|
-
"""
|
56
|
-
result = toml.loads(obj, **kwargs)
|
57
|
-
|
58
|
-
# Handle array of tables in TOML for "many" case
|
59
|
-
if many:
|
60
|
-
# Check if there's a top-level array key that might hold multiple items
|
61
|
-
for key, value in result.items():
|
62
|
-
if isinstance(value, list) and all(
|
63
|
-
isinstance(item, dict) for item in value
|
64
|
-
):
|
65
|
-
return value
|
66
|
-
# If no array of tables found, wrap the result in a list
|
67
|
-
return [result]
|
68
|
-
|
69
|
-
return result
|
70
|
-
|
71
|
-
@classmethod
|
72
|
-
def to_obj(
|
73
|
-
cls,
|
74
|
-
subj: T,
|
75
|
-
*,
|
76
|
-
many: bool = False,
|
77
|
-
**kwargs,
|
78
|
-
) -> str:
|
79
|
-
"""
|
80
|
-
Convert an object (or collection) to a TOML string.
|
81
|
-
|
82
|
-
Parameters
|
83
|
-
----------
|
84
|
-
subj : T
|
85
|
-
The object to serialize.
|
86
|
-
many : bool, optional
|
87
|
-
If True, convert multiple items to a TOML array of tables.
|
88
|
-
**kwargs
|
89
|
-
Extra arguments for toml.dumps().
|
90
|
-
|
91
|
-
Returns
|
92
|
-
-------
|
93
|
-
str
|
94
|
-
The resulting TOML string.
|
95
|
-
"""
|
96
|
-
if many:
|
97
|
-
if isinstance(subj, Collective):
|
98
|
-
# For multiple items, create a wrapper dict with an array of items
|
99
|
-
data = {"items": [i.to_dict() for i in subj]}
|
100
|
-
else:
|
101
|
-
data = {"items": [subj.to_dict()]}
|
102
|
-
return toml.dumps(data, **kwargs)
|
103
|
-
|
104
|
-
return toml.dumps(subj.to_dict(), **kwargs)
|
105
|
-
|
106
|
-
|
107
|
-
class TomlFileAdapter(Adapter):
|
108
|
-
"""
|
109
|
-
Adapter that reads/writes TOML data to/from a file on disk.
|
110
|
-
The file extension key is ".toml".
|
111
|
-
"""
|
112
|
-
|
113
|
-
obj_key = ".toml"
|
114
|
-
|
115
|
-
@classmethod
|
116
|
-
def from_obj(
|
117
|
-
cls,
|
118
|
-
subj_cls: type[T],
|
119
|
-
obj: str | Path,
|
120
|
-
/,
|
121
|
-
*,
|
122
|
-
many: bool = False,
|
123
|
-
**kwargs,
|
124
|
-
) -> dict | list[dict]:
|
125
|
-
"""
|
126
|
-
Read a TOML file from disk and return a dict or list of dicts.
|
127
|
-
|
128
|
-
Parameters
|
129
|
-
----------
|
130
|
-
subj_cls : type[T]
|
131
|
-
The target class for context.
|
132
|
-
obj : str | Path
|
133
|
-
The TOML file path.
|
134
|
-
many : bool
|
135
|
-
If True, expects an array of tables. Otherwise single dict.
|
136
|
-
**kwargs
|
137
|
-
Extra arguments for toml.load().
|
138
|
-
|
139
|
-
Returns
|
140
|
-
-------
|
141
|
-
dict | list[dict]
|
142
|
-
The loaded data from file.
|
143
|
-
"""
|
144
|
-
with open(obj, encoding="utf-8") as f:
|
145
|
-
result = toml.load(f, **kwargs)
|
146
|
-
|
147
|
-
# Handle array of tables in TOML for "many" case
|
148
|
-
if many:
|
149
|
-
# Check if there's a top-level array key that might hold multiple items
|
150
|
-
for key, value in result.items():
|
151
|
-
if isinstance(value, list) and all(
|
152
|
-
isinstance(item, dict) for item in value
|
153
|
-
):
|
154
|
-
return value
|
155
|
-
# If no array of tables found, wrap the result in a list
|
156
|
-
return [result]
|
157
|
-
|
158
|
-
return result
|
159
|
-
|
160
|
-
@classmethod
|
161
|
-
def to_obj(
|
162
|
-
cls,
|
163
|
-
subj: T,
|
164
|
-
/,
|
165
|
-
*,
|
166
|
-
fp: str | Path,
|
167
|
-
many: bool = False,
|
168
|
-
mode: str = "w",
|
169
|
-
**kwargs,
|
170
|
-
) -> None:
|
171
|
-
"""
|
172
|
-
Write a dict (or list) to a TOML file.
|
173
|
-
|
174
|
-
Parameters
|
175
|
-
----------
|
176
|
-
subj : T
|
177
|
-
The object/collection to serialize.
|
178
|
-
fp : str | Path
|
179
|
-
The file path to write.
|
180
|
-
many : bool
|
181
|
-
If True, write as a TOML array of tables of multiple items.
|
182
|
-
mode : str
|
183
|
-
File open mode, defaults to write ("w").
|
184
|
-
**kwargs
|
185
|
-
Extra arguments for toml.dump().
|
186
|
-
|
187
|
-
Returns
|
188
|
-
-------
|
189
|
-
None
|
190
|
-
"""
|
191
|
-
with open(fp, mode, encoding="utf-8") as f:
|
192
|
-
if many:
|
193
|
-
if isinstance(subj, Collective):
|
194
|
-
# TOML requires arrays of tables to be in a table
|
195
|
-
data = {"items": [i.to_dict() for i in subj]}
|
196
|
-
else:
|
197
|
-
data = {"items": [subj.to_dict()]}
|
198
|
-
toml.dump(data, f, **kwargs)
|
199
|
-
else:
|
200
|
-
toml.dump(subj.to_dict(), f, **kwargs)
|
201
|
-
logging.info(f"TOML data saved to {fp}")
|
202
|
-
|
203
|
-
|
204
|
-
# File: lionagi/protocols/adapters/toml_adapter.py
|
lionagi/adapters/types.py
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
from .adapter import ADAPTER_MEMBERS, Adapter, AdapterRegistry
|
2
|
-
from .json_adapter import JsonAdapter, JsonFileAdapter
|
3
|
-
from .pandas_.csv_adapter import CSVFileAdapter
|
4
|
-
from .pandas_.excel_adapter import ExcelFileAdapter
|
5
|
-
from .pandas_.pd_dataframe_adapter import PandasDataFrameAdapter
|
6
|
-
from .pandas_.pd_series_adapter import PandasSeriesAdapter
|
7
|
-
from .toml_adapter import TomlAdapter, TomlFileAdapter
|
8
|
-
|
9
|
-
__all__ = (
|
10
|
-
"Adapter",
|
11
|
-
"AdapterRegistry",
|
12
|
-
"ADAPTER_MEMBERS",
|
13
|
-
"JsonAdapter",
|
14
|
-
"JsonFileAdapter",
|
15
|
-
"CSVFileAdapter",
|
16
|
-
"PandasSeriesAdapter",
|
17
|
-
"PandasDataFrameAdapter",
|
18
|
-
"ExcelFileAdapter",
|
19
|
-
"TomlAdapter",
|
20
|
-
"TomlFileAdapter",
|
21
|
-
)
|