lionagi 0.6.0__py3-none-any.whl → 0.7.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- lionagi/__init__.py +2 -0
- lionagi/libs/token_transform/__init__.py +0 -0
- lionagi/libs/token_transform/llmlingua.py +1 -0
- lionagi/libs/token_transform/perplexity.py +439 -0
- lionagi/libs/token_transform/synthlang.py +409 -0
- lionagi/operations/ReAct/ReAct.py +126 -0
- lionagi/operations/ReAct/utils.py +28 -0
- lionagi/operations/__init__.py +1 -9
- lionagi/operations/_act/act.py +73 -0
- lionagi/operations/chat/__init__.py +3 -0
- lionagi/operations/chat/chat.py +173 -0
- lionagi/operations/communicate/__init__.py +0 -0
- lionagi/operations/communicate/communicate.py +167 -0
- lionagi/operations/instruct/__init__.py +3 -0
- lionagi/operations/instruct/instruct.py +29 -0
- lionagi/operations/interpret/__init__.py +3 -0
- lionagi/operations/interpret/interpret.py +40 -0
- lionagi/operations/operate/__init__.py +3 -0
- lionagi/operations/operate/operate.py +189 -0
- lionagi/operations/parse/__init__.py +3 -0
- lionagi/operations/parse/parse.py +125 -0
- lionagi/operations/plan/plan.py +3 -3
- lionagi/operations/select/__init__.py +0 -4
- lionagi/operations/select/select.py +11 -30
- lionagi/operations/select/utils.py +13 -2
- lionagi/operations/translate/__init__.py +0 -0
- lionagi/operations/translate/translate.py +47 -0
- lionagi/operations/types.py +25 -3
- lionagi/operatives/action/function_calling.py +1 -1
- lionagi/operatives/action/manager.py +22 -26
- lionagi/operatives/action/tool.py +1 -1
- lionagi/operatives/strategies/__init__.py +3 -0
- lionagi/{operations → operatives}/strategies/params.py +18 -2
- lionagi/protocols/adapters/__init__.py +0 -0
- lionagi/protocols/adapters/adapter.py +95 -0
- lionagi/protocols/adapters/json_adapter.py +101 -0
- lionagi/protocols/adapters/pandas_/__init__.py +0 -0
- lionagi/protocols/adapters/pandas_/csv_adapter.py +50 -0
- lionagi/protocols/adapters/pandas_/excel_adapter.py +52 -0
- lionagi/protocols/adapters/pandas_/pd_dataframe_adapter.py +31 -0
- lionagi/protocols/adapters/pandas_/pd_series_adapter.py +17 -0
- lionagi/protocols/adapters/types.py +18 -0
- lionagi/protocols/generic/pile.py +22 -1
- lionagi/protocols/graph/node.py +17 -1
- lionagi/protocols/types.py +3 -3
- lionagi/service/__init__.py +1 -14
- lionagi/service/endpoints/base.py +1 -1
- lionagi/service/endpoints/rate_limited_processor.py +2 -1
- lionagi/service/manager.py +1 -1
- lionagi/service/types.py +18 -0
- lionagi/session/branch.py +1098 -929
- lionagi/version.py +1 -1
- {lionagi-0.6.0.dist-info → lionagi-0.7.0.dist-info}/METADATA +4 -4
- {lionagi-0.6.0.dist-info → lionagi-0.7.0.dist-info}/RECORD +66 -38
- lionagi/libs/compress/models.py +0 -66
- lionagi/libs/compress/utils.py +0 -69
- lionagi/operations/select/prompt.py +0 -5
- lionagi/protocols/_adapter.py +0 -224
- /lionagi/{libs/compress → operations/ReAct}/__init__.py +0 -0
- /lionagi/operations/{strategies → _act}/__init__.py +0 -0
- /lionagi/{operations → operatives}/strategies/base.py +0 -0
- /lionagi/{operations → operatives}/strategies/concurrent.py +0 -0
- /lionagi/{operations → operatives}/strategies/concurrent_chunk.py +0 -0
- /lionagi/{operations → operatives}/strategies/concurrent_sequential_chunk.py +0 -0
- /lionagi/{operations → operatives}/strategies/sequential.py +0 -0
- /lionagi/{operations → operatives}/strategies/sequential_chunk.py +0 -0
- /lionagi/{operations → operatives}/strategies/sequential_concurrent_chunk.py +0 -0
- /lionagi/{operations → operatives}/strategies/utils.py +0 -0
- {lionagi-0.6.0.dist-info → lionagi-0.7.0.dist-info}/WHEEL +0 -0
- {lionagi-0.6.0.dist-info → lionagi-0.7.0.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
import logging
|
2
|
+
from pathlib import Path
|
3
|
+
|
4
|
+
import pandas as pd
|
5
|
+
|
6
|
+
from lionagi.protocols._concepts import Collective
|
7
|
+
|
8
|
+
from ..adapter import Adapter, T
|
9
|
+
|
10
|
+
|
11
|
+
class CSVFileAdapter(Adapter):
|
12
|
+
obj_key = ".csv"
|
13
|
+
|
14
|
+
@classmethod
|
15
|
+
def from_obj(
|
16
|
+
cls,
|
17
|
+
subj_cls: type[T],
|
18
|
+
obj: str | Path,
|
19
|
+
/,
|
20
|
+
*,
|
21
|
+
many: bool = False,
|
22
|
+
**kwargs,
|
23
|
+
) -> list[dict]:
|
24
|
+
"""kwargs for pd.read_csv"""
|
25
|
+
df: pd.DataFrame = pd.read_csv(obj, **kwargs)
|
26
|
+
dicts_ = df.to_dict(orient="records")
|
27
|
+
return dicts_[0] if not many else dicts_
|
28
|
+
|
29
|
+
@classmethod
|
30
|
+
def to_obj(
|
31
|
+
cls,
|
32
|
+
subj: T,
|
33
|
+
/,
|
34
|
+
*,
|
35
|
+
fp: str | Path,
|
36
|
+
many: bool = False,
|
37
|
+
**kwargs,
|
38
|
+
):
|
39
|
+
"""kwargs for pd.DataFrame.to_csv"""
|
40
|
+
kwargs["index"] = False
|
41
|
+
if many:
|
42
|
+
if isinstance(subj, Collective):
|
43
|
+
pd.DataFrame([i.to_dict() for i in subj]).to_csv(fp, **kwargs)
|
44
|
+
logging.info(f"Successfully saved data to {fp}")
|
45
|
+
return
|
46
|
+
pd.DataFrame([subj.to_dict()]).to_csv(fp, **kwargs)
|
47
|
+
logging.info(f"Successfully saved data to {fp}")
|
48
|
+
return
|
49
|
+
pd.DataFrame([subj.to_dict()]).to_csv(fp, **kwargs)
|
50
|
+
logging.info(f"Successfully saved data to {fp}")
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import logging
|
2
|
+
from pathlib import Path
|
3
|
+
|
4
|
+
import pandas as pd
|
5
|
+
|
6
|
+
from lionagi.protocols._concepts import Collective
|
7
|
+
|
8
|
+
from ..adapter import Adapter, T
|
9
|
+
|
10
|
+
|
11
|
+
class ExcelFileAdapter(Adapter):
|
12
|
+
obj_key = ".xlsx"
|
13
|
+
|
14
|
+
@classmethod
|
15
|
+
def from_obj(
|
16
|
+
cls,
|
17
|
+
subj_cls: type[T],
|
18
|
+
obj: str | Path,
|
19
|
+
/,
|
20
|
+
*,
|
21
|
+
many: bool = False,
|
22
|
+
**kwargs,
|
23
|
+
) -> list[dict]:
|
24
|
+
"""kwargs for pd.read_csv"""
|
25
|
+
df: pd.DataFrame = pd.read_excel(obj, **kwargs)
|
26
|
+
dicts_ = df.to_dict(orient="records")
|
27
|
+
return dicts_[0] if not many else dicts_
|
28
|
+
|
29
|
+
@classmethod
|
30
|
+
def to_obj(
|
31
|
+
cls,
|
32
|
+
subj: T,
|
33
|
+
/,
|
34
|
+
*,
|
35
|
+
fp: str | Path,
|
36
|
+
many: bool = False,
|
37
|
+
**kwargs,
|
38
|
+
):
|
39
|
+
"""kwargs for pd.DataFrame.to_csv"""
|
40
|
+
kwargs["index"] = False
|
41
|
+
if many:
|
42
|
+
if isinstance(subj, Collective):
|
43
|
+
pd.DataFrame([i.to_dict() for i in subj]).to_excel(
|
44
|
+
fp, **kwargs
|
45
|
+
)
|
46
|
+
logging.info(f"Successfully saved data to {fp}")
|
47
|
+
return
|
48
|
+
pd.DataFrame([subj.to_dict()]).to_excel(fp, **kwargs)
|
49
|
+
logging.info(f"Successfully saved data to {fp}")
|
50
|
+
return
|
51
|
+
pd.DataFrame([subj.to_dict()]).to_excel(fp, **kwargs)
|
52
|
+
logging.info(f"Successfully saved data to {fp}")
|
@@ -0,0 +1,31 @@
|
|
1
|
+
from datetime import datetime
|
2
|
+
|
3
|
+
import pandas as pd
|
4
|
+
|
5
|
+
from ..adapter import Adapter, T
|
6
|
+
|
7
|
+
|
8
|
+
class PandasDataFrameAdapter(Adapter):
|
9
|
+
|
10
|
+
obj_key = "pd_dataframe"
|
11
|
+
alias = ("pandas_dataframe", "pd.DataFrame", "pd_dataframe")
|
12
|
+
|
13
|
+
@classmethod
|
14
|
+
def from_obj(
|
15
|
+
cls, subj_cls: type[T], obj: pd.DataFrame, /, **kwargs
|
16
|
+
) -> list[dict]:
|
17
|
+
"""kwargs for pd.DataFrame.to_dict"""
|
18
|
+
return obj.to_dict(orient="records", **kwargs)
|
19
|
+
|
20
|
+
@classmethod
|
21
|
+
def to_obj(cls, subj: list[T], /, **kwargs) -> pd.DataFrame:
|
22
|
+
"""kwargs for pd.DataFrame"""
|
23
|
+
out_ = []
|
24
|
+
for i in subj:
|
25
|
+
_dict = i.to_dict()
|
26
|
+
_dict["created_at"] = datetime.fromtimestamp(_dict["created_at"])
|
27
|
+
out_.append(_dict)
|
28
|
+
df = pd.DataFrame(out_, **kwargs)
|
29
|
+
if "created_at" in df.columns:
|
30
|
+
df["created_at"] = pd.to_datetime(df["created_at"])
|
31
|
+
return df
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import pandas as pd
|
2
|
+
|
3
|
+
from ..adapter import Adapter, T
|
4
|
+
|
5
|
+
|
6
|
+
class PandasSeriesAdapter(Adapter):
|
7
|
+
|
8
|
+
obj_key = "pd_series"
|
9
|
+
alias = ("pandas_series", "pd.series", "pd_series")
|
10
|
+
|
11
|
+
@classmethod
|
12
|
+
def from_obj(cls, subj_cls: type[T], obj: pd.Series, /, **kwargs) -> dict:
|
13
|
+
return obj.to_dict(**kwargs)
|
14
|
+
|
15
|
+
@classmethod
|
16
|
+
def to_obj(cls, subj: T, /, **kwargs) -> pd.Series:
|
17
|
+
return pd.Series(subj.to_dict(), **kwargs)
|
@@ -0,0 +1,18 @@
|
|
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
|
+
|
8
|
+
__all__ = (
|
9
|
+
"Adapter",
|
10
|
+
"AdapterRegistry",
|
11
|
+
"ADAPTER_MEMBERS",
|
12
|
+
"JsonAdapter",
|
13
|
+
"JsonFileAdapter",
|
14
|
+
"CSVFileAdapter",
|
15
|
+
"PandasSeriesAdapter",
|
16
|
+
"PandasDataFrameAdapter",
|
17
|
+
"ExcelFileAdapter",
|
18
|
+
)
|
@@ -27,8 +27,12 @@ from typing_extensions import override
|
|
27
27
|
from lionagi._errors import ItemExistsError, ItemNotFoundError
|
28
28
|
from lionagi.utils import UNDEFINED, is_same_dtype, to_list
|
29
29
|
|
30
|
-
from .._adapter import Adapter, AdapterRegistry, PileAdapterRegistry
|
31
30
|
from .._concepts import Observable
|
31
|
+
from ..adapters.adapter import Adapter, AdapterRegistry
|
32
|
+
from ..adapters.json_adapter import JsonAdapter, JsonFileAdapter
|
33
|
+
from ..adapters.pandas_.csv_adapter import CSVFileAdapter
|
34
|
+
from ..adapters.pandas_.excel_adapter import ExcelFileAdapter
|
35
|
+
from ..adapters.pandas_.pd_dataframe_adapter import PandasDataFrameAdapter
|
32
36
|
from .element import ID, Collective, E, Element, IDType, validate_order
|
33
37
|
from .progression import Progression
|
34
38
|
|
@@ -36,6 +40,23 @@ D = TypeVar("D")
|
|
36
40
|
T = TypeVar("T", bound=E)
|
37
41
|
|
38
42
|
|
43
|
+
PILE_DEFAULT_ADAPTERS = (
|
44
|
+
JsonAdapter,
|
45
|
+
JsonFileAdapter,
|
46
|
+
CSVFileAdapter,
|
47
|
+
ExcelFileAdapter,
|
48
|
+
PandasDataFrameAdapter,
|
49
|
+
)
|
50
|
+
|
51
|
+
|
52
|
+
class PileAdapterRegistry(AdapterRegistry):
|
53
|
+
pass
|
54
|
+
|
55
|
+
|
56
|
+
for i in PILE_DEFAULT_ADAPTERS:
|
57
|
+
PileAdapterRegistry.register(i)
|
58
|
+
|
59
|
+
|
39
60
|
__all__ = (
|
40
61
|
"Pile",
|
41
62
|
"pile",
|
lionagi/protocols/graph/node.py
CHANGED
@@ -9,10 +9,26 @@ from pydantic import field_validator
|
|
9
9
|
|
10
10
|
from lionagi._class_registry import LION_CLASS_REGISTRY
|
11
11
|
|
12
|
-
from .._adapter import AdapterRegistry, NodeAdapterRegistry
|
13
12
|
from .._concepts import Relational
|
13
|
+
from ..adapters.adapter import AdapterRegistry
|
14
|
+
from ..adapters.json_adapter import JsonAdapter, JsonFileAdapter
|
15
|
+
from ..adapters.pandas_.pd_series_adapter import PandasSeriesAdapter
|
14
16
|
from ..generic.element import Element
|
15
17
|
|
18
|
+
NODE_DEFAULT_ADAPTERS = (
|
19
|
+
JsonAdapter,
|
20
|
+
JsonFileAdapter,
|
21
|
+
PandasSeriesAdapter,
|
22
|
+
)
|
23
|
+
|
24
|
+
|
25
|
+
class NodeAdapterRegistry(AdapterRegistry):
|
26
|
+
pass
|
27
|
+
|
28
|
+
|
29
|
+
for i in NODE_DEFAULT_ADAPTERS:
|
30
|
+
NodeAdapterRegistry.register(i)
|
31
|
+
|
16
32
|
__all__ = ("Node",)
|
17
33
|
|
18
34
|
|
lionagi/protocols/types.py
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
#
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
4
4
|
|
5
|
-
from ._adapter import Adapter, AdapterRegistry
|
6
5
|
from ._concepts import (
|
7
6
|
Collective,
|
8
7
|
Communicatable,
|
@@ -14,6 +13,7 @@ from ._concepts import (
|
|
14
13
|
Relational,
|
15
14
|
Sendable,
|
16
15
|
)
|
16
|
+
from .adapters.adapter import Adapter, AdapterRegistry
|
17
17
|
from .generic.element import ID, Element, IDError, IDType, validate_order
|
18
18
|
from .generic.event import Event, EventStatus, Execution
|
19
19
|
from .generic.log import Log, LogManager, LogManagerConfig
|
@@ -89,8 +89,8 @@ __all__ = (
|
|
89
89
|
"MessageField",
|
90
90
|
"MESSAGE_FIELDS",
|
91
91
|
"validate_sender_recipient",
|
92
|
-
"Adapter",
|
93
|
-
"AdapterRegistry",
|
94
92
|
"MessageManager",
|
95
93
|
"to_list_type",
|
94
|
+
"Adapter",
|
95
|
+
"AdapterRegistry",
|
96
96
|
)
|
lionagi/service/__init__.py
CHANGED
@@ -1,14 +1 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# SPDX-License-Identifier: Apache-2.0
|
4
|
-
|
5
|
-
from .endpoints.base import APICalling, EndPoint
|
6
|
-
from .imodel import iModel
|
7
|
-
from .manager import iModelManager
|
8
|
-
|
9
|
-
__all__ = (
|
10
|
-
"iModel",
|
11
|
-
"iModelManager",
|
12
|
-
"EndPoint",
|
13
|
-
"APICalling",
|
14
|
-
)
|
1
|
+
from .types import *
|
@@ -12,7 +12,7 @@ from aiocache import cached
|
|
12
12
|
from pydantic import BaseModel, ConfigDict, Field
|
13
13
|
|
14
14
|
from lionagi._errors import ExecutionError, RateLimitError
|
15
|
-
from lionagi.protocols.
|
15
|
+
from lionagi.protocols.generic.event import Event, EventStatus
|
16
16
|
from lionagi.settings import Settings
|
17
17
|
|
18
18
|
from .token_calculator import TokenCalculator
|
lionagi/service/manager.py
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
#
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
4
4
|
|
5
|
+
from lionagi.protocols._concepts import Manager
|
5
6
|
from lionagi.utils import is_same_dtype
|
6
7
|
|
7
|
-
from ..protocols._concepts import Manager
|
8
8
|
from .endpoints.chat_completion import ChatCompletionEndPoint
|
9
9
|
from .imodel import iModel
|
10
10
|
|
lionagi/service/types.py
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Copyright (c) 2023 - 2024, HaiyangLi <quantocean.li at gmail dot com>
|
2
|
+
#
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
4
|
+
|
5
|
+
from .endpoints.base import APICalling, EndPoint
|
6
|
+
from .endpoints.rate_limited_processor import RateLimitedAPIExecutor
|
7
|
+
from .endpoints.token_calculator import TokenCalculator
|
8
|
+
from .imodel import iModel
|
9
|
+
from .manager import iModelManager
|
10
|
+
|
11
|
+
__all__ = (
|
12
|
+
"APICalling",
|
13
|
+
"EndPoint",
|
14
|
+
"RateLimitedAPIExecutor",
|
15
|
+
"TokenCalculator",
|
16
|
+
"iModel",
|
17
|
+
"iModelManager",
|
18
|
+
)
|