lionagi 0.6.0__py3-none-any.whl → 0.7.0__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.
Files changed (70) hide show
  1. lionagi/__init__.py +2 -0
  2. lionagi/libs/token_transform/__init__.py +0 -0
  3. lionagi/libs/token_transform/llmlingua.py +1 -0
  4. lionagi/libs/token_transform/perplexity.py +439 -0
  5. lionagi/libs/token_transform/synthlang.py +409 -0
  6. lionagi/operations/ReAct/ReAct.py +126 -0
  7. lionagi/operations/ReAct/utils.py +28 -0
  8. lionagi/operations/__init__.py +1 -9
  9. lionagi/operations/_act/act.py +73 -0
  10. lionagi/operations/chat/__init__.py +3 -0
  11. lionagi/operations/chat/chat.py +173 -0
  12. lionagi/operations/communicate/__init__.py +0 -0
  13. lionagi/operations/communicate/communicate.py +167 -0
  14. lionagi/operations/instruct/__init__.py +3 -0
  15. lionagi/operations/instruct/instruct.py +29 -0
  16. lionagi/operations/interpret/__init__.py +3 -0
  17. lionagi/operations/interpret/interpret.py +40 -0
  18. lionagi/operations/operate/__init__.py +3 -0
  19. lionagi/operations/operate/operate.py +189 -0
  20. lionagi/operations/parse/__init__.py +3 -0
  21. lionagi/operations/parse/parse.py +125 -0
  22. lionagi/operations/plan/plan.py +3 -3
  23. lionagi/operations/select/__init__.py +0 -4
  24. lionagi/operations/select/select.py +11 -30
  25. lionagi/operations/select/utils.py +13 -2
  26. lionagi/operations/translate/__init__.py +0 -0
  27. lionagi/operations/translate/translate.py +47 -0
  28. lionagi/operations/types.py +25 -3
  29. lionagi/operatives/action/function_calling.py +1 -1
  30. lionagi/operatives/action/manager.py +22 -26
  31. lionagi/operatives/action/tool.py +1 -1
  32. lionagi/operatives/strategies/__init__.py +3 -0
  33. lionagi/{operations → operatives}/strategies/params.py +18 -2
  34. lionagi/protocols/adapters/__init__.py +0 -0
  35. lionagi/protocols/adapters/adapter.py +95 -0
  36. lionagi/protocols/adapters/json_adapter.py +101 -0
  37. lionagi/protocols/adapters/pandas_/__init__.py +0 -0
  38. lionagi/protocols/adapters/pandas_/csv_adapter.py +50 -0
  39. lionagi/protocols/adapters/pandas_/excel_adapter.py +52 -0
  40. lionagi/protocols/adapters/pandas_/pd_dataframe_adapter.py +31 -0
  41. lionagi/protocols/adapters/pandas_/pd_series_adapter.py +17 -0
  42. lionagi/protocols/adapters/types.py +18 -0
  43. lionagi/protocols/generic/pile.py +22 -1
  44. lionagi/protocols/graph/node.py +17 -1
  45. lionagi/protocols/types.py +3 -3
  46. lionagi/service/__init__.py +1 -14
  47. lionagi/service/endpoints/base.py +1 -1
  48. lionagi/service/endpoints/rate_limited_processor.py +2 -1
  49. lionagi/service/manager.py +1 -1
  50. lionagi/service/types.py +18 -0
  51. lionagi/session/branch.py +1098 -929
  52. lionagi/version.py +1 -1
  53. {lionagi-0.6.0.dist-info → lionagi-0.7.0.dist-info}/METADATA +4 -4
  54. {lionagi-0.6.0.dist-info → lionagi-0.7.0.dist-info}/RECORD +66 -38
  55. lionagi/libs/compress/models.py +0 -66
  56. lionagi/libs/compress/utils.py +0 -69
  57. lionagi/operations/select/prompt.py +0 -5
  58. lionagi/protocols/_adapter.py +0 -224
  59. /lionagi/{libs/compress → operations/ReAct}/__init__.py +0 -0
  60. /lionagi/operations/{strategies → _act}/__init__.py +0 -0
  61. /lionagi/{operations → operatives}/strategies/base.py +0 -0
  62. /lionagi/{operations → operatives}/strategies/concurrent.py +0 -0
  63. /lionagi/{operations → operatives}/strategies/concurrent_chunk.py +0 -0
  64. /lionagi/{operations → operatives}/strategies/concurrent_sequential_chunk.py +0 -0
  65. /lionagi/{operations → operatives}/strategies/sequential.py +0 -0
  66. /lionagi/{operations → operatives}/strategies/sequential_chunk.py +0 -0
  67. /lionagi/{operations → operatives}/strategies/sequential_concurrent_chunk.py +0 -0
  68. /lionagi/{operations → operatives}/strategies/utils.py +0 -0
  69. {lionagi-0.6.0.dist-info → lionagi-0.7.0.dist-info}/WHEEL +0 -0
  70. {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",
@@ -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
 
@@ -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
  )
@@ -1,14 +1 @@
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 .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.types import Event, EventStatus
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
@@ -8,7 +8,8 @@ from typing import Self
8
8
 
9
9
  from typing_extensions import override
10
10
 
11
- from ...protocols.types import Executor, Processor
11
+ from lionagi.protocols.generic.processor import Executor, Processor
12
+
12
13
  from .base import APICalling
13
14
 
14
15
  __all__ = (
@@ -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
 
@@ -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
+ )