lionagi 0.16.2__py3-none-any.whl → 0.17.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.
- lionagi/adapters/_utils.py +10 -23
- lionagi/adapters/async_postgres_adapter.py +83 -79
- lionagi/ln/__init__.py +4 -4
- lionagi/ln/_json_dump.py +0 -6
- 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/__init__.py +0 -6
- lionagi/operations/_visualize_graph.py +285 -0
- lionagi/operations/brainstorm/brainstorm.py +14 -12
- lionagi/operations/builder.py +23 -302
- lionagi/operations/communicate/communicate.py +1 -1
- lionagi/operations/flow.py +14 -11
- lionagi/operations/node.py +14 -3
- lionagi/operations/operate/operate.py +5 -11
- lionagi/operations/parse/parse.py +2 -3
- lionagi/operations/types.py +0 -2
- lionagi/operations/utils.py +11 -5
- lionagi/protocols/generic/pile.py +3 -7
- lionagi/protocols/graph/graph.py +23 -6
- lionagi/protocols/graph/node.py +0 -2
- lionagi/protocols/messages/message.py +0 -1
- lionagi/protocols/operatives/operative.py +2 -2
- lionagi/protocols/types.py +0 -15
- lionagi/service/connections/endpoint.py +11 -5
- 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 +24 -18
- lionagi/session/session.py +2 -18
- lionagi/utils.py +3 -335
- lionagi/version.py +1 -1
- {lionagi-0.16.2.dist-info → lionagi-0.17.0.dist-info}/METADATA +4 -13
- {lionagi-0.16.2.dist-info → lionagi-0.17.0.dist-info}/RECORD +39 -61
- lionagi/adapters/postgres_model_adapter.py +0 -131
- lionagi/libs/concurrency.py +0 -1
- 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/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 -387
- lionagi/protocols/graph/_utils.py +0 -22
- lionagi/service/connections/providers/claude_code_.py +0 -299
- {lionagi-0.16.2.dist-info → lionagi-0.17.0.dist-info}/WHEEL +0 -0
- {lionagi-0.16.2.dist-info → lionagi-0.17.0.dist-info}/licenses/LICENSE +0 -0
lionagi/operations/utils.py
CHANGED
@@ -2,18 +2,24 @@
|
|
2
2
|
#
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
4
4
|
|
5
|
+
from typing import TYPE_CHECKING
|
6
|
+
|
5
7
|
from lionagi.fields.instruct import Instruct
|
6
|
-
|
8
|
+
|
9
|
+
if TYPE_CHECKING:
|
10
|
+
from lionagi.session.session import Branch, Session
|
7
11
|
|
8
12
|
|
9
13
|
def prepare_session(
|
10
|
-
session: Session
|
11
|
-
branch: Branch
|
14
|
+
session: "Session" = None,
|
15
|
+
branch: "Branch" = None,
|
12
16
|
branch_kwargs=None,
|
13
|
-
) -> tuple[Session, Branch]:
|
17
|
+
) -> tuple["Session", "Branch"]:
|
18
|
+
from lionagi.session.session import Branch, Session
|
19
|
+
|
14
20
|
if session is not None:
|
15
21
|
if branch is not None:
|
16
|
-
branch: Branch = session.branches[branch]
|
22
|
+
branch: "Branch" = session.branches[branch]
|
17
23
|
else:
|
18
24
|
branch = session.new_branch(**(branch_kwargs or {}))
|
19
25
|
else:
|
@@ -18,14 +18,13 @@ from functools import wraps
|
|
18
18
|
from pathlib import Path
|
19
19
|
from typing import Any, ClassVar, Generic, Literal, TypeVar
|
20
20
|
|
21
|
-
import pandas as pd
|
22
21
|
from pydantic import Field, field_serializer
|
23
22
|
from pydantic.fields import FieldInfo
|
24
23
|
from pydapter import Adaptable, AsyncAdaptable
|
25
24
|
from typing_extensions import Self, deprecated, override
|
26
25
|
|
27
26
|
from lionagi._errors import ItemExistsError, ItemNotFoundError, ValidationError
|
28
|
-
from lionagi.
|
27
|
+
from lionagi.ln.concurrency import Lock as ConcurrencyLock
|
29
28
|
from lionagi.utils import (
|
30
29
|
UNDEFINED,
|
31
30
|
is_same_dtype,
|
@@ -1047,9 +1046,7 @@ class Pile(Element, Collective[T], Generic[T], Adaptable, AsyncAdaptable):
|
|
1047
1046
|
kw["adapt_meth"] = "from_dict"
|
1048
1047
|
return await super().adapt_from_async(obj, obj_key, many=many, **kw)
|
1049
1048
|
|
1050
|
-
def to_df(
|
1051
|
-
self, columns: list[str] | None = None, **kw: Any
|
1052
|
-
) -> pd.DataFrame:
|
1049
|
+
def to_df(self, columns: list[str] | None = None, **kw: Any):
|
1053
1050
|
"""Convert to DataFrame."""
|
1054
1051
|
from pydapter.extras.pandas_ import DataFrameAdapter
|
1055
1052
|
|
@@ -1207,11 +1204,10 @@ def to_list_type(value: Any, /) -> list[Any]:
|
|
1207
1204
|
|
1208
1205
|
if not _ADAPATER_REGISTERED:
|
1209
1206
|
from pydapter.adapters import CsvAdapter, JsonAdapter
|
1210
|
-
from pydapter.extras.pandas_ import DataFrameAdapter
|
1211
1207
|
|
1212
1208
|
Pile.register_adapter(CsvAdapter)
|
1213
1209
|
Pile.register_adapter(JsonAdapter)
|
1214
|
-
|
1210
|
+
|
1215
1211
|
_ADAPATER_REGISTERED = True
|
1216
1212
|
|
1217
1213
|
Pile = Pile
|
lionagi/protocols/graph/graph.py
CHANGED
@@ -19,10 +19,8 @@ from .node import Node
|
|
19
19
|
|
20
20
|
T = TypeVar("T", bound=Node)
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
_NETWORKX_AVAILABLE = check_networkx_available()
|
25
|
-
_MATPLIB_AVAILABLE = check_matplotlib_available()
|
22
|
+
_NETWORKX_AVAILABLE = None
|
23
|
+
_MATPLIB_AVAILABLE = None
|
26
24
|
__all__ = ("Graph",)
|
27
25
|
|
28
26
|
|
@@ -219,8 +217,17 @@ class Graph(Element, Relational, Generic[T]):
|
|
219
217
|
|
220
218
|
def to_networkx(self, **kwargs) -> Any:
|
221
219
|
"""Convert the graph to a NetworkX graph object."""
|
220
|
+
global _NETWORKX_AVAILABLE
|
221
|
+
if _NETWORKX_AVAILABLE is None:
|
222
|
+
from lionagi.ln import is_import_installed
|
223
|
+
|
224
|
+
_NETWORKX_AVAILABLE = is_import_installed("networkx")
|
225
|
+
|
222
226
|
if _NETWORKX_AVAILABLE is not True:
|
223
|
-
raise
|
227
|
+
raise ImportError(
|
228
|
+
"The 'networkx' package is required for this feature. "
|
229
|
+
"Please install `networkx` or `'lionagi[graph]'`."
|
230
|
+
)
|
224
231
|
|
225
232
|
from networkx import DiGraph # type: ignore
|
226
233
|
|
@@ -248,8 +255,18 @@ class Graph(Element, Relational, Generic[T]):
|
|
248
255
|
):
|
249
256
|
"""Display the graph using NetworkX and Matplotlib."""
|
250
257
|
g = self.to_networkx(**kwargs)
|
258
|
+
|
259
|
+
global _MATPLIB_AVAILABLE
|
260
|
+
if _MATPLIB_AVAILABLE is None:
|
261
|
+
from lionagi.ln import is_import_installed
|
262
|
+
|
263
|
+
_MATPLIB_AVAILABLE = is_import_installed("matplotlib")
|
264
|
+
|
251
265
|
if _MATPLIB_AVAILABLE is not True:
|
252
|
-
raise
|
266
|
+
raise ImportError(
|
267
|
+
"The 'matplotlib' package is required for this feature. "
|
268
|
+
"Please install `matplotlib` or `'lionagi[graph]'`."
|
269
|
+
)
|
253
270
|
|
254
271
|
import matplotlib.pyplot as plt # type: ignore
|
255
272
|
import networkx as nx # type: ignore
|
lionagi/protocols/graph/node.py
CHANGED
@@ -124,11 +124,9 @@ class Node(Element, Relational, AsyncAdaptable, Adaptable):
|
|
124
124
|
|
125
125
|
if not _ADAPATER_REGISTERED:
|
126
126
|
from pydapter.adapters import JsonAdapter, TomlAdapter
|
127
|
-
from pydapter.extras.pandas_ import SeriesAdapter
|
128
127
|
|
129
128
|
Node.register_adapter(JsonAdapter)
|
130
129
|
Node.register_adapter(TomlAdapter)
|
131
|
-
Node.register_adapter(SeriesAdapter)
|
132
130
|
|
133
131
|
from lionagi.adapters._utils import check_async_postgres_available
|
134
132
|
|
@@ -2,12 +2,12 @@
|
|
2
2
|
#
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
4
4
|
|
5
|
-
from typing import Any
|
5
|
+
from typing import Any
|
6
6
|
|
7
7
|
from pydantic import BaseModel
|
8
8
|
from pydantic.fields import FieldInfo
|
9
9
|
|
10
|
-
from lionagi.
|
10
|
+
from lionagi.ln.fuzzy._fuzzy_match import fuzzy_match_keys
|
11
11
|
from lionagi.models import FieldModel, ModelParams, OperableModel
|
12
12
|
from lionagi.utils import UNDEFINED, to_json
|
13
13
|
|
lionagi/protocols/types.py
CHANGED
@@ -5,10 +5,7 @@
|
|
5
5
|
from ._concepts import Collective, Communicatable, Condition, Manager
|
6
6
|
from ._concepts import Observable as LegacyObservable
|
7
7
|
from ._concepts import Observer, Ordering, Relational, Sendable
|
8
|
-
from .action.manager import ActionManager, FunctionCalling, Tool, ToolRef
|
9
8
|
from .contracts import Observable, ObservableProto
|
10
|
-
from .forms.flow import FlowDefinition, FlowStep
|
11
|
-
from .forms.report import BaseForm, Form, Report
|
12
9
|
from .generic.element import ID, Element, IDError, IDType, validate_order
|
13
10
|
from .generic.event import Event, EventStatus, Execution
|
14
11
|
from .generic.log import (
|
@@ -43,7 +40,6 @@ from .messages.manager import (
|
|
43
40
|
SenderRecipient,
|
44
41
|
System,
|
45
42
|
)
|
46
|
-
from .operatives.step import Operative, Step
|
47
43
|
|
48
44
|
__all__ = (
|
49
45
|
"Collective",
|
@@ -98,17 +94,6 @@ __all__ = (
|
|
98
94
|
"RoledMessage",
|
99
95
|
"SenderRecipient",
|
100
96
|
"System",
|
101
|
-
"FlowDefinition",
|
102
|
-
"FlowStep",
|
103
|
-
"BaseForm",
|
104
|
-
"Form",
|
105
|
-
"Report",
|
106
|
-
"Operative",
|
107
|
-
"Step",
|
108
|
-
"ActionManager",
|
109
|
-
"Tool",
|
110
|
-
"FunctionCalling",
|
111
|
-
"ToolRef",
|
112
97
|
"MailManager",
|
113
98
|
"DataLogger",
|
114
99
|
"DataLoggerConfig",
|
@@ -5,18 +5,13 @@
|
|
5
5
|
import asyncio
|
6
6
|
import logging
|
7
7
|
|
8
|
-
import aiohttp
|
9
|
-
import backoff
|
10
|
-
from aiocache import cached
|
11
8
|
from pydantic import BaseModel
|
12
9
|
|
13
|
-
from lionagi.config import settings
|
14
10
|
from lionagi.service.resilience import (
|
15
11
|
CircuitBreaker,
|
16
12
|
RetryConfig,
|
17
13
|
retry_with_backoff,
|
18
14
|
)
|
19
|
-
from lionagi.utils import to_dict
|
20
15
|
|
21
16
|
from .endpoint_config import EndpointConfig
|
22
17
|
from .header_factory import HeaderFactory
|
@@ -65,6 +60,8 @@ class Endpoint:
|
|
65
60
|
|
66
61
|
def _create_http_session(self):
|
67
62
|
"""Create a new HTTP session (not thread-safe, create new for each request)."""
|
63
|
+
import aiohttp
|
64
|
+
|
68
65
|
return aiohttp.ClientSession(
|
69
66
|
timeout=aiohttp.ClientTimeout(self.config.timeout),
|
70
67
|
**self.config.client_kwargs,
|
@@ -231,6 +228,9 @@ class Endpoint:
|
|
231
228
|
|
232
229
|
# Handle caching if requested
|
233
230
|
if cache_control:
|
231
|
+
from aiocache import cached
|
232
|
+
|
233
|
+
from lionagi.config import settings
|
234
234
|
|
235
235
|
@cached(**settings.aiocache_config.as_kwargs())
|
236
236
|
async def _cached_call(payload: dict, headers: dict, **kwargs):
|
@@ -268,6 +268,8 @@ class Endpoint:
|
|
268
268
|
Returns:
|
269
269
|
The response from the endpoint.
|
270
270
|
"""
|
271
|
+
import aiohttp
|
272
|
+
import backoff
|
271
273
|
|
272
274
|
async def _make_request_with_backoff():
|
273
275
|
# Create a new session for this request
|
@@ -382,6 +384,8 @@ class Endpoint:
|
|
382
384
|
**kwargs,
|
383
385
|
) as response:
|
384
386
|
if response.status != 200:
|
387
|
+
import aiohttp
|
388
|
+
|
385
389
|
raise aiohttp.ClientResponseError(
|
386
390
|
request_info=response.request_info,
|
387
391
|
history=response.history,
|
@@ -409,6 +413,8 @@ class Endpoint:
|
|
409
413
|
|
410
414
|
@classmethod
|
411
415
|
def from_dict(cls, data: dict):
|
416
|
+
from lionagi.utils import to_dict
|
417
|
+
|
412
418
|
data = to_dict(data, recursive=True)
|
413
419
|
retry_config = data.get("retry_config")
|
414
420
|
circuit_breaker = data.get("circuit_breaker")
|
@@ -57,17 +57,9 @@ def match_endpoint(
|
|
57
57
|
|
58
58
|
return NvidiaNimChatEndpoint(None, **kwargs)
|
59
59
|
if provider == "claude_code":
|
60
|
-
|
61
|
-
from .providers.claude_code_cli import ClaudeCodeCLIEndpoint
|
60
|
+
from .providers.claude_code_cli import ClaudeCodeCLIEndpoint
|
62
61
|
|
63
|
-
|
64
|
-
|
65
|
-
if "query" in endpoint or "code" in endpoint:
|
66
|
-
from lionagi.service.connections.providers.claude_code_ import (
|
67
|
-
ClaudeCodeEndpoint,
|
68
|
-
)
|
69
|
-
|
70
|
-
return ClaudeCodeEndpoint(None, **kwargs)
|
62
|
+
return ClaudeCodeCLIEndpoint(None, **kwargs)
|
71
63
|
|
72
64
|
from .providers.oai_ import OpenaiChatEndpoint
|
73
65
|
|
@@ -1,6 +1,5 @@
|
|
1
1
|
from .anthropic_ import AnthropicMessagesEndpoint
|
2
|
-
from .
|
3
|
-
from .claude_code_cli import ClaudeCodeCLIEndpoint
|
2
|
+
from .claude_code_cli import ClaudeCodeCLIEndpoint, ClaudeCodeRequest
|
4
3
|
from .exa_ import ExaSearchEndpoint, ExaSearchRequest
|
5
4
|
from .oai_ import (
|
6
5
|
GroqChatEndpoint,
|
@@ -14,7 +13,6 @@ from .perplexity_ import PerplexityChatEndpoint, PerplexityChatRequest
|
|
14
13
|
|
15
14
|
__all__ = (
|
16
15
|
"AnthropicMessagesEndpoint",
|
17
|
-
"ClaudeCodeEndpoint",
|
18
16
|
"ClaudeCodeRequest",
|
19
17
|
"ClaudeCodeCLIEndpoint",
|
20
18
|
"ExaSearchEndpoint",
|
@@ -8,7 +8,7 @@ from typing import Any
|
|
8
8
|
import anyio
|
9
9
|
from pydantic import Field, PrivateAttr
|
10
10
|
|
11
|
-
from lionagi.
|
11
|
+
from lionagi.ln.concurrency import fail_after, get_cancelled_exc_class
|
12
12
|
from lionagi.protocols.types import Event, EventStatus
|
13
13
|
|
14
14
|
from ._types import AssosiatedEventInfo, HookEventTypes
|
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|
5
5
|
|
6
6
|
from typing import Any, TypeVar
|
7
7
|
|
8
|
-
from lionagi.
|
8
|
+
from lionagi.ln.concurrency import get_cancelled_exc_class
|
9
9
|
from lionagi.protocols.types import Event, EventStatus
|
10
10
|
from lionagi.utils import UNDEFINED
|
11
11
|
|
@@ -8,7 +8,7 @@ from typing import Any
|
|
8
8
|
|
9
9
|
from typing_extensions import Self, override
|
10
10
|
|
11
|
-
from lionagi.
|
11
|
+
from lionagi.ln.concurrency import CapacityLimiter, Lock, move_on_after
|
12
12
|
from lionagi.protocols.types import Executor, Processor
|
13
13
|
|
14
14
|
from .connections.api_calling import APICalling
|
lionagi/session/branch.py
CHANGED
@@ -4,10 +4,8 @@
|
|
4
4
|
|
5
5
|
from collections.abc import AsyncGenerator, Callable
|
6
6
|
from enum import Enum
|
7
|
-
from typing import Any, Literal
|
7
|
+
from typing import TYPE_CHECKING, Any, Literal, Optional
|
8
8
|
|
9
|
-
import pandas as pd
|
10
|
-
from jinja2 import Template
|
11
9
|
from pydantic import BaseModel, Field, JsonValue, PrivateAttr, field_serializer
|
12
10
|
|
13
11
|
from lionagi.config import settings
|
@@ -15,11 +13,11 @@ from lionagi.fields import Instruct
|
|
15
13
|
from lionagi.libs.schema.as_readable import as_readable
|
16
14
|
from lionagi.models.field_model import FieldModel
|
17
15
|
from lionagi.operations.manager import OperationManager
|
16
|
+
from lionagi.protocols.action.manager import ActionManager
|
18
17
|
from lionagi.protocols.action.tool import FuncTool, Tool, ToolRef
|
19
18
|
from lionagi.protocols.types import (
|
20
19
|
ID,
|
21
20
|
MESSAGE_FIELDS,
|
22
|
-
ActionManager,
|
23
21
|
ActionRequest,
|
24
22
|
ActionResponse,
|
25
23
|
AssistantResponse,
|
@@ -34,8 +32,6 @@ from lionagi.protocols.types import (
|
|
34
32
|
Mailbox,
|
35
33
|
MessageManager,
|
36
34
|
MessageRole,
|
37
|
-
Operative,
|
38
|
-
Package,
|
39
35
|
PackageCategory,
|
40
36
|
Pile,
|
41
37
|
Progression,
|
@@ -54,6 +50,10 @@ from lionagi.utils import copy
|
|
54
50
|
|
55
51
|
from .prompts import LION_SYSTEM_MESSAGE
|
56
52
|
|
53
|
+
if TYPE_CHECKING:
|
54
|
+
from lionagi.protocols.operatives.operative import Operative
|
55
|
+
|
56
|
+
|
57
57
|
__all__ = ("Branch",)
|
58
58
|
|
59
59
|
|
@@ -117,18 +117,18 @@ class Branch(Element, Communicatable, Relational):
|
|
117
117
|
def __init__(
|
118
118
|
self,
|
119
119
|
*,
|
120
|
-
user: SenderRecipient = None,
|
120
|
+
user: "SenderRecipient" = None,
|
121
121
|
name: str | None = None,
|
122
122
|
messages: Pile[RoledMessage] = None, # message manager kwargs
|
123
123
|
system: System | JsonValue = None,
|
124
|
-
system_sender: SenderRecipient = None,
|
124
|
+
system_sender: "SenderRecipient" = None,
|
125
125
|
chat_model: iModel | dict = None, # iModelManager kwargs
|
126
126
|
parse_model: iModel | dict = None,
|
127
127
|
imodel: iModel = None, # deprecated, alias of chat_model
|
128
128
|
tools: FuncTool | list[FuncTool] = None, # ActionManager kwargs
|
129
129
|
log_config: LogManagerConfig | dict = None, # LogManager kwargs
|
130
130
|
system_datetime: bool | str = None,
|
131
|
-
system_template
|
131
|
+
system_template=None,
|
132
132
|
system_template_context: dict = None,
|
133
133
|
logs: Pile[Log] = None,
|
134
134
|
use_lion_system_message: bool = False,
|
@@ -163,7 +163,7 @@ class Branch(Element, Communicatable, Relational):
|
|
163
163
|
system_datetime (bool | str, optional):
|
164
164
|
Whether to include timestamps in system messages (True/False)
|
165
165
|
or a string format for datetime.
|
166
|
-
system_template (Template | str, optional):
|
166
|
+
system_template (jinja2.Template | str, optional):
|
167
167
|
Optional Jinja2 template for system messages.
|
168
168
|
system_template_context (dict, optional):
|
169
169
|
Context for rendering the system template.
|
@@ -177,6 +177,8 @@ class Branch(Element, Communicatable, Relational):
|
|
177
177
|
super().__init__(user=user, name=name, **kwargs)
|
178
178
|
|
179
179
|
# --- MessageManager ---
|
180
|
+
from lionagi.protocols.messages.manager import MessageManager
|
181
|
+
|
180
182
|
self._message_manager = MessageManager(messages=messages)
|
181
183
|
|
182
184
|
if any(
|
@@ -401,7 +403,7 @@ class Branch(Element, Communicatable, Relational):
|
|
401
403
|
# -------------------------------------------------------------------------
|
402
404
|
# Conversion / Serialization
|
403
405
|
# -------------------------------------------------------------------------
|
404
|
-
def to_df(self, *, progression: Progression = None)
|
406
|
+
def to_df(self, *, progression: Progression = None):
|
405
407
|
"""
|
406
408
|
Convert branch messages into a `pandas.DataFrame`.
|
407
409
|
|
@@ -412,6 +414,8 @@ class Branch(Element, Communicatable, Relational):
|
|
412
414
|
Returns:
|
413
415
|
pd.DataFrame: Each row represents a message, with columns defined by MESSAGE_FIELDS.
|
414
416
|
"""
|
417
|
+
from lionagi.protocols.generic.pile import Pile
|
418
|
+
|
415
419
|
if progression is None:
|
416
420
|
progression = self.msgs.progression
|
417
421
|
|
@@ -429,7 +433,7 @@ class Branch(Element, Communicatable, Relational):
|
|
429
433
|
def send(
|
430
434
|
self,
|
431
435
|
recipient: IDType,
|
432
|
-
category: PackageCategory
|
436
|
+
category: Optional["PackageCategory"],
|
433
437
|
item: Any,
|
434
438
|
request_source: IDType | None = None,
|
435
439
|
) -> None:
|
@@ -446,6 +450,8 @@ class Branch(Element, Communicatable, Relational):
|
|
446
450
|
request_source (IDType | None):
|
447
451
|
The ID that prompted or requested this send operation (optional).
|
448
452
|
"""
|
453
|
+
from lionagi.protocols.mail.package import Package
|
454
|
+
|
449
455
|
package = Package(
|
450
456
|
category=category,
|
451
457
|
item=item,
|
@@ -833,7 +839,7 @@ class Branch(Element, Communicatable, Relational):
|
|
833
839
|
] = "return_value",
|
834
840
|
max_retries: int = 3,
|
835
841
|
request_type: type[BaseModel] = None,
|
836
|
-
operative: Operative = None,
|
842
|
+
operative: "Operative" = None,
|
837
843
|
similarity_algo="jaro_winkler",
|
838
844
|
similarity_threshold: float = 0.85,
|
839
845
|
fuzzy_match: bool = True,
|
@@ -911,8 +917,8 @@ class Branch(Element, Communicatable, Relational):
|
|
911
917
|
instruction: Instruction | JsonValue = None,
|
912
918
|
guidance: JsonValue = None,
|
913
919
|
context: JsonValue = None,
|
914
|
-
sender: SenderRecipient = None,
|
915
|
-
recipient: SenderRecipient = None,
|
920
|
+
sender: "SenderRecipient" = None,
|
921
|
+
recipient: "SenderRecipient" = None,
|
916
922
|
progression: Progression = None,
|
917
923
|
chat_model: iModel = None,
|
918
924
|
invoke_actions: bool = True,
|
@@ -922,7 +928,7 @@ class Branch(Element, Communicatable, Relational):
|
|
922
928
|
parse_model: iModel = None,
|
923
929
|
skip_validation: bool = False,
|
924
930
|
tools: ToolRef = None,
|
925
|
-
operative: Operative = None,
|
931
|
+
operative: "Operative" = None,
|
926
932
|
response_format: type[
|
927
933
|
BaseModel
|
928
934
|
] = None, # alias of operative.request_type
|
@@ -1063,8 +1069,8 @@ class Branch(Element, Communicatable, Relational):
|
|
1063
1069
|
guidance: JsonValue = None,
|
1064
1070
|
context: JsonValue = None,
|
1065
1071
|
plain_content: str = None,
|
1066
|
-
sender: SenderRecipient = None,
|
1067
|
-
recipient: SenderRecipient = None,
|
1072
|
+
sender: "SenderRecipient" = None,
|
1073
|
+
recipient: "SenderRecipient" = None,
|
1068
1074
|
progression: ID.IDSeq = None,
|
1069
1075
|
response_format: type[BaseModel] = None,
|
1070
1076
|
request_fields: dict | list[str] = None,
|
lionagi/session/session.py
CHANGED
@@ -6,7 +6,6 @@ import contextlib
|
|
6
6
|
from collections.abc import Callable
|
7
7
|
from typing import Any
|
8
8
|
|
9
|
-
import pandas as pd
|
10
9
|
from pydantic import (
|
11
10
|
Field,
|
12
11
|
JsonValue,
|
@@ -19,7 +18,6 @@ from typing_extensions import Self
|
|
19
18
|
from lionagi.protocols.types import (
|
20
19
|
ID,
|
21
20
|
MESSAGE_FIELDS,
|
22
|
-
ActionManager,
|
23
21
|
Communicatable,
|
24
22
|
Exchange,
|
25
23
|
Graph,
|
@@ -33,13 +31,12 @@ from lionagi.protocols.types import (
|
|
33
31
|
RoledMessage,
|
34
32
|
SenderRecipient,
|
35
33
|
System,
|
36
|
-
Tool,
|
37
34
|
)
|
38
35
|
|
39
36
|
from .._errors import ItemNotFoundError
|
40
37
|
from ..ln import lcall
|
41
38
|
from ..service.imodel import iModel
|
42
|
-
from .branch import Branch, OperationManager
|
39
|
+
from .branch import ActionManager, Branch, OperationManager, Tool
|
43
40
|
|
44
41
|
|
45
42
|
class Session(Node, Communicatable, Relational):
|
@@ -257,7 +254,7 @@ class Session(Node, Communicatable, Relational):
|
|
257
254
|
branches: ID.RefSeq = None,
|
258
255
|
exclude_clone: bool = False,
|
259
256
|
exlcude_load: bool = False,
|
260
|
-
)
|
257
|
+
):
|
261
258
|
out = self.concat_messages(
|
262
259
|
branches=branches,
|
263
260
|
exclude_clone=exclude_clone,
|
@@ -298,19 +295,6 @@ class Session(Node, Communicatable, Relational):
|
|
298
295
|
collections=messages, item_type={RoledMessage}, strict_type=False
|
299
296
|
)
|
300
297
|
|
301
|
-
def to_df(
|
302
|
-
self,
|
303
|
-
branches: ID.RefSeq = None,
|
304
|
-
exclude_clone: bool = False,
|
305
|
-
exclude_load: bool = False,
|
306
|
-
) -> pd.DataFrame:
|
307
|
-
out = self.concat_messages(
|
308
|
-
branches=branches,
|
309
|
-
exclude_clone=exclude_clone,
|
310
|
-
exclude_load=exclude_load,
|
311
|
-
)
|
312
|
-
return out.to_df(columns=MESSAGE_FIELDS)
|
313
|
-
|
314
298
|
def send(self, to_: ID.RefSeq = None):
|
315
299
|
"""
|
316
300
|
Send mail to specified branches.
|