lionagi 0.5.1__py3-none-any.whl → 0.5.3__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/__init__.py +3 -1
- lionagi/core/action/tool.py +3 -5
- lionagi/core/communication/action_request.py +3 -3
- lionagi/core/communication/message.py +3 -3
- lionagi/core/communication/utils.py +3 -3
- lionagi/core/generic/component.py +4 -4
- lionagi/core/generic/element.py +51 -47
- lionagi/core/generic/graph.py +1 -1
- lionagi/core/generic/log.py +2 -2
- lionagi/core/generic/pile.py +10 -11
- lionagi/core/generic/progression.py +19 -12
- lionagi/core/generic/utils.py +6 -3
- lionagi/core/models/base.py +11 -68
- lionagi/core/models/field_model.py +42 -19
- lionagi/core/models/{new_model_params.py → model_params.py} +5 -6
- lionagi/core/models/note.py +2 -2
- lionagi/core/models/operable_model.py +8 -4
- lionagi/core/models/schema_model.py +9 -31
- lionagi/core/models/types.py +15 -6
- lionagi/core/session/branch.py +8 -4
- lionagi/core/session/branch_mixins.py +11 -12
- lionagi/core/session/session.py +1 -2
- lionagi/core/typing/__init__.py +4 -4
- lionagi/core/typing/{concepts.py → _concepts.py} +43 -2
- lionagi/core/typing/_id.py +104 -0
- lionagi/integrations/anthropic_/AnthropicModel.py +8 -3
- lionagi/integrations/groq_/GroqModel.py +11 -4
- lionagi/integrations/litellm_/imodel.py +6 -8
- lionagi/integrations/openai_/OpenAIModel.py +8 -3
- lionagi/integrations/openai_/image_token_calculator/image_token_calculator.py +14 -8
- lionagi/integrations/perplexity_/PerplexityModel.py +8 -3
- lionagi/libs/func/async_calls/__init__.py +6 -3
- lionagi/libs/func/async_calls/alcall.py +46 -0
- lionagi/libs/func/async_calls/bcall.py +49 -1
- lionagi/libs/func/async_calls/rcall.py +32 -0
- lionagi/libs/utils.py +12 -1
- lionagi/operations/brainstorm/brainstorm.py +4 -4
- lionagi/operations/brainstorm/prompt.py +8 -1
- lionagi/operations/plan/plan.py +3 -3
- lionagi/operations/plan/prompt.py +17 -16
- lionagi/protocols/__init__.py +3 -0
- lionagi/protocols/configs/__init__.py +0 -15
- lionagi/protocols/configs/branch_config.py +1 -1
- lionagi/protocols/configs/imodel_config.py +2 -2
- lionagi/protocols/configs/log_config.py +1 -1
- lionagi/protocols/configs/types.py +15 -0
- lionagi/protocols/operatives/__init__.py +3 -15
- lionagi/protocols/operatives/action.py +4 -0
- lionagi/protocols/operatives/instruct.py +6 -8
- lionagi/protocols/operatives/operative.py +9 -21
- lionagi/protocols/operatives/prompts.py +53 -202
- lionagi/protocols/operatives/reason.py +4 -0
- lionagi/protocols/operatives/step.py +11 -23
- lionagi/protocols/operatives/types.py +19 -0
- lionagi/protocols/registries/__init__.py +3 -0
- lionagi/protocols/registries/_component_registry.py +4 -0
- lionagi/protocols/registries/_pile_registry.py +4 -0
- lionagi/service/__init__.py +3 -0
- lionagi/service/service_match_util.py +4 -4
- lionagi/settings.py +10 -18
- lionagi/strategies/base.py +4 -5
- lionagi/strategies/concurrent.py +4 -3
- lionagi/strategies/concurrent_chunk.py +3 -3
- lionagi/strategies/concurrent_sequential_chunk.py +3 -3
- lionagi/strategies/params.py +7 -4
- lionagi/version.py +1 -1
- {lionagi-0.5.1.dist-info → lionagi-0.5.3.dist-info}/METADATA +5 -3
- {lionagi-0.5.1.dist-info → lionagi-0.5.3.dist-info}/RECORD +73 -72
- lionagi/core/typing/config.py +0 -15
- lionagi/core/typing/id.py +0 -221
- /lionagi/core/typing/{pydantic_.py → _pydantic.py} +0 -0
- /lionagi/core/typing/{typing_.py → _typing.py} +0 -0
- /lionagi/integrations/{services.py → _services.py} +0 -0
- {lionagi-0.5.1.dist-info → lionagi-0.5.3.dist-info}/WHEEL +0 -0
- {lionagi-0.5.1.dist-info → lionagi-0.5.3.dist-info}/licenses/LICENSE +0 -0
@@ -1,25 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
you may not use this file except in compliance with the License.
|
6
|
-
You may obtain a copy of the License at
|
7
|
-
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
See the License for the specific language governing permissions and
|
14
|
-
limitations under the License.
|
15
|
-
"""
|
1
|
+
# Copyright (c) 2023 - 2024, HaiyangLi <quantocean.li at gmail dot com>
|
2
|
+
#
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
16
4
|
|
17
5
|
from typing import Self
|
18
6
|
|
19
7
|
from pydantic import BaseModel, Field, PrivateAttr, model_validator
|
20
8
|
from pydantic.fields import FieldInfo
|
21
9
|
|
22
|
-
from lionagi.core.models import FieldModel,
|
10
|
+
from lionagi.core.models import FieldModel, ModelParams, OperableModel
|
23
11
|
from lionagi.core.typing import UNDEFINED
|
24
12
|
from lionagi.libs.parse import to_json, validate_keys
|
25
13
|
|
@@ -29,10 +17,10 @@ class Operative(OperableModel):
|
|
29
17
|
|
30
18
|
name: str | None = None
|
31
19
|
|
32
|
-
request_params:
|
20
|
+
request_params: ModelParams | None = Field(default=None)
|
33
21
|
request_type: type[BaseModel] | None = Field(default=None)
|
34
22
|
|
35
|
-
response_params:
|
23
|
+
response_params: ModelParams | None = Field(default=None)
|
36
24
|
response_type: type[BaseModel] | None = Field(default=None)
|
37
25
|
response_model: OperableModel | None = Field(default=None)
|
38
26
|
response_str_dict: dict | str | None = Field(default=None)
|
@@ -140,7 +128,7 @@ class Operative(OperableModel):
|
|
140
128
|
|
141
129
|
def create_response_type(
|
142
130
|
self,
|
143
|
-
response_params:
|
131
|
+
response_params: ModelParams | None = None,
|
144
132
|
field_models: list[FieldModel] | None = None,
|
145
133
|
parameter_fields: dict[str, FieldInfo] | None = None,
|
146
134
|
exclude_fields: list[str] | None = None,
|
@@ -154,7 +142,7 @@ class Operative(OperableModel):
|
|
154
142
|
"""Creates a new response type based on the provided parameters.
|
155
143
|
|
156
144
|
Args:
|
157
|
-
response_params (
|
145
|
+
response_params (ModelParams, optional): Parameters for the new response model.
|
158
146
|
field_models (list[FieldModel], optional): List of field models.
|
159
147
|
parameter_fields (dict[str, FieldInfo], optional): Dictionary of parameter fields.
|
160
148
|
exclude_fields (list, optional): List of fields to exclude.
|
@@ -165,7 +153,7 @@ class Operative(OperableModel):
|
|
165
153
|
frozen (bool, optional): Whether the model is frozen.
|
166
154
|
validators (dict, optional): Dictionary of validators.
|
167
155
|
"""
|
168
|
-
self.response_params = response_params or
|
156
|
+
self.response_params = response_params or ModelParams(
|
169
157
|
parameter_fields=parameter_fields,
|
170
158
|
field_models=field_models,
|
171
159
|
exclude_fields=exclude_fields,
|
@@ -1,232 +1,83 @@
|
|
1
|
-
|
1
|
+
# Copyright (c) 2023 - 2024, HaiyangLi <quantocean.li at gmail dot com>
|
2
|
+
#
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
2
4
|
|
3
5
|
function_field_description = (
|
4
|
-
"
|
5
|
-
"
|
6
|
-
"
|
7
|
-
"must leave blank or set to None."
|
6
|
+
"Name of the function to call from the provided `tool_schemas`. "
|
7
|
+
"If no `tool_schemas` exist, set to None or leave blank. "
|
8
|
+
"Never invent new function names outside what's given."
|
8
9
|
)
|
9
10
|
|
10
11
|
arguments_field_description = (
|
11
|
-
"
|
12
|
-
"
|
13
|
-
"
|
12
|
+
"Dictionary of arguments for the chosen function. "
|
13
|
+
"Use only argument names/types defined in `tool_schemas`. "
|
14
|
+
"Never introduce extra argument names."
|
14
15
|
)
|
15
16
|
|
16
17
|
action_required_field_description = (
|
17
|
-
"
|
18
|
-
"
|
19
|
-
"
|
20
|
-
"`
|
21
|
-
" are provided, this field is ignored."
|
18
|
+
"Whether this step strictly requires performing actions. "
|
19
|
+
"If true, the requests in `action_requests` must be fulfilled, "
|
20
|
+
"assuming `tool_schemas` are available. "
|
21
|
+
"If false or no `tool_schemas` exist, actions are optional."
|
22
22
|
)
|
23
23
|
|
24
24
|
action_requests_field_description = (
|
25
|
-
"List of actions to be
|
26
|
-
"
|
27
|
-
"
|
28
|
-
"provided `tool_schemas`. Do not invent function or "
|
29
|
-
"argument names.**"
|
25
|
+
"List of actions to be executed when `action_required` is true. "
|
26
|
+
"Each action must align with the available `tool_schemas`. "
|
27
|
+
"Leave empty if no actions are needed."
|
30
28
|
)
|
31
29
|
|
32
30
|
confidence_description = (
|
33
|
-
"
|
34
|
-
"
|
35
|
-
"
|
36
|
-
"-
|
37
|
-
"
|
38
|
-
"
|
39
|
-
"- **[0.5, 0.8)**: Recheck your reasoning and consider reverting to a "
|
40
|
-
"previous, more confident reasoning path.\n"
|
41
|
-
"- **[0, 0.5)**: Stop because the reasoning is starting to be off track."
|
31
|
+
"Numeric confidence score (0.0 to 1.0, up to three decimals) indicating "
|
32
|
+
"how well you've met user expectations. Use this guide:\n"
|
33
|
+
" • 1.0: Highly confident\n"
|
34
|
+
" • 0.8-1.0: Reasonably sure\n"
|
35
|
+
" • 0.5-0.8: Re-check or refine\n"
|
36
|
+
" • 0.0-0.5: Off track"
|
42
37
|
)
|
43
38
|
|
44
39
|
instruction_field_description = (
|
45
|
-
"
|
46
|
-
"1
|
47
|
-
"2
|
48
|
-
"
|
49
|
-
"
|
50
|
-
"- Start with a
|
51
|
-
"-
|
52
|
-
"-
|
53
|
-
"-
|
54
|
-
"**Examples:**\n"
|
55
|
-
"- 'Analyze the provided sales data and identify top 3 performing products'\n"
|
56
|
-
"- 'Generate a Python function that validates email addresses'\n"
|
57
|
-
"- 'Create a data visualization showing monthly revenue trends'"
|
40
|
+
"A clear, actionable task definition. Specify:\n"
|
41
|
+
"1) The primary goal or objective\n"
|
42
|
+
"2) Key success criteria or constraints\n"
|
43
|
+
"\n"
|
44
|
+
"Guidelines:\n"
|
45
|
+
"- Start with a direct action verb (e.g., 'Analyze', 'Generate', 'Create')\n"
|
46
|
+
"- Include scope, boundaries, or constraints\n"
|
47
|
+
"- Provide success criteria if relevant\n"
|
48
|
+
"- For complex tasks, break them into logical steps"
|
58
49
|
)
|
59
50
|
|
60
51
|
guidance_field_description = (
|
61
|
-
"
|
62
|
-
"
|
63
|
-
"1
|
64
|
-
"2
|
65
|
-
"3
|
66
|
-
"4
|
67
|
-
"
|
68
|
-
"- Be explicit about any assumptions that should be made\n"
|
69
|
-
"- Specify preferred approaches or techniques\n"
|
70
|
-
"- Detail any constraints on resources or methods\n"
|
71
|
-
"- Include relevant standards or compliance requirements\n\n"
|
72
|
-
"Leave as None if no specific guidance is needed beyond the instruction."
|
52
|
+
"Strategic direction and constraints for executing the task. "
|
53
|
+
"Include:\n"
|
54
|
+
"1) Preferred methods or frameworks\n"
|
55
|
+
"2) Quality benchmarks (e.g., speed, clarity)\n"
|
56
|
+
"3) Resource or environmental constraints\n"
|
57
|
+
"4) Relevant compliance or standards\n"
|
58
|
+
"Use None if no special guidance."
|
73
59
|
)
|
74
60
|
|
75
61
|
context_field_description = (
|
76
|
-
"
|
77
|
-
"
|
78
|
-
"
|
79
|
-
"
|
80
|
-
"
|
81
|
-
"
|
82
|
-
"
|
83
|
-
"**Context should:**\n"
|
84
|
-
"- Be directly relevant to the task\n"
|
85
|
-
"- Provide necessary background without excess detail\n"
|
86
|
-
"- Include any dependencies or prerequisites\n"
|
87
|
-
"- Specify the current state of the system\n\n"
|
88
|
-
"Set to None if no additional context is required."
|
62
|
+
"Background information and current-state data needed for the task. "
|
63
|
+
"Should be:\n"
|
64
|
+
"1) Directly relevant\n"
|
65
|
+
"2) Sufficient to perform the task\n"
|
66
|
+
"3) Free of extraneous detail\n"
|
67
|
+
"Include environment, prior outcomes, system states, or dependencies. "
|
68
|
+
"Use None if no additional context is needed."
|
89
69
|
)
|
90
70
|
|
91
71
|
reason_field_description = (
|
92
|
-
"
|
93
|
-
"
|
94
|
-
"
|
95
|
-
"
|
96
|
-
"- Must provide confidence scores for decisions\n"
|
97
|
-
"- Should explain trade-offs considered\n\n"
|
98
|
-
"**When set to False:**\n"
|
99
|
-
"- Skip detailed reasoning\n"
|
100
|
-
"- Focus on direct results\n"
|
101
|
-
"- Omit confidence scoring\n\n"
|
102
|
-
"Set to None to make reasoning optional based on context."
|
72
|
+
"Include a thoughtful explanation of decisions, trade-offs, "
|
73
|
+
"and insights. Encourage deeper introspection on why certain "
|
74
|
+
"choices were made, potential alternatives, and how confidence "
|
75
|
+
"was shaped. If not needed, set to None."
|
103
76
|
)
|
104
77
|
|
105
78
|
actions_field_description = (
|
106
|
-
"
|
107
|
-
"
|
108
|
-
"
|
109
|
-
"
|
110
|
-
"- Each action must be properly structured and validated\n"
|
111
|
-
"- Actions must use available tool schemas\n\n"
|
112
|
-
"**When set to False:**\n"
|
113
|
-
"- No actions should be included\n"
|
114
|
-
"- Focus on analysis and recommendations\n\n"
|
115
|
-
"Set to None to make actions optional based on requirements."
|
79
|
+
"Controls execution mode. "
|
80
|
+
"True: Execute specified actions. "
|
81
|
+
"False: Analysis/recommendations only. "
|
82
|
+
"None: Contextual execution."
|
116
83
|
)
|
117
|
-
|
118
|
-
# Example structures for each field to demonstrate proper formatting
|
119
|
-
instruction_examples: list[JsonValue] = [
|
120
|
-
"Analyze the dataset 'sales_2023.csv' and identify revenue trends",
|
121
|
-
"Create a Python function to process customer feedback data",
|
122
|
-
{
|
123
|
-
"task": "data_analysis",
|
124
|
-
"target": "sales_performance",
|
125
|
-
"scope": ["revenue", "growth", "seasonality"],
|
126
|
-
},
|
127
|
-
]
|
128
|
-
|
129
|
-
guidance_examples: list[JsonValue] = [
|
130
|
-
"Use statistical methods for trend analysis",
|
131
|
-
"Optimize for readability and maintainability",
|
132
|
-
{
|
133
|
-
"methods": ["regression", "time_series"],
|
134
|
-
"constraints": {"memory": "2GB", "time": "5min"},
|
135
|
-
},
|
136
|
-
]
|
137
|
-
|
138
|
-
context_examples: list[JsonValue] = [
|
139
|
-
"Previous analysis showed seasonal patterns",
|
140
|
-
{
|
141
|
-
"prior_results": {"accuracy": 0.95},
|
142
|
-
"system_state": "production",
|
143
|
-
"dependencies": ["numpy", "pandas"],
|
144
|
-
},
|
145
|
-
]
|
146
|
-
|
147
|
-
"""Field description for InstructModel."""
|
148
|
-
|
149
|
-
instruct_model_description = (
|
150
|
-
"Generate structured instructions for task execution.\n\n"
|
151
|
-
"**Key Components:**\n"
|
152
|
-
"1. Task Definition: Clear description of what needs to be accomplished\n"
|
153
|
-
"2. Execution Parameters: How the task should be performed\n"
|
154
|
-
"3. Success Criteria: What constitutes successful completion\n"
|
155
|
-
"4. Scope and Boundaries: Limits and constraints of the task\n\n"
|
156
|
-
"**Structure Guidelines:**\n"
|
157
|
-
"- `instruction`: Core task or objective to accomplish\n"
|
158
|
-
"- `guidance`: Parameters, preferences, and constraints\n"
|
159
|
-
"- `context`: Relevant background and environmental information\n"
|
160
|
-
"- `reason`: Whether to include reasoning in output\n"
|
161
|
-
"- `actions`: Whether specific actions are required\n\n"
|
162
|
-
"**Best Practices:**\n"
|
163
|
-
"- Keep instructions clear and specific\n"
|
164
|
-
"- Provide necessary but not excessive detail\n"
|
165
|
-
"- Define measurable outcomes\n"
|
166
|
-
"- Include relevant dependencies\n"
|
167
|
-
"- Specify critical constraints\n\n"
|
168
|
-
"**Common Issues to Avoid:**\n"
|
169
|
-
"- Vague or ambiguous directives\n"
|
170
|
-
"- Missing essential context\n"
|
171
|
-
"- Undefined success criteria\n"
|
172
|
-
"- Incomplete requirements\n"
|
173
|
-
"- Conflicting parameters\n\n"
|
174
|
-
"Structure instructions to enable successful task execution while maintaining "
|
175
|
-
"appropriate flexibility for implementation details."
|
176
|
-
)
|
177
|
-
|
178
|
-
instruct_model_examples = [
|
179
|
-
{
|
180
|
-
"instruction": "Process the input data according to specified requirements",
|
181
|
-
"guidance": {
|
182
|
-
"requirements": ["validation", "transformation", "aggregation"],
|
183
|
-
"output_format": "structured_report",
|
184
|
-
"quality_metrics": ["accuracy", "completeness"],
|
185
|
-
},
|
186
|
-
"context": {
|
187
|
-
"input_source": "data_stream",
|
188
|
-
"domain": "general",
|
189
|
-
"priority": "standard",
|
190
|
-
},
|
191
|
-
"reason": True,
|
192
|
-
"actions": True,
|
193
|
-
},
|
194
|
-
{
|
195
|
-
"instruction": "Evaluate system performance against baseline metrics",
|
196
|
-
"guidance": {
|
197
|
-
"evaluation_criteria": [
|
198
|
-
"response_time",
|
199
|
-
"resource_usage",
|
200
|
-
"error_rate",
|
201
|
-
],
|
202
|
-
"methodology": "standard",
|
203
|
-
"reporting": "detailed",
|
204
|
-
},
|
205
|
-
"context": {
|
206
|
-
"environment": "test",
|
207
|
-
"criticality": "medium",
|
208
|
-
"constraints": {"time": "bounded"},
|
209
|
-
},
|
210
|
-
"reason": True,
|
211
|
-
"actions": False,
|
212
|
-
},
|
213
|
-
]
|
214
|
-
|
215
|
-
|
216
|
-
__all__ = [
|
217
|
-
"function_field_description",
|
218
|
-
"arguments_field_description",
|
219
|
-
"action_required_field_description",
|
220
|
-
"action_requests_field_description",
|
221
|
-
"confidence_description",
|
222
|
-
"instruction_field_description",
|
223
|
-
"guidance_field_description",
|
224
|
-
"context_field_description",
|
225
|
-
"reason_field_description",
|
226
|
-
"actions_field_description",
|
227
|
-
"instruction_examples",
|
228
|
-
"guidance_examples",
|
229
|
-
"context_examples",
|
230
|
-
"instruct_model_description",
|
231
|
-
"instruct_model_examples",
|
232
|
-
]
|
@@ -1,23 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
you may not use this file except in compliance with the License.
|
6
|
-
You may obtain a copy of the License at
|
7
|
-
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
See the License for the specific language governing permissions and
|
14
|
-
limitations under the License.
|
15
|
-
"""
|
1
|
+
# Copyright (c) 2023 - 2024, HaiyangLi <quantocean.li at gmail dot com>
|
2
|
+
#
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
16
4
|
|
17
5
|
from pydantic import BaseModel
|
18
6
|
from pydantic.fields import FieldInfo
|
19
7
|
|
20
|
-
from lionagi.core.typing import FieldModel,
|
8
|
+
from lionagi.core.typing import FieldModel, ModelParams
|
21
9
|
from lionagi.protocols.operatives.operative import Operative
|
22
10
|
|
23
11
|
from .action import (
|
@@ -54,7 +42,7 @@ class Step:
|
|
54
42
|
operative_name: str | None = None,
|
55
43
|
reason: bool = False,
|
56
44
|
actions: bool = False,
|
57
|
-
request_params:
|
45
|
+
request_params: ModelParams | None = None,
|
58
46
|
parameter_fields: dict[str, FieldInfo] | None = None,
|
59
47
|
base_type: type[BaseModel] | None = None,
|
60
48
|
field_models: list[FieldModel] | None = None,
|
@@ -72,7 +60,7 @@ class Step:
|
|
72
60
|
operative_name (str, optional): Name of the operative.
|
73
61
|
reason (bool, optional): Whether to include reason field.
|
74
62
|
actions (bool, optional): Whether to include action fields.
|
75
|
-
request_params (
|
63
|
+
request_params (ModelParams, optional): Parameters for the new model.
|
76
64
|
parameter_fields (dict[str, FieldInfo], optional): Parameter fields for the model.
|
77
65
|
base_type (type[BaseModel], optional): Base type for the model.
|
78
66
|
field_models (list[FieldModel], optional): List of field models.
|
@@ -100,7 +88,7 @@ class Step:
|
|
100
88
|
ACTION_REQUIRED_FIELD,
|
101
89
|
]
|
102
90
|
)
|
103
|
-
request_params = request_params or
|
91
|
+
request_params = request_params or ModelParams(
|
104
92
|
parameter_fields=parameter_fields,
|
105
93
|
base_type=base_type,
|
106
94
|
field_models=field_models,
|
@@ -119,7 +107,7 @@ class Step:
|
|
119
107
|
*,
|
120
108
|
operative: Operative,
|
121
109
|
additional_data: dict | None = None,
|
122
|
-
response_params:
|
110
|
+
response_params: ModelParams | None = None,
|
123
111
|
field_models: list[FieldModel] | None = None,
|
124
112
|
frozen_response: bool = False,
|
125
113
|
response_config_dict: dict | None = None,
|
@@ -131,7 +119,7 @@ class Step:
|
|
131
119
|
Args:
|
132
120
|
operative (Operative): The operative instance to update.
|
133
121
|
additional_data (dict | None, optional): Additional data to include in the response.
|
134
|
-
response_params (
|
122
|
+
response_params (ModelParams | None, optional): Parameters for the response model.
|
135
123
|
field_models (list[FieldModel] | None, optional): List of field models.
|
136
124
|
frozen_response (bool, optional): Whether the response model is frozen.
|
137
125
|
response_config_dict (dict | None, optional): Configuration dictionary for the response.
|
@@ -162,7 +150,7 @@ class Step:
|
|
162
150
|
@staticmethod
|
163
151
|
def _create_response_type(
|
164
152
|
operative: Operative,
|
165
|
-
response_params:
|
153
|
+
response_params: ModelParams | None = None,
|
166
154
|
response_validators: dict | None = None,
|
167
155
|
frozen_response: bool = False,
|
168
156
|
response_config_dict: dict | None = None,
|
@@ -174,7 +162,7 @@ class Step:
|
|
174
162
|
|
175
163
|
Args:
|
176
164
|
operative (Operative): The operative instance.
|
177
|
-
response_params (
|
165
|
+
response_params (ModelParams | None, optional): Parameters for the response model.
|
178
166
|
response_validators (dict | None, optional): Validators for the response model.
|
179
167
|
frozen_response (bool, optional): Whether the response model is frozen.
|
180
168
|
response_config_dict (dict | None, optional): Configuration dictionary for the response.
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Copyright (c) 2023 - 2024, HaiyangLi <quantocean.li at gmail dot com>
|
2
|
+
#
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
4
|
+
|
5
|
+
from .action import ActionRequestModel, ActionResponseModel
|
6
|
+
from .instruct import Instruct
|
7
|
+
from .operative import Operative
|
8
|
+
from .reason import ReasonModel
|
9
|
+
from .step import Step, StepModel
|
10
|
+
|
11
|
+
__all__: list[str] = [
|
12
|
+
"Operative",
|
13
|
+
"Step",
|
14
|
+
"ActionRequestModel",
|
15
|
+
"ActionResponseModel",
|
16
|
+
"StepModel",
|
17
|
+
"Instruct",
|
18
|
+
"ReasonModel",
|
19
|
+
]
|
lionagi/service/__init__.py
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
from lionagi.integrations.litellm_.imodel import LiteiModel
|
2
|
+
|
1
3
|
from .imodel import iModel
|
2
4
|
from .rate_limiter import RateLimiter, RateLimitError
|
3
5
|
from .service import Service, register_service
|
@@ -10,4 +12,5 @@ __all__ = [
|
|
10
12
|
"RateLimitError",
|
11
13
|
"invoke_retry",
|
12
14
|
"iModel",
|
15
|
+
"LiteiModel",
|
13
16
|
]
|
@@ -19,7 +19,7 @@ def match_service(service_name: str, **kwargs):
|
|
19
19
|
return key1 == key2
|
20
20
|
|
21
21
|
if service_name == "openai":
|
22
|
-
from lionagi.integrations.
|
22
|
+
from lionagi.integrations._services import OpenAIService
|
23
23
|
|
24
24
|
api_key = kwargs.get("api_key")
|
25
25
|
openai_organization = kwargs.get("openai_organization")
|
@@ -44,7 +44,7 @@ def match_service(service_name: str, **kwargs):
|
|
44
44
|
)
|
45
45
|
|
46
46
|
elif service_name == "anthropic":
|
47
|
-
from lionagi.integrations.
|
47
|
+
from lionagi.integrations._services import AnthropicService
|
48
48
|
|
49
49
|
api_key = kwargs.get("api_key")
|
50
50
|
api_version = kwargs.get("api_version", "2023-06-01")
|
@@ -63,7 +63,7 @@ def match_service(service_name: str, **kwargs):
|
|
63
63
|
)
|
64
64
|
|
65
65
|
elif service_name == "perplexity":
|
66
|
-
from lionagi.integrations.
|
66
|
+
from lionagi.integrations._services import PerplexityService
|
67
67
|
|
68
68
|
api_key = kwargs.get("api_key")
|
69
69
|
api_version = kwargs.get("api_version", "2023-06-01")
|
@@ -77,7 +77,7 @@ def match_service(service_name: str, **kwargs):
|
|
77
77
|
return PerplexityService(api_key=api_key)
|
78
78
|
|
79
79
|
elif service_name == "groq":
|
80
|
-
from lionagi.integrations.
|
80
|
+
from lionagi.integrations._services import GroqService
|
81
81
|
|
82
82
|
api_key = kwargs.get("api_key")
|
83
83
|
for service in ServiceSetting.services.values():
|
lionagi/settings.py
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
from datetime import timezone
|
2
2
|
from enum import Enum
|
3
3
|
|
4
|
-
from lionagi.protocols.configs import (
|
4
|
+
from lionagi.protocols.configs.types import (
|
5
5
|
BranchConfig,
|
6
|
-
|
6
|
+
LogConfig,
|
7
7
|
MessageConfig,
|
8
8
|
RetryConfig,
|
9
9
|
TimedFuncCallConfig,
|
10
10
|
iModelConfig,
|
11
11
|
)
|
12
|
-
from lionagi.protocols.configs.log_config import LogConfig
|
13
12
|
|
14
13
|
|
15
14
|
class BaseSystemFields(str, Enum):
|
16
|
-
|
15
|
+
LN_ID = "ln_id"
|
17
16
|
TIMESTAMP = "timestamp"
|
18
17
|
METADATA = "metadata"
|
19
18
|
EXTRA_FIELDS = "extra_fields"
|
@@ -22,15 +21,8 @@ class BaseSystemFields(str, Enum):
|
|
22
21
|
EMBEDDING = "embedding"
|
23
22
|
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
random_hyphen=True,
|
28
|
-
num_hyphens=4,
|
29
|
-
hyphen_start_index=6,
|
30
|
-
hyphen_end_index=-6,
|
31
|
-
prefix="ao",
|
32
|
-
postfix="",
|
33
|
-
)
|
24
|
+
UUID_VERSION = 4
|
25
|
+
|
34
26
|
|
35
27
|
DEFAULT_TIMED_FUNC_CALL_CONFIG = TimedFuncCallConfig(
|
36
28
|
initial_delay=0,
|
@@ -61,7 +53,7 @@ DEFAULT_CHAT_CONFIG = iModelConfig(
|
|
61
53
|
)
|
62
54
|
|
63
55
|
|
64
|
-
|
56
|
+
DEFAULT_PARSE_CONFIG = iModelConfig(
|
65
57
|
provider="openai",
|
66
58
|
task="chat",
|
67
59
|
model="gpt-4o-mini",
|
@@ -109,7 +101,7 @@ DEFAULT_BRANCH_CONFIG = BranchConfig(
|
|
109
101
|
auto_register_tools=True,
|
110
102
|
action_call_config=DEFAULT_TIMED_FUNC_CALL_CONFIG,
|
111
103
|
imodel_config=DEFAULT_CHAT_CONFIG,
|
112
|
-
retry_imodel_config=
|
104
|
+
retry_imodel_config=DEFAULT_PARSE_CONFIG,
|
113
105
|
)
|
114
106
|
|
115
107
|
|
@@ -120,7 +112,7 @@ BASE_LION_FIELDS = set(BaseSystemFields.__members__.values())
|
|
120
112
|
class Settings:
|
121
113
|
|
122
114
|
class Config:
|
123
|
-
|
115
|
+
UUID_VERSION: int = UUID_VERSION
|
124
116
|
RETRY: RetryConfig = DEFAULT_RETRY_CONFIG
|
125
117
|
TIMED_CALL: TimedFuncCallConfig = DEFAULT_TIMED_FUNC_CALL_CONFIG
|
126
118
|
TIMEZONE: timezone = DEFAULT_TIMEZONE
|
@@ -129,8 +121,8 @@ class Settings:
|
|
129
121
|
BRANCH: BranchConfig = DEFAULT_BRANCH_CONFIG
|
130
122
|
|
131
123
|
class iModel:
|
132
|
-
CHAT:
|
133
|
-
PARSE: iModelConfig =
|
124
|
+
CHAT: iModelConfig = DEFAULT_CHAT_CONFIG
|
125
|
+
PARSE: iModelConfig = DEFAULT_PARSE_CONFIG
|
134
126
|
|
135
127
|
|
136
128
|
# File: autoos/setting.py
|
lionagi/strategies/base.py
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
from typing import ClassVar
|
2
2
|
|
3
|
-
from pydantic import model_validator
|
3
|
+
from pydantic import BaseModel, model_validator
|
4
4
|
|
5
|
-
from lionagi.
|
5
|
+
from lionagi.core.session.types import Branch, Session
|
6
|
+
from lionagi.protocols.operatives.instruct import Instruct, InstructResponse
|
6
7
|
|
7
|
-
from ..protocols.types import BaseLionModel
|
8
|
-
from ..session.types import Branch, Session
|
9
8
|
from .params import StrategyParams
|
10
9
|
|
11
10
|
|
12
|
-
class StrategyExecutor(
|
11
|
+
class StrategyExecutor(BaseModel):
|
13
12
|
"""Base class for different execution strategies.
|
14
13
|
|
15
14
|
Each concrete executor should implement `execute()` to run instructions
|
lionagi/strategies/concurrent.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
from lionagi.
|
2
|
-
from lionagi.
|
3
|
-
from lionagi.
|
1
|
+
from lionagi.core.session.types import Branch
|
2
|
+
from lionagi.libs.func.types import alcall
|
3
|
+
from lionagi.libs.parse.types import to_list
|
4
|
+
from lionagi.protocols.operatives.instruct import Instruct, InstructResponse
|
4
5
|
|
5
6
|
from .base import StrategyExecutor
|
6
7
|
|