lionagi 0.14.11__py3-none-any.whl → 0.15.1__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/libs/concurrency.py +1 -0
- lionagi/libs/token_transform/perplexity.py +2 -1
- lionagi/libs/token_transform/symbolic_compress_context.py +8 -7
- lionagi/ln/__init__.py +49 -0
- lionagi/ln/_async_call.py +294 -0
- lionagi/ln/_list_call.py +130 -0
- lionagi/ln/_models.py +126 -0
- lionagi/ln/_to_list.py +176 -0
- lionagi/ln/_types.py +146 -0
- lionagi/{libs → ln}/concurrency/__init__.py +4 -2
- lionagi/ln/concurrency/utils.py +15 -0
- lionagi/models/hashable_model.py +1 -2
- lionagi/operations/brainstorm/brainstorm.py +2 -1
- lionagi/operations/flow.py +3 -3
- lionagi/operations/manager.py +10 -8
- lionagi/operations/node.py +2 -3
- lionagi/operations/plan/plan.py +3 -3
- lionagi/protocols/generic/event.py +47 -6
- lionagi/protocols/generic/pile.py +1 -1
- lionagi/service/hooks/_types.py +2 -2
- lionagi/session/branch.py +14 -3
- lionagi/session/session.py +55 -25
- lionagi/utils.py +90 -510
- lionagi/version.py +1 -1
- {lionagi-0.14.11.dist-info → lionagi-0.15.1.dist-info}/METADATA +4 -4
- {lionagi-0.14.11.dist-info → lionagi-0.15.1.dist-info}/RECORD +36 -30
- lionagi/libs/hash/__init__.py +0 -3
- lionagi/libs/hash/manager.py +0 -26
- /lionagi/{libs/hash/hash_dict.py → ln/_hash.py} +0 -0
- /lionagi/{libs → ln}/concurrency/cancel.py +0 -0
- /lionagi/{libs → ln}/concurrency/errors.py +0 -0
- /lionagi/{libs → ln}/concurrency/patterns.py +0 -0
- /lionagi/{libs → ln}/concurrency/primitives.py +0 -0
- /lionagi/{libs → ln}/concurrency/resource_tracker.py +0 -0
- /lionagi/{libs → ln}/concurrency/task.py +0 -0
- /lionagi/{libs → ln}/concurrency/throttle.py +0 -0
- {lionagi-0.14.11.dist-info → lionagi-0.15.1.dist-info}/WHEEL +0 -0
- {lionagi-0.14.11.dist-info → lionagi-0.15.1.dist-info}/licenses/LICENSE +0 -0
lionagi/session/session.py
CHANGED
@@ -7,7 +7,7 @@ from collections.abc import Callable
|
|
7
7
|
from typing import Any
|
8
8
|
|
9
9
|
import pandas as pd
|
10
|
-
from pydantic import Field, JsonValue, model_validator
|
10
|
+
from pydantic import Field, JsonValue, PrivateAttr, model_validator
|
11
11
|
from typing_extensions import Self
|
12
12
|
|
13
13
|
from lionagi.protocols.types import (
|
@@ -31,9 +31,9 @@ from lionagi.protocols.types import (
|
|
31
31
|
)
|
32
32
|
|
33
33
|
from .._errors import ItemNotFoundError
|
34
|
+
from ..ln import lcall
|
34
35
|
from ..service.imodel import iModel
|
35
|
-
from
|
36
|
-
from .branch import Branch
|
36
|
+
from .branch import Branch, OperationManager
|
37
37
|
|
38
38
|
|
39
39
|
class Session(Node, Communicatable, Relational):
|
@@ -56,6 +56,35 @@ class Session(Node, Communicatable, Relational):
|
|
56
56
|
default_factory=MailManager, exclude=True
|
57
57
|
)
|
58
58
|
name: str = Field(default="Session")
|
59
|
+
user: SenderRecipient | None = None
|
60
|
+
_operation_manager: OperationManager = PrivateAttr(
|
61
|
+
default_factory=OperationManager
|
62
|
+
)
|
63
|
+
|
64
|
+
async def ainclude_branches(self, branches: ID[Branch].ItemSeq):
|
65
|
+
async with self.branches:
|
66
|
+
self.include_branches(branches)
|
67
|
+
|
68
|
+
def include_branches(self, branches: ID[Branch].ItemSeq):
|
69
|
+
def _take_in_branch(branch: Branch):
|
70
|
+
if not branch in self.branches:
|
71
|
+
self.branches.include(branch)
|
72
|
+
self.mail_manager.add_sources(branch)
|
73
|
+
|
74
|
+
branch.user = self.id
|
75
|
+
branch._operation_manager = self._operation_manager
|
76
|
+
if self.default_branch is None:
|
77
|
+
self.default_branch = branch
|
78
|
+
|
79
|
+
branches = [branches] if isinstance(branches, Branch) else branches
|
80
|
+
|
81
|
+
for i in branches:
|
82
|
+
_take_in_branch(i)
|
83
|
+
|
84
|
+
def register_operation(
|
85
|
+
self, operation: str, func: Callable, *, update: bool = False
|
86
|
+
):
|
87
|
+
self._operation_manager.register(operation, func, update=update)
|
59
88
|
|
60
89
|
@model_validator(mode="after")
|
61
90
|
def _add_mail_sources(self) -> Self:
|
@@ -64,7 +93,7 @@ class Session(Node, Communicatable, Relational):
|
|
64
93
|
if self.default_branch not in self.branches:
|
65
94
|
self.branches.include(self.default_branch)
|
66
95
|
if self.branches:
|
67
|
-
self.
|
96
|
+
self.include_branches(self.branches)
|
68
97
|
return self
|
69
98
|
|
70
99
|
def _lookup_branch_by_name(self, name: str) -> Branch | None:
|
@@ -102,7 +131,8 @@ class Session(Node, Communicatable, Relational):
|
|
102
131
|
progress: Progression = None,
|
103
132
|
tool_manager: ActionManager = None,
|
104
133
|
tools: Tool | Callable | list = None,
|
105
|
-
|
134
|
+
as_default_branch: bool = False,
|
135
|
+
**kwargs,
|
106
136
|
) -> Branch:
|
107
137
|
kwargs["system"] = system
|
108
138
|
kwargs["system_sender"] = system_sender
|
@@ -116,13 +146,9 @@ class Session(Node, Communicatable, Relational):
|
|
116
146
|
kwargs["tools"] = tools
|
117
147
|
kwargs = {k: v for k, v in kwargs.items() if v is not None}
|
118
148
|
|
119
|
-
from .branch import Branch
|
120
|
-
|
121
149
|
branch = Branch(**kwargs) # type: ignore
|
122
|
-
|
123
|
-
|
124
|
-
self.mail_manager.add_sources(branch)
|
125
|
-
if self.default_branch is None:
|
150
|
+
self.include_branches(branch)
|
151
|
+
if as_default_branch:
|
126
152
|
self.default_branch = branch
|
127
153
|
return branch
|
128
154
|
|
@@ -179,7 +205,7 @@ class Session(Node, Communicatable, Relational):
|
|
179
205
|
"""
|
180
206
|
branch: Branch = self.branches[branch]
|
181
207
|
branch_clone = branch.clone(sender=self.id)
|
182
|
-
self.
|
208
|
+
self.include_branches(branch_clone)
|
183
209
|
return branch_clone
|
184
210
|
|
185
211
|
def change_default_branch(self, branch: ID.Ref):
|
@@ -230,10 +256,11 @@ class Session(Node, Communicatable, Relational):
|
|
230
256
|
lambda x: [
|
231
257
|
i for i in self.branches[x].messages if i not in exclude_flag
|
232
258
|
],
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
259
|
+
input_unique=True,
|
260
|
+
input_flatten=True,
|
261
|
+
input_dropna=True,
|
262
|
+
output_flatten=True,
|
263
|
+
output_unique=True,
|
237
264
|
)
|
238
265
|
return Pile(
|
239
266
|
collections=messages, item_type={RoledMessage}, strict_type=False
|
@@ -269,14 +296,15 @@ class Session(Node, Communicatable, Relational):
|
|
269
296
|
lcall(
|
270
297
|
to_,
|
271
298
|
lambda x: self.mail_manager.send(ID.get_id(x)),
|
272
|
-
|
273
|
-
|
274
|
-
|
299
|
+
input_unique=True,
|
300
|
+
input_flatten=True,
|
301
|
+
input_dropna=True,
|
302
|
+
input_use_values=True,
|
275
303
|
)
|
276
304
|
except Exception as e:
|
277
305
|
raise ValueError(f"Failed to send mail. Error: {e}")
|
278
306
|
|
279
|
-
async def acollect_send_all(self, receive_all: bool =
|
307
|
+
async def acollect_send_all(self, receive_all: bool = True):
|
280
308
|
"""
|
281
309
|
Collect and send mail for all branches, optionally receiving all mail.
|
282
310
|
|
@@ -286,7 +314,7 @@ class Session(Node, Communicatable, Relational):
|
|
286
314
|
async with self.mail_manager.sources:
|
287
315
|
self.collect_send_all(receive_all)
|
288
316
|
|
289
|
-
def collect_send_all(self, receive_all: bool =
|
317
|
+
def collect_send_all(self, receive_all: bool = True):
|
290
318
|
"""
|
291
319
|
Collect and send mail for all branches, optionally receiving all mail.
|
292
320
|
|
@@ -296,7 +324,8 @@ class Session(Node, Communicatable, Relational):
|
|
296
324
|
self.collect()
|
297
325
|
self.send()
|
298
326
|
if receive_all:
|
299
|
-
|
327
|
+
for i in self.branches:
|
328
|
+
i.receive_all()
|
300
329
|
|
301
330
|
def collect(self, from_: ID.RefSeq = None):
|
302
331
|
"""
|
@@ -316,9 +345,10 @@ class Session(Node, Communicatable, Relational):
|
|
316
345
|
lcall(
|
317
346
|
from_,
|
318
347
|
lambda x: self.mail_manager.collect(ID.get_id(x)),
|
319
|
-
|
320
|
-
|
321
|
-
|
348
|
+
input_flatten=True,
|
349
|
+
input_dropna=True,
|
350
|
+
input_unique=True,
|
351
|
+
input_use_values=True,
|
322
352
|
)
|
323
353
|
except Exception as e:
|
324
354
|
raise ValueError(f"Failed to collect mail. Error: {e}")
|