lionagi 0.6.1__py3-none-any.whl → 0.7.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/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 +108 -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 +39 -0
- lionagi/operations/operate/__init__.py +3 -0
- lionagi/operations/operate/operate.py +194 -0
- lionagi/operations/parse/__init__.py +3 -0
- lionagi/operations/parse/parse.py +89 -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 +16 -0
- lionagi/operatives/action/manager.py +115 -93
- lionagi/operatives/action/request_response_model.py +31 -0
- lionagi/operatives/action/tool.py +50 -20
- lionagi/operatives/strategies/__init__.py +3 -0
- lionagi/protocols/_concepts.py +1 -1
- lionagi/protocols/adapters/adapter.py +25 -0
- lionagi/protocols/adapters/json_adapter.py +107 -27
- lionagi/protocols/adapters/pandas_/csv_adapter.py +55 -11
- lionagi/protocols/adapters/pandas_/excel_adapter.py +52 -10
- lionagi/protocols/adapters/pandas_/pd_dataframe_adapter.py +54 -4
- lionagi/protocols/adapters/pandas_/pd_series_adapter.py +40 -0
- lionagi/protocols/generic/element.py +1 -1
- lionagi/protocols/generic/pile.py +5 -8
- lionagi/protocols/graph/edge.py +1 -1
- lionagi/protocols/graph/graph.py +16 -8
- lionagi/protocols/graph/node.py +1 -1
- lionagi/protocols/mail/exchange.py +126 -15
- lionagi/protocols/mail/mail.py +33 -0
- lionagi/protocols/mail/mailbox.py +62 -0
- lionagi/protocols/mail/manager.py +97 -41
- lionagi/protocols/mail/package.py +57 -3
- lionagi/protocols/messages/action_request.py +77 -26
- lionagi/protocols/messages/action_response.py +55 -26
- lionagi/protocols/messages/assistant_response.py +50 -15
- lionagi/protocols/messages/base.py +36 -0
- lionagi/protocols/messages/instruction.py +175 -145
- lionagi/protocols/messages/manager.py +152 -56
- lionagi/protocols/messages/message.py +61 -25
- lionagi/protocols/messages/system.py +54 -19
- lionagi/service/imodel.py +24 -0
- lionagi/session/branch.py +1116 -939
- lionagi/utils.py +1 -0
- lionagi/version.py +1 -1
- {lionagi-0.6.1.dist-info → lionagi-0.7.1.dist-info}/METADATA +1 -1
- {lionagi-0.6.1.dist-info → lionagi-0.7.1.dist-info}/RECORD +75 -56
- lionagi/libs/compress/models.py +0 -66
- lionagi/libs/compress/utils.py +0 -69
- lionagi/operations/select/prompt.py +0 -5
- /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/params.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.1.dist-info → lionagi-0.7.1.dist-info}/WHEEL +0 -0
- {lionagi-0.6.1.dist-info → lionagi-0.7.1.dist-info}/licenses/LICENSE +0 -0
@@ -2,6 +2,11 @@
|
|
2
2
|
#
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
4
4
|
|
5
|
+
"""
|
6
|
+
Defines the `System` class, representing system-level instructions or
|
7
|
+
settings that guide the AI's behavior from a privileged role.
|
8
|
+
"""
|
9
|
+
|
5
10
|
from datetime import datetime
|
6
11
|
from typing import Any, NoReturn, Self
|
7
12
|
|
@@ -19,14 +24,16 @@ def format_system_content(
|
|
19
24
|
system_message: str,
|
20
25
|
) -> dict:
|
21
26
|
"""
|
22
|
-
|
27
|
+
Insert optional datetime string into the system message content.
|
23
28
|
|
24
29
|
Args:
|
25
|
-
system_datetime:
|
26
|
-
|
30
|
+
system_datetime (bool|str|None):
|
31
|
+
If True, embed current time. If str, use as time. If None, omit.
|
32
|
+
system_message (str):
|
33
|
+
The main system message text.
|
27
34
|
|
28
35
|
Returns:
|
29
|
-
|
36
|
+
dict: The combined system content.
|
30
37
|
"""
|
31
38
|
content: dict = {"system_message": system_message}
|
32
39
|
if system_datetime:
|
@@ -40,6 +47,11 @@ def format_system_content(
|
|
40
47
|
|
41
48
|
|
42
49
|
class System(RoledMessage):
|
50
|
+
"""
|
51
|
+
A specialized message that sets a *system-level* context or policy.
|
52
|
+
Usually the first in a conversation, instructing the AI about general
|
53
|
+
constraints or identity.
|
54
|
+
"""
|
43
55
|
|
44
56
|
template: str | Template | None = jinja_env.get_template(
|
45
57
|
"system_message.jinja2"
|
@@ -58,14 +70,26 @@ class System(RoledMessage):
|
|
58
70
|
**kwargs,
|
59
71
|
) -> Self:
|
60
72
|
"""
|
61
|
-
|
73
|
+
Construct a system message with optional datetime annotation.
|
62
74
|
|
63
75
|
Args:
|
64
|
-
system_message:
|
65
|
-
|
76
|
+
system_message (str):
|
77
|
+
The main text instructing the AI about behavior/identity.
|
78
|
+
system_datetime (bool|str, optional):
|
79
|
+
If True or str, embed a time reference. If str, it is used directly.
|
80
|
+
sender (SenderRecipient, optional):
|
81
|
+
Typically `MessageRole.SYSTEM`.
|
82
|
+
recipient (SenderRecipient, optional):
|
83
|
+
Typically `MessageRole.ASSISTANT`.
|
84
|
+
template (Template|str|None):
|
85
|
+
An optional custom template for rendering.
|
86
|
+
system (Any):
|
87
|
+
Alias for `system_message` (deprecated).
|
88
|
+
**kwargs:
|
89
|
+
Additional content merged into the final dict.
|
66
90
|
|
67
91
|
Returns:
|
68
|
-
System:
|
92
|
+
System: A newly created system-level message.
|
69
93
|
"""
|
70
94
|
if system and system_message:
|
71
95
|
raise ValueError(
|
@@ -78,14 +102,14 @@ class System(RoledMessage):
|
|
78
102
|
system_datetime=system_datetime, system_message=system_message
|
79
103
|
)
|
80
104
|
content.update(kwargs)
|
81
|
-
params = {
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
105
|
+
params = {
|
106
|
+
"role": MessageRole.SYSTEM,
|
107
|
+
"content": content,
|
108
|
+
"sender": sender or MessageRole.SYSTEM,
|
109
|
+
"recipient": recipient or MessageRole.ASSISTANT,
|
110
|
+
}
|
86
111
|
if template:
|
87
112
|
params["template"] = template
|
88
|
-
|
89
113
|
return cls(**params)
|
90
114
|
|
91
115
|
def update(
|
@@ -98,13 +122,21 @@ class System(RoledMessage):
|
|
98
122
|
**kwargs,
|
99
123
|
) -> NoReturn:
|
100
124
|
"""
|
101
|
-
|
125
|
+
Adjust fields of this system message.
|
102
126
|
|
103
127
|
Args:
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
128
|
+
system_message (JsonValue):
|
129
|
+
New system message text.
|
130
|
+
sender (SenderRecipient):
|
131
|
+
Updated sender or role.
|
132
|
+
recipient (SenderRecipient):
|
133
|
+
Updated recipient or role.
|
134
|
+
system_datetime (bool|str):
|
135
|
+
If set, embed new datetime info.
|
136
|
+
template (Template|str|None):
|
137
|
+
New template override.
|
138
|
+
**kwargs:
|
139
|
+
Additional fields for self.content.
|
108
140
|
"""
|
109
141
|
if any([system_message, system_message]):
|
110
142
|
self.content = format_system_content(
|
@@ -113,3 +145,6 @@ class System(RoledMessage):
|
|
113
145
|
super().update(
|
114
146
|
sender=sender, recipient=recipient, template=template, **kwargs
|
115
147
|
)
|
148
|
+
|
149
|
+
|
150
|
+
# File: lionagi/protocols/messages/system.py
|
lionagi/service/imodel.py
CHANGED
@@ -295,3 +295,27 @@ class iModel:
|
|
295
295
|
**data,
|
296
296
|
**processor_config,
|
297
297
|
)
|
298
|
+
|
299
|
+
async def compress_text(
|
300
|
+
self,
|
301
|
+
text: str,
|
302
|
+
system_msg: str = None,
|
303
|
+
target_ratio: float = 0.2,
|
304
|
+
n_samples: int = 5,
|
305
|
+
max_tokens_per_sample=80,
|
306
|
+
verbose=True,
|
307
|
+
) -> str:
|
308
|
+
"""
|
309
|
+
Convenience function that instantiates LLMCompressor and compresses text.
|
310
|
+
"""
|
311
|
+
from lionagi.libs.token_transform.perplexity import LLMCompressor
|
312
|
+
|
313
|
+
compressor = LLMCompressor(
|
314
|
+
chat_model=self,
|
315
|
+
system_msg=system_msg,
|
316
|
+
target_ratio=target_ratio,
|
317
|
+
n_samples=n_samples,
|
318
|
+
max_tokens_per_sample=max_tokens_per_sample,
|
319
|
+
verbose=verbose,
|
320
|
+
)
|
321
|
+
return await compressor.compress(text)
|