agently 4.0.6.7__py3-none-any.whl → 4.0.7__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.
- agently/base.py +3 -5
- agently/builtins/agent_extensions/ConfigurePromptExtension.py +40 -9
- agently/builtins/hookers/SystemMessageHooker.py +51 -7
- agently/builtins/plugins/ModelRequester/OpenAICompatible.py +32 -0
- agently/builtins/plugins/PromptGenerator/AgentlyPromptGenerator.py +64 -1
- agently/builtins/plugins/ResponseParser/AgentlyResponseParser.py +22 -14
- agently/core/Agent.py +67 -27
- agently/core/ModelRequest.py +216 -26
- agently/core/PluginManager.py +2 -0
- agently/core/Prompt.py +15 -45
- agently/core/TriggerFlow/BluePrint.py +2 -0
- agently/core/TriggerFlow/Chunk.py +5 -4
- agently/core/TriggerFlow/Execution.py +29 -12
- agently/core/TriggerFlow/TriggerFlow.py +24 -10
- agently/core/TriggerFlow/process/BaseProcess.py +63 -21
- agently/core/TriggerFlow/process/ForEachProcess.py +30 -24
- agently/core/TriggerFlow/process/MatchCaseProcess.py +6 -6
- agently/integrations/chromadb.py +15 -0
- agently/types/data/response.py +10 -1
- agently/types/plugins/PromptGenerator.py +5 -1
- agently/types/plugins/ResponseParser.py +26 -6
- agently/types/trigger_flow/trigger_flow.py +6 -6
- agently/utils/DataFormatter.py +77 -0
- agently/utils/PythonSandbox.py +101 -0
- agently/utils/Settings.py +19 -2
- agently/utils/__init__.py +1 -0
- {agently-4.0.6.7.dist-info → agently-4.0.7.dist-info}/METADATA +1 -1
- {agently-4.0.6.7.dist-info → agently-4.0.7.dist-info}/RECORD +30 -29
- {agently-4.0.6.7.dist-info → agently-4.0.7.dist-info}/WHEEL +0 -0
- {agently-4.0.6.7.dist-info → agently-4.0.7.dist-info}/licenses/LICENSE +0 -0
agently/core/Agent.py
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
import uuid
|
|
16
|
+
import yaml
|
|
17
|
+
import json
|
|
16
18
|
|
|
17
19
|
from typing import Any, TYPE_CHECKING
|
|
18
20
|
|
|
@@ -64,6 +66,8 @@ class BaseAgent:
|
|
|
64
66
|
self.request_prompt = self.request.prompt
|
|
65
67
|
self.prompt = self.request_prompt
|
|
66
68
|
|
|
69
|
+
self.set_settings = self.settings.set_settings
|
|
70
|
+
|
|
67
71
|
self.get_response = self.request.get_response
|
|
68
72
|
self.get_result = self.request.get_result
|
|
69
73
|
self.get_meta = self.request.get_meta
|
|
@@ -81,17 +85,13 @@ class BaseAgent:
|
|
|
81
85
|
self.async_start = self.async_get_data
|
|
82
86
|
|
|
83
87
|
# Basic Methods
|
|
84
|
-
def set_settings(self, key: str, value: "SerializableValue"):
|
|
85
|
-
self.settings.set_settings(key, value)
|
|
86
|
-
return self
|
|
87
|
-
|
|
88
88
|
def set_agent_prompt(
|
|
89
89
|
self,
|
|
90
90
|
key: "PromptStandardSlot | str",
|
|
91
91
|
value: Any,
|
|
92
92
|
mappings: dict[str, Any] | None = None,
|
|
93
93
|
):
|
|
94
|
-
self.
|
|
94
|
+
self.agent_prompt.set(key, value, mappings)
|
|
95
95
|
return self
|
|
96
96
|
|
|
97
97
|
def set_request_prompt(
|
|
@@ -104,7 +104,7 @@ class BaseAgent:
|
|
|
104
104
|
return self
|
|
105
105
|
|
|
106
106
|
def remove_agent_prompt(self, key: "PromptStandardSlot | str"):
|
|
107
|
-
self.
|
|
107
|
+
self.agent_prompt.set(key, None)
|
|
108
108
|
return self
|
|
109
109
|
|
|
110
110
|
def remove_request_prompt(self, key: "PromptStandardSlot | str"):
|
|
@@ -112,34 +112,34 @@ class BaseAgent:
|
|
|
112
112
|
return self
|
|
113
113
|
|
|
114
114
|
def reset_chat_history(self):
|
|
115
|
-
if "chat_history" in self.
|
|
116
|
-
self.
|
|
115
|
+
if "chat_history" in self.agent_prompt:
|
|
116
|
+
self.agent_prompt.set("chat_history", [])
|
|
117
117
|
return self
|
|
118
118
|
|
|
119
119
|
def set_chat_history(self, chat_history: "list[dict[str, Any] | ChatMessage]"):
|
|
120
120
|
self.reset_chat_history()
|
|
121
121
|
if not isinstance(chat_history, list):
|
|
122
122
|
chat_history = [chat_history]
|
|
123
|
-
self.
|
|
123
|
+
self.agent_prompt.set("chat_history", chat_history)
|
|
124
124
|
return self
|
|
125
125
|
|
|
126
126
|
def add_chat_history(self, chat_history: "list[dict[str, Any] | ChatMessage] | dict[str, Any] | ChatMessage"):
|
|
127
127
|
if not isinstance(chat_history, list):
|
|
128
128
|
chat_history = [chat_history]
|
|
129
|
-
self.
|
|
129
|
+
self.agent_prompt.set("chat_history", chat_history)
|
|
130
130
|
return self
|
|
131
131
|
|
|
132
132
|
def reset_action_results(self):
|
|
133
|
-
if "action_results" in self.
|
|
134
|
-
del self.
|
|
133
|
+
if "action_results" in self.agent_prompt:
|
|
134
|
+
del self.agent_prompt["action_results"]
|
|
135
135
|
return self
|
|
136
136
|
|
|
137
137
|
def set_action_results(self, action_results: list[dict[str, Any]]):
|
|
138
|
-
self.
|
|
138
|
+
self.agent_prompt.set("action_results", action_results)
|
|
139
139
|
return self
|
|
140
140
|
|
|
141
141
|
def add_action_results(self, action: str, result: Any):
|
|
142
|
-
self.
|
|
142
|
+
self.agent_prompt.append("action_results", {action: result})
|
|
143
143
|
return self
|
|
144
144
|
|
|
145
145
|
# Quick Prompt
|
|
@@ -151,7 +151,7 @@ class BaseAgent:
|
|
|
151
151
|
always: bool = False,
|
|
152
152
|
):
|
|
153
153
|
if always:
|
|
154
|
-
self.
|
|
154
|
+
self.agent_prompt.set("input", prompt, mappings)
|
|
155
155
|
else:
|
|
156
156
|
self.request.prompt.set("input", prompt, mappings)
|
|
157
157
|
return self
|
|
@@ -164,8 +164,8 @@ class BaseAgent:
|
|
|
164
164
|
always: bool = False,
|
|
165
165
|
):
|
|
166
166
|
if always:
|
|
167
|
-
self.
|
|
168
|
-
self.
|
|
167
|
+
self.agent_prompt.set("instruct", ["{system.rule} ARE IMPORTANT RULES YOU SHALL FOLLOW!"])
|
|
168
|
+
self.agent_prompt.set("system.rule", prompt, mappings)
|
|
169
169
|
else:
|
|
170
170
|
self.request.prompt.set("instruct", ["{system.rule} ARE IMPORTANT RULES YOU SHALL FOLLOW!"])
|
|
171
171
|
self.request.prompt.set("system.rule", prompt, mappings)
|
|
@@ -179,8 +179,8 @@ class BaseAgent:
|
|
|
179
179
|
always: bool = False,
|
|
180
180
|
):
|
|
181
181
|
if always:
|
|
182
|
-
self.
|
|
183
|
-
self.
|
|
182
|
+
self.agent_prompt.set("instruct", ["YOU MUST REACT AND RESPOND AS {system.role}!"])
|
|
183
|
+
self.agent_prompt.set("system.your_role", prompt, mappings)
|
|
184
184
|
else:
|
|
185
185
|
self.request.prompt.set("instruct", ["YOU MUST REACT AND RESPOND AS {system.role}!"])
|
|
186
186
|
self.request.prompt.set("system.your_role", prompt, mappings)
|
|
@@ -194,8 +194,8 @@ class BaseAgent:
|
|
|
194
194
|
always: bool = False,
|
|
195
195
|
):
|
|
196
196
|
if always:
|
|
197
|
-
self.
|
|
198
|
-
self.
|
|
197
|
+
self.agent_prompt.set("instruct", ["{system.user_info} IS IMPORTANT INFORMATION ABOUT USER!"])
|
|
198
|
+
self.agent_prompt.set("system.user_info", prompt, mappings)
|
|
199
199
|
else:
|
|
200
200
|
self.request.prompt.set("instruct", ["{system.user_info} IS IMPORTANT INFORMATION ABOUT USER!"])
|
|
201
201
|
self.request.prompt.set("system.user_info", prompt, mappings)
|
|
@@ -209,7 +209,7 @@ class BaseAgent:
|
|
|
209
209
|
always: bool = False,
|
|
210
210
|
):
|
|
211
211
|
if always:
|
|
212
|
-
self.
|
|
212
|
+
self.agent_prompt.set("input", prompt, mappings)
|
|
213
213
|
else:
|
|
214
214
|
self.request.prompt.set("input", prompt, mappings)
|
|
215
215
|
return self
|
|
@@ -222,7 +222,7 @@ class BaseAgent:
|
|
|
222
222
|
always: bool = False,
|
|
223
223
|
):
|
|
224
224
|
if always:
|
|
225
|
-
self.
|
|
225
|
+
self.agent_prompt.set("info", prompt, mappings)
|
|
226
226
|
else:
|
|
227
227
|
self.request.prompt.set("info", prompt, mappings)
|
|
228
228
|
return self
|
|
@@ -235,7 +235,7 @@ class BaseAgent:
|
|
|
235
235
|
always: bool = False,
|
|
236
236
|
):
|
|
237
237
|
if always:
|
|
238
|
-
self.
|
|
238
|
+
self.agent_prompt.set("instruct", prompt, mappings)
|
|
239
239
|
else:
|
|
240
240
|
self.request.prompt.set("instruct", prompt, mappings)
|
|
241
241
|
return self
|
|
@@ -248,7 +248,7 @@ class BaseAgent:
|
|
|
248
248
|
always: bool = False,
|
|
249
249
|
):
|
|
250
250
|
if always:
|
|
251
|
-
self.
|
|
251
|
+
self.agent_prompt.set("examples", prompt, mappings)
|
|
252
252
|
else:
|
|
253
253
|
self.request.prompt.set("examples", prompt, mappings)
|
|
254
254
|
return self
|
|
@@ -266,11 +266,24 @@ class BaseAgent:
|
|
|
266
266
|
always: bool = False,
|
|
267
267
|
):
|
|
268
268
|
if always:
|
|
269
|
-
self.
|
|
269
|
+
self.agent_prompt.set("output", prompt, mappings)
|
|
270
270
|
else:
|
|
271
271
|
self.request.prompt.set("output", prompt, mappings)
|
|
272
272
|
return self
|
|
273
273
|
|
|
274
|
+
def attachment(
|
|
275
|
+
self,
|
|
276
|
+
prompt: list[dict[str, Any]],
|
|
277
|
+
mappings: dict[str, Any] | None = None,
|
|
278
|
+
*,
|
|
279
|
+
always: bool = False,
|
|
280
|
+
):
|
|
281
|
+
if always:
|
|
282
|
+
self.agent_prompt.set("attachment", prompt, mappings)
|
|
283
|
+
else:
|
|
284
|
+
self.request_prompt.set("attachment", prompt, mappings)
|
|
285
|
+
return self
|
|
286
|
+
|
|
274
287
|
def options(
|
|
275
288
|
self,
|
|
276
289
|
options: dict[str, Any],
|
|
@@ -278,7 +291,34 @@ class BaseAgent:
|
|
|
278
291
|
always: bool = False,
|
|
279
292
|
):
|
|
280
293
|
if always:
|
|
281
|
-
self.
|
|
294
|
+
self.agent_prompt.set("options", options)
|
|
282
295
|
else:
|
|
283
296
|
self.request.prompt.set("options", options)
|
|
284
297
|
return self
|
|
298
|
+
|
|
299
|
+
# Prompt
|
|
300
|
+
def get_prompt_text(self):
|
|
301
|
+
return self.request_prompt.to_text()[6:][:-11]
|
|
302
|
+
|
|
303
|
+
def get_json_prompt(self):
|
|
304
|
+
prompt_data = {
|
|
305
|
+
".agent": self.agent_prompt.to_serializable_prompt_data(),
|
|
306
|
+
".request": self.request_prompt.to_serializable_prompt_data(),
|
|
307
|
+
}
|
|
308
|
+
return json.dumps(
|
|
309
|
+
prompt_data,
|
|
310
|
+
indent=2,
|
|
311
|
+
ensure_ascii=False,
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
def get_yaml_prompt(self):
|
|
315
|
+
prompt_data = {
|
|
316
|
+
".agent": self.agent_prompt.to_serializable_prompt_data(),
|
|
317
|
+
".request": self.request_prompt.to_serializable_prompt_data(),
|
|
318
|
+
}
|
|
319
|
+
return yaml.safe_dump(
|
|
320
|
+
prompt_data,
|
|
321
|
+
indent=2,
|
|
322
|
+
allow_unicode=True,
|
|
323
|
+
sort_keys=False,
|
|
324
|
+
)
|
agently/core/ModelRequest.py
CHANGED
|
@@ -22,12 +22,13 @@ ContentKindTuple: TypeAlias = Literal["all", "delta", "original"]
|
|
|
22
22
|
ContentKindStreaming: TypeAlias = Literal["instant", "streaming_parse"]
|
|
23
23
|
|
|
24
24
|
from agently.core import Prompt, ExtensionHandlers
|
|
25
|
-
from agently.utils import Settings, FunctionShifter, DataFormatter
|
|
25
|
+
from agently.utils import Settings, FunctionShifter, DataFormatter, DataLocator
|
|
26
26
|
|
|
27
27
|
if TYPE_CHECKING:
|
|
28
28
|
from agently.core import PluginManager
|
|
29
29
|
from agently.types.data import AgentlyModelResponseMessage, PromptStandardSlot, StreamingData, SerializableValue
|
|
30
30
|
from agently.types.plugins import ModelRequester, ResponseParser
|
|
31
|
+
from pydantic import BaseModel
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
class ModelResponseResult:
|
|
@@ -39,6 +40,7 @@ class ModelResponseResult:
|
|
|
39
40
|
response_generator: AsyncGenerator["AgentlyModelResponseMessage", None],
|
|
40
41
|
plugin_manager: "PluginManager",
|
|
41
42
|
settings: Settings,
|
|
43
|
+
extension_handlers: ExtensionHandlers,
|
|
42
44
|
):
|
|
43
45
|
self.agent_name = agent_name
|
|
44
46
|
self.plugin_manager = plugin_manager
|
|
@@ -50,19 +52,145 @@ class ModelResponseResult:
|
|
|
50
52
|
str(self.settings["plugins.ResponseParser.activate"]),
|
|
51
53
|
),
|
|
52
54
|
)
|
|
53
|
-
|
|
55
|
+
self._response_id = response_id
|
|
56
|
+
self._extension_handlers = extension_handlers
|
|
57
|
+
self._response_parser = ResponseParser(agent_name, response_id, prompt, response_generator, self.settings)
|
|
54
58
|
self.prompt = prompt
|
|
55
|
-
self.full_result_data = _response_parser.full_result_data
|
|
56
|
-
self.get_meta = _response_parser.get_meta
|
|
57
|
-
self.async_get_meta = _response_parser.async_get_meta
|
|
58
|
-
self.get_text = _response_parser.get_text
|
|
59
|
-
self.async_get_text = _response_parser.async_get_text
|
|
60
|
-
self.get_data = _response_parser.get_data
|
|
61
|
-
self.async_get_data = _response_parser.async_get_data
|
|
62
|
-
self.get_data_object = _response_parser.get_data_object
|
|
63
|
-
self.async_get_data_object = _response_parser.async_get_data_object
|
|
64
|
-
self.
|
|
65
|
-
self.
|
|
59
|
+
self.full_result_data = self._response_parser.full_result_data
|
|
60
|
+
self.get_meta = self._response_parser.get_meta
|
|
61
|
+
self.async_get_meta = self._response_parser.async_get_meta
|
|
62
|
+
self.get_text = self._response_parser.get_text
|
|
63
|
+
self.async_get_text = self._response_parser.async_get_text
|
|
64
|
+
# self.get_data = self._response_parser.get_data
|
|
65
|
+
# self.async_get_data = self._response_parser.async_get_data
|
|
66
|
+
# self.get_data_object = self._response_parser.get_data_object
|
|
67
|
+
# self.async_get_data_object = self._response_parser.async_get_data_object
|
|
68
|
+
self.get_data = FunctionShifter.syncify(self.async_get_data)
|
|
69
|
+
self.get_data_object = FunctionShifter.syncify(self.async_get_data_object)
|
|
70
|
+
self.get_generator = self._response_parser.get_generator
|
|
71
|
+
self.get_async_generator = self._response_parser.get_async_generator
|
|
72
|
+
|
|
73
|
+
@overload
|
|
74
|
+
async def async_get_data(
|
|
75
|
+
self,
|
|
76
|
+
*,
|
|
77
|
+
type: Literal['parsed'],
|
|
78
|
+
ensure_keys: list[str],
|
|
79
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
80
|
+
max_retries: int = 3,
|
|
81
|
+
raise_ensure_failure: bool = True,
|
|
82
|
+
_retry_count: int = 0,
|
|
83
|
+
) -> dict[str, Any]: ...
|
|
84
|
+
|
|
85
|
+
@overload
|
|
86
|
+
async def async_get_data(
|
|
87
|
+
self,
|
|
88
|
+
*,
|
|
89
|
+
type: Literal['original', 'parsed', 'all'] = "parsed",
|
|
90
|
+
ensure_keys: list[str] | None = None,
|
|
91
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
92
|
+
max_retries: int = 3,
|
|
93
|
+
raise_ensure_failure: bool = True,
|
|
94
|
+
_retry_count: int = 0,
|
|
95
|
+
) -> Any: ...
|
|
96
|
+
|
|
97
|
+
async def async_get_data(
|
|
98
|
+
self,
|
|
99
|
+
*,
|
|
100
|
+
type: Literal['original', 'parsed', 'all'] = "parsed",
|
|
101
|
+
ensure_keys: list[str] | None = None,
|
|
102
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
103
|
+
max_retries: int = 3,
|
|
104
|
+
raise_ensure_failure: bool = True,
|
|
105
|
+
_retry_count: int = 0,
|
|
106
|
+
) -> Any:
|
|
107
|
+
if type == "parsed" and ensure_keys:
|
|
108
|
+
try:
|
|
109
|
+
data = await self._response_parser.async_get_data(type=type)
|
|
110
|
+
for ensure_key in ensure_keys:
|
|
111
|
+
EMPTY = object()
|
|
112
|
+
if DataLocator.locate_path_in_dict(data, ensure_key, key_style, default=EMPTY) is EMPTY:
|
|
113
|
+
raise
|
|
114
|
+
return data
|
|
115
|
+
except:
|
|
116
|
+
from agently.base import async_system_message
|
|
117
|
+
|
|
118
|
+
await async_system_message(
|
|
119
|
+
"MODEL_REQUEST",
|
|
120
|
+
{
|
|
121
|
+
"agent_name": self.agent_name,
|
|
122
|
+
"response_id": self._response_id,
|
|
123
|
+
"content": {
|
|
124
|
+
"stage": "No Target Data in Response, Preparing Retry",
|
|
125
|
+
"detail": f"\n[Response]: { await self.async_get_text() }\n"
|
|
126
|
+
f"[Retried Times]: { _retry_count }",
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
self.settings,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
if _retry_count < max_retries:
|
|
133
|
+
return await ModelResponse(
|
|
134
|
+
self.agent_name,
|
|
135
|
+
self.plugin_manager,
|
|
136
|
+
self.settings,
|
|
137
|
+
self.prompt,
|
|
138
|
+
self._extension_handlers,
|
|
139
|
+
).result.async_get_data(
|
|
140
|
+
type=type,
|
|
141
|
+
ensure_keys=ensure_keys,
|
|
142
|
+
key_style=key_style,
|
|
143
|
+
max_retries=max_retries,
|
|
144
|
+
raise_ensure_failure=raise_ensure_failure,
|
|
145
|
+
_retry_count=_retry_count + 1,
|
|
146
|
+
)
|
|
147
|
+
else:
|
|
148
|
+
if raise_ensure_failure:
|
|
149
|
+
raise ValueError(
|
|
150
|
+
f"Can not generate ensure keys { ensure_keys } within { max_retries } retires."
|
|
151
|
+
)
|
|
152
|
+
else:
|
|
153
|
+
return await self._response_parser.async_get_data(type=type)
|
|
154
|
+
return await self._response_parser.async_get_data(type=type)
|
|
155
|
+
|
|
156
|
+
@overload
|
|
157
|
+
async def async_get_data_object(
|
|
158
|
+
self,
|
|
159
|
+
*,
|
|
160
|
+
ensure_keys: list[str],
|
|
161
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
162
|
+
max_retries: int = 3,
|
|
163
|
+
raise_ensure_failure: bool = True,
|
|
164
|
+
) -> "BaseModel": ...
|
|
165
|
+
|
|
166
|
+
@overload
|
|
167
|
+
async def async_get_data_object(
|
|
168
|
+
self,
|
|
169
|
+
*,
|
|
170
|
+
ensure_keys: None,
|
|
171
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
172
|
+
max_retries: int = 3,
|
|
173
|
+
raise_ensure_failure: bool = True,
|
|
174
|
+
) -> "BaseModel | None": ...
|
|
175
|
+
|
|
176
|
+
async def async_get_data_object(
|
|
177
|
+
self,
|
|
178
|
+
*,
|
|
179
|
+
ensure_keys: list[str] | None = None,
|
|
180
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
181
|
+
max_retries: int = 3,
|
|
182
|
+
raise_ensure_failure: bool = True,
|
|
183
|
+
):
|
|
184
|
+
if ensure_keys:
|
|
185
|
+
await self.async_get_data(
|
|
186
|
+
ensure_keys=ensure_keys,
|
|
187
|
+
key_style=key_style,
|
|
188
|
+
max_retries=max_retries,
|
|
189
|
+
_retry_count=0,
|
|
190
|
+
raise_ensure_failure=raise_ensure_failure,
|
|
191
|
+
)
|
|
192
|
+
return await self._response_parser.async_get_data_object()
|
|
193
|
+
return await self._response_parser.async_get_data_object()
|
|
66
194
|
|
|
67
195
|
|
|
68
196
|
class ModelResponse:
|
|
@@ -98,6 +226,7 @@ class ModelResponse:
|
|
|
98
226
|
self._get_response_generator(),
|
|
99
227
|
self.plugin_manager,
|
|
100
228
|
self.settings,
|
|
229
|
+
self.extension_handlers,
|
|
101
230
|
)
|
|
102
231
|
self.get_meta = self.result.get_meta
|
|
103
232
|
self.async_get_meta = self.result.async_get_meta
|
|
@@ -296,13 +425,15 @@ class ModelRequest:
|
|
|
296
425
|
parent=parent_extension_handlers,
|
|
297
426
|
)
|
|
298
427
|
|
|
428
|
+
self.set_settings = self.settings.set_settings
|
|
429
|
+
|
|
299
430
|
self.get_meta = FunctionShifter.syncify(self.async_get_meta)
|
|
300
431
|
self.get_text = FunctionShifter.syncify(self.async_get_text)
|
|
301
432
|
self.get_data = FunctionShifter.syncify(self.async_get_data)
|
|
302
433
|
self.get_data_object = FunctionShifter.syncify(self.async_get_data_object)
|
|
303
434
|
|
|
304
|
-
|
|
305
|
-
self.
|
|
435
|
+
self.start = self.get_data
|
|
436
|
+
self.async_start = self.async_get_data
|
|
306
437
|
|
|
307
438
|
def set_prompt(
|
|
308
439
|
self,
|
|
@@ -394,6 +525,15 @@ class ModelRequest:
|
|
|
394
525
|
self.prompt.set("output", prompt, mappings)
|
|
395
526
|
return self
|
|
396
527
|
|
|
528
|
+
def attachment(
|
|
529
|
+
self,
|
|
530
|
+
prompt: list[dict[str, Any]],
|
|
531
|
+
mappings: dict[str, Any] | None = None,
|
|
532
|
+
):
|
|
533
|
+
self.prompt.set("attachment", prompt, mappings)
|
|
534
|
+
return self
|
|
535
|
+
|
|
536
|
+
# Response & Result
|
|
397
537
|
def get_response(self):
|
|
398
538
|
response = ModelResponse(
|
|
399
539
|
self.agent_name,
|
|
@@ -418,68 +558,118 @@ class ModelRequest:
|
|
|
418
558
|
self,
|
|
419
559
|
*,
|
|
420
560
|
type: Literal['original', 'parsed', 'all'] = "parsed",
|
|
561
|
+
ensure_keys: list[str] | None = None,
|
|
562
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
563
|
+
max_retries: int = 3,
|
|
564
|
+
raise_ensure_failure: bool = True,
|
|
421
565
|
):
|
|
422
|
-
|
|
566
|
+
response = self.get_response()
|
|
567
|
+
return await response.async_get_data(
|
|
568
|
+
type=type,
|
|
569
|
+
ensure_keys=ensure_keys,
|
|
570
|
+
key_style=key_style,
|
|
571
|
+
max_retries=max_retries,
|
|
572
|
+
raise_ensure_failure=raise_ensure_failure,
|
|
573
|
+
)
|
|
423
574
|
|
|
424
|
-
async def async_get_data_object(
|
|
425
|
-
|
|
575
|
+
async def async_get_data_object(
|
|
576
|
+
self,
|
|
577
|
+
*,
|
|
578
|
+
ensure_keys: list[str] | None = None,
|
|
579
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
580
|
+
max_retries: int = 3,
|
|
581
|
+
raise_ensure_failure: bool = True,
|
|
582
|
+
):
|
|
583
|
+
response = self.get_response()
|
|
584
|
+
return await response.async_get_data_object(
|
|
585
|
+
ensure_keys=ensure_keys,
|
|
586
|
+
key_style=key_style,
|
|
587
|
+
max_retries=max_retries,
|
|
588
|
+
raise_ensure_failure=raise_ensure_failure,
|
|
589
|
+
)
|
|
426
590
|
|
|
427
591
|
@overload
|
|
428
592
|
def get_generator(
|
|
429
593
|
self,
|
|
430
594
|
type: Literal["instant", "streaming_parse"],
|
|
595
|
+
*,
|
|
596
|
+
specific: list[str] | str | None = ["reasoning_delta", "delta", "reasoning_done", "done", "tool_calls"],
|
|
431
597
|
) -> Generator["StreamingData", None, None]: ...
|
|
432
598
|
|
|
433
599
|
@overload
|
|
434
600
|
def get_generator(
|
|
435
601
|
self,
|
|
436
602
|
type: Literal["all"],
|
|
603
|
+
*,
|
|
604
|
+
specific: list[str] | str | None = ["reasoning_delta", "delta", "reasoning_done", "done", "tool_calls"],
|
|
437
605
|
) -> Generator[tuple[str, Any], None, None]: ...
|
|
438
606
|
|
|
439
607
|
@overload
|
|
440
608
|
def get_generator(
|
|
441
609
|
self,
|
|
442
|
-
type: Literal["delta", "
|
|
610
|
+
type: Literal["delta", "specific", "original"],
|
|
611
|
+
*,
|
|
612
|
+
specific: list[str] | str | None = ["reasoning_delta", "delta", "reasoning_done", "done", "tool_calls"],
|
|
443
613
|
) -> Generator[str, None, None]: ...
|
|
444
614
|
|
|
445
615
|
@overload
|
|
446
616
|
def get_generator(
|
|
447
617
|
self,
|
|
448
|
-
type: Literal["all", "original", "delta", "
|
|
618
|
+
type: Literal["all", "original", "delta", "specific", "instant", "streaming_parse"] | None = "delta",
|
|
619
|
+
*,
|
|
620
|
+
specific: list[str] | str | None = ["reasoning_delta", "delta", "reasoning_done", "done", "tool_calls"],
|
|
449
621
|
) -> Generator: ...
|
|
450
622
|
|
|
451
623
|
def get_generator(
|
|
452
624
|
self,
|
|
453
|
-
type: Literal["all", "original", "delta", "
|
|
625
|
+
type: Literal["all", "original", "delta", "specific", "instant", "streaming_parse"] | None = "delta",
|
|
626
|
+
*,
|
|
627
|
+
specific: list[str] | str | None = ["reasoning_delta", "delta", "reasoning_done", "done", "tool_calls"],
|
|
454
628
|
) -> Generator:
|
|
455
|
-
return self.get_response().get_generator(
|
|
629
|
+
return self.get_response().get_generator(
|
|
630
|
+
type=type,
|
|
631
|
+
specific=specific,
|
|
632
|
+
)
|
|
456
633
|
|
|
457
634
|
@overload
|
|
458
635
|
def get_async_generator(
|
|
459
636
|
self,
|
|
460
637
|
type: Literal["instant", "streaming_parse"],
|
|
638
|
+
*,
|
|
639
|
+
specific: list[str] | str | None = ["reasoning_delta", "delta", "reasoning_done", "done", "tool_calls"],
|
|
461
640
|
) -> AsyncGenerator["StreamingData", None]: ...
|
|
462
641
|
|
|
463
642
|
@overload
|
|
464
643
|
def get_async_generator(
|
|
465
644
|
self,
|
|
466
645
|
type: Literal["all"],
|
|
646
|
+
*,
|
|
647
|
+
specific: list[str] | str | None = ["reasoning_delta", "delta", "reasoning_done", "done", "tool_calls"],
|
|
467
648
|
) -> AsyncGenerator[tuple[str, Any], None]: ...
|
|
468
649
|
|
|
469
650
|
@overload
|
|
470
651
|
def get_async_generator(
|
|
471
652
|
self,
|
|
472
|
-
type: Literal["delta", "
|
|
653
|
+
type: Literal["delta", "specific", "original"],
|
|
654
|
+
*,
|
|
655
|
+
specific: list[str] | str | None = ["reasoning_delta", "delta", "reasoning_done", "done", "tool_calls"],
|
|
473
656
|
) -> AsyncGenerator[str, None]: ...
|
|
474
657
|
|
|
475
658
|
@overload
|
|
476
659
|
def get_async_generator(
|
|
477
660
|
self,
|
|
478
|
-
type: Literal["all", "original", "delta", "
|
|
661
|
+
type: Literal["all", "original", "delta", "specific", "instant", "streaming_parse"] | None = "delta",
|
|
662
|
+
*,
|
|
663
|
+
specific: list[str] | str | None = ["reasoning_delta", "delta", "reasoning_done", "done", "tool_calls"],
|
|
479
664
|
) -> AsyncGenerator: ...
|
|
480
665
|
|
|
481
666
|
def get_async_generator(
|
|
482
667
|
self,
|
|
483
|
-
type: Literal["all", "original", "delta", "
|
|
668
|
+
type: Literal["all", "original", "delta", "specific", "instant", "streaming_parse"] | None = "delta",
|
|
669
|
+
*,
|
|
670
|
+
specific: list[str] | str | None = ["reasoning_delta", "delta", "reasoning_done", "done", "tool_calls"],
|
|
484
671
|
) -> AsyncGenerator:
|
|
485
|
-
return self.get_response().get_async_generator(
|
|
672
|
+
return self.get_response().get_async_generator(
|
|
673
|
+
type=type,
|
|
674
|
+
specific=specific,
|
|
675
|
+
)
|