agentrun-inner-test 0.0.46__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.
- agentrun/__init__.py +325 -0
- agentrun/agent_runtime/__client_async_template.py +466 -0
- agentrun/agent_runtime/__endpoint_async_template.py +345 -0
- agentrun/agent_runtime/__init__.py +53 -0
- agentrun/agent_runtime/__runtime_async_template.py +477 -0
- agentrun/agent_runtime/api/__data_async_template.py +58 -0
- agentrun/agent_runtime/api/__init__.py +6 -0
- agentrun/agent_runtime/api/control.py +1362 -0
- agentrun/agent_runtime/api/data.py +98 -0
- agentrun/agent_runtime/client.py +868 -0
- agentrun/agent_runtime/endpoint.py +649 -0
- agentrun/agent_runtime/model.py +362 -0
- agentrun/agent_runtime/runtime.py +904 -0
- agentrun/credential/__client_async_template.py +177 -0
- agentrun/credential/__credential_async_template.py +216 -0
- agentrun/credential/__init__.py +28 -0
- agentrun/credential/api/__init__.py +5 -0
- agentrun/credential/api/control.py +606 -0
- agentrun/credential/client.py +319 -0
- agentrun/credential/credential.py +381 -0
- agentrun/credential/model.py +248 -0
- agentrun/integration/__init__.py +21 -0
- agentrun/integration/agentscope/__init__.py +12 -0
- agentrun/integration/agentscope/adapter.py +17 -0
- agentrun/integration/agentscope/builtin.py +65 -0
- agentrun/integration/agentscope/message_adapter.py +185 -0
- agentrun/integration/agentscope/model_adapter.py +60 -0
- agentrun/integration/agentscope/tool_adapter.py +59 -0
- agentrun/integration/builtin/__init__.py +16 -0
- agentrun/integration/builtin/model.py +93 -0
- agentrun/integration/builtin/sandbox.py +1234 -0
- agentrun/integration/builtin/toolset.py +47 -0
- agentrun/integration/crewai/__init__.py +12 -0
- agentrun/integration/crewai/adapter.py +9 -0
- agentrun/integration/crewai/builtin.py +65 -0
- agentrun/integration/crewai/model_adapter.py +31 -0
- agentrun/integration/crewai/tool_adapter.py +26 -0
- agentrun/integration/google_adk/__init__.py +12 -0
- agentrun/integration/google_adk/adapter.py +15 -0
- agentrun/integration/google_adk/builtin.py +65 -0
- agentrun/integration/google_adk/message_adapter.py +144 -0
- agentrun/integration/google_adk/model_adapter.py +46 -0
- agentrun/integration/google_adk/tool_adapter.py +235 -0
- agentrun/integration/langchain/__init__.py +30 -0
- agentrun/integration/langchain/adapter.py +15 -0
- agentrun/integration/langchain/builtin.py +71 -0
- agentrun/integration/langchain/message_adapter.py +141 -0
- agentrun/integration/langchain/model_adapter.py +37 -0
- agentrun/integration/langchain/tool_adapter.py +50 -0
- agentrun/integration/langgraph/__init__.py +35 -0
- agentrun/integration/langgraph/adapter.py +20 -0
- agentrun/integration/langgraph/agent_converter.py +1073 -0
- agentrun/integration/langgraph/builtin.py +65 -0
- agentrun/integration/pydantic_ai/__init__.py +12 -0
- agentrun/integration/pydantic_ai/adapter.py +13 -0
- agentrun/integration/pydantic_ai/builtin.py +65 -0
- agentrun/integration/pydantic_ai/model_adapter.py +44 -0
- agentrun/integration/pydantic_ai/tool_adapter.py +19 -0
- agentrun/integration/utils/__init__.py +112 -0
- agentrun/integration/utils/adapter.py +560 -0
- agentrun/integration/utils/canonical.py +164 -0
- agentrun/integration/utils/converter.py +134 -0
- agentrun/integration/utils/model.py +110 -0
- agentrun/integration/utils/tool.py +1759 -0
- agentrun/model/__client_async_template.py +357 -0
- agentrun/model/__init__.py +57 -0
- agentrun/model/__model_proxy_async_template.py +270 -0
- agentrun/model/__model_service_async_template.py +267 -0
- agentrun/model/api/__init__.py +6 -0
- agentrun/model/api/control.py +1173 -0
- agentrun/model/api/data.py +196 -0
- agentrun/model/client.py +674 -0
- agentrun/model/model.py +235 -0
- agentrun/model/model_proxy.py +439 -0
- agentrun/model/model_service.py +438 -0
- agentrun/sandbox/__aio_sandbox_async_template.py +523 -0
- agentrun/sandbox/__browser_sandbox_async_template.py +110 -0
- agentrun/sandbox/__client_async_template.py +491 -0
- agentrun/sandbox/__code_interpreter_sandbox_async_template.py +463 -0
- agentrun/sandbox/__init__.py +69 -0
- agentrun/sandbox/__sandbox_async_template.py +463 -0
- agentrun/sandbox/__template_async_template.py +152 -0
- agentrun/sandbox/aio_sandbox.py +905 -0
- agentrun/sandbox/api/__aio_data_async_template.py +335 -0
- agentrun/sandbox/api/__browser_data_async_template.py +140 -0
- agentrun/sandbox/api/__code_interpreter_data_async_template.py +206 -0
- agentrun/sandbox/api/__init__.py +19 -0
- agentrun/sandbox/api/__sandbox_data_async_template.py +107 -0
- agentrun/sandbox/api/aio_data.py +551 -0
- agentrun/sandbox/api/browser_data.py +172 -0
- agentrun/sandbox/api/code_interpreter_data.py +396 -0
- agentrun/sandbox/api/control.py +1051 -0
- agentrun/sandbox/api/playwright_async.py +492 -0
- agentrun/sandbox/api/playwright_sync.py +492 -0
- agentrun/sandbox/api/sandbox_data.py +154 -0
- agentrun/sandbox/browser_sandbox.py +185 -0
- agentrun/sandbox/client.py +925 -0
- agentrun/sandbox/code_interpreter_sandbox.py +823 -0
- agentrun/sandbox/model.py +397 -0
- agentrun/sandbox/sandbox.py +848 -0
- agentrun/sandbox/template.py +217 -0
- agentrun/server/__init__.py +191 -0
- agentrun/server/agui_normalizer.py +180 -0
- agentrun/server/agui_protocol.py +797 -0
- agentrun/server/invoker.py +309 -0
- agentrun/server/model.py +427 -0
- agentrun/server/openai_protocol.py +535 -0
- agentrun/server/protocol.py +140 -0
- agentrun/server/server.py +208 -0
- agentrun/toolset/__client_async_template.py +62 -0
- agentrun/toolset/__init__.py +51 -0
- agentrun/toolset/__toolset_async_template.py +204 -0
- agentrun/toolset/api/__init__.py +17 -0
- agentrun/toolset/api/control.py +262 -0
- agentrun/toolset/api/mcp.py +100 -0
- agentrun/toolset/api/openapi.py +1251 -0
- agentrun/toolset/client.py +102 -0
- agentrun/toolset/model.py +321 -0
- agentrun/toolset/toolset.py +270 -0
- agentrun/utils/__data_api_async_template.py +720 -0
- agentrun/utils/__init__.py +5 -0
- agentrun/utils/__resource_async_template.py +158 -0
- agentrun/utils/config.py +258 -0
- agentrun/utils/control_api.py +78 -0
- agentrun/utils/data_api.py +1120 -0
- agentrun/utils/exception.py +151 -0
- agentrun/utils/helper.py +108 -0
- agentrun/utils/log.py +77 -0
- agentrun/utils/model.py +168 -0
- agentrun/utils/resource.py +291 -0
- agentrun_inner_test-0.0.46.dist-info/METADATA +263 -0
- agentrun_inner_test-0.0.46.dist-info/RECORD +135 -0
- agentrun_inner_test-0.0.46.dist-info/WHEEL +5 -0
- agentrun_inner_test-0.0.46.dist-info/licenses/LICENSE +201 -0
- agentrun_inner_test-0.0.46.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"""Model Service 高层 API / Model Service High-Level API
|
|
2
|
+
|
|
3
|
+
此模块定义模型服务资源的高级API。
|
|
4
|
+
This module defines the high-level API for model service resources.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import List, Optional
|
|
8
|
+
|
|
9
|
+
from agentrun.model.api.data import BaseInfo, ModelCompletionAPI
|
|
10
|
+
from agentrun.utils.config import Config
|
|
11
|
+
from agentrun.utils.model import PageableInput
|
|
12
|
+
from agentrun.utils.resource import ResourceBase
|
|
13
|
+
|
|
14
|
+
from .model import (
|
|
15
|
+
BackendType,
|
|
16
|
+
ModelServiceCreateInput,
|
|
17
|
+
ModelServiceImmutableProps,
|
|
18
|
+
ModelServiceListInput,
|
|
19
|
+
ModelServiceMutableProps,
|
|
20
|
+
ModelServicesSystemProps,
|
|
21
|
+
ModelServiceUpdateInput,
|
|
22
|
+
ModelType,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ModelService(
|
|
27
|
+
ModelServiceImmutableProps,
|
|
28
|
+
ModelServiceMutableProps,
|
|
29
|
+
ModelServicesSystemProps,
|
|
30
|
+
ResourceBase,
|
|
31
|
+
):
|
|
32
|
+
"""模型服务"""
|
|
33
|
+
|
|
34
|
+
@classmethod
|
|
35
|
+
def __get_client(cls):
|
|
36
|
+
from .client import ModelClient
|
|
37
|
+
|
|
38
|
+
return ModelClient()
|
|
39
|
+
|
|
40
|
+
@classmethod
|
|
41
|
+
async def create_async(
|
|
42
|
+
cls, input: ModelServiceCreateInput, config: Optional[Config] = None
|
|
43
|
+
):
|
|
44
|
+
"""创建模型服务(异步)
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
input: 模型服务输入参数
|
|
48
|
+
config: 配置
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
ModelService: 创建的模型服务对象
|
|
52
|
+
"""
|
|
53
|
+
return await cls.__get_client().create_async(input, config=config)
|
|
54
|
+
|
|
55
|
+
@classmethod
|
|
56
|
+
async def delete_by_name_async(
|
|
57
|
+
cls, model_service_name: str, config: Optional[Config] = None
|
|
58
|
+
):
|
|
59
|
+
"""根据名称删除模型服务(异步)
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
model_service_name: 模型服务名称
|
|
63
|
+
config: 配置
|
|
64
|
+
"""
|
|
65
|
+
return await cls.__get_client().delete_async(
|
|
66
|
+
model_service_name, backend_type=BackendType.SERVICE, config=config
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
@classmethod
|
|
70
|
+
async def update_by_name_async(
|
|
71
|
+
cls,
|
|
72
|
+
model_service_name: str,
|
|
73
|
+
input: ModelServiceUpdateInput,
|
|
74
|
+
config: Optional[Config] = None,
|
|
75
|
+
):
|
|
76
|
+
"""根据名称更新模型服务(异步)
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
model_service_name: 模型服务名称
|
|
80
|
+
input: 模型服务更新输入参数
|
|
81
|
+
config: 配置
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
ModelService: 更新后的模型服务对象
|
|
85
|
+
"""
|
|
86
|
+
return await cls.__get_client().update_async(
|
|
87
|
+
model_service_name, input, config=config
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
@classmethod
|
|
91
|
+
async def get_by_name_async(
|
|
92
|
+
cls, model_service_name: str, config: Optional[Config] = None
|
|
93
|
+
):
|
|
94
|
+
"""根据名称获取模型服务(异步)
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
model_service_name: 模型服务名称
|
|
98
|
+
config: 配置
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
ModelService: 模型服务对象
|
|
102
|
+
"""
|
|
103
|
+
return await cls.__get_client().get_async(
|
|
104
|
+
model_service_name, backend_type=BackendType.SERVICE, config=config
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
@classmethod
|
|
108
|
+
async def _list_page_async(
|
|
109
|
+
cls, page_input: PageableInput, config: Config | None = None, **kwargs
|
|
110
|
+
):
|
|
111
|
+
return await cls.__get_client().list_async(
|
|
112
|
+
input=ModelServiceListInput(
|
|
113
|
+
**kwargs,
|
|
114
|
+
**page_input.model_dump(),
|
|
115
|
+
),
|
|
116
|
+
config=config,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
@classmethod
|
|
120
|
+
async def list_all_async(
|
|
121
|
+
cls,
|
|
122
|
+
*,
|
|
123
|
+
model_type: Optional[ModelType] = None,
|
|
124
|
+
provider: Optional[str] = None,
|
|
125
|
+
config: Optional[Config] = None,
|
|
126
|
+
) -> List["ModelService"]:
|
|
127
|
+
return await cls._list_all_async(
|
|
128
|
+
lambda m: m.model_service_id or "",
|
|
129
|
+
config=config,
|
|
130
|
+
model_type=model_type,
|
|
131
|
+
provider=provider,
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
async def update_async(
|
|
135
|
+
self, input: ModelServiceUpdateInput, config: Optional[Config] = None
|
|
136
|
+
):
|
|
137
|
+
"""更新模型服务(异步)
|
|
138
|
+
|
|
139
|
+
Args:
|
|
140
|
+
input: 模型服务更新输入参数
|
|
141
|
+
config: 配置
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
ModelService: 更新后的模型服务对象
|
|
145
|
+
"""
|
|
146
|
+
if self.model_service_name is None:
|
|
147
|
+
raise ValueError(
|
|
148
|
+
"model_service_name is required to update a ModelService"
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
result = await self.update_by_name_async(
|
|
152
|
+
self.model_service_name, input, config=config
|
|
153
|
+
)
|
|
154
|
+
self.update_self(result)
|
|
155
|
+
|
|
156
|
+
return self
|
|
157
|
+
|
|
158
|
+
async def delete_async(self, config: Optional[Config] = None):
|
|
159
|
+
"""删除模型服务(异步)
|
|
160
|
+
|
|
161
|
+
Args:
|
|
162
|
+
config: 配置
|
|
163
|
+
"""
|
|
164
|
+
if self.model_service_name is None:
|
|
165
|
+
raise ValueError(
|
|
166
|
+
"model_service_name is required to delete a ModelService"
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
return await self.delete_by_name_async(
|
|
170
|
+
self.model_service_name, config=config
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
async def get_async(self, config: Optional[Config] = None):
|
|
174
|
+
"""刷新模型服务信息(异步)
|
|
175
|
+
|
|
176
|
+
Args:
|
|
177
|
+
config: 配置
|
|
178
|
+
|
|
179
|
+
Returns:
|
|
180
|
+
ModelService: 刷新后的模型服务对象
|
|
181
|
+
"""
|
|
182
|
+
if self.model_service_name is None:
|
|
183
|
+
raise ValueError(
|
|
184
|
+
"model_service_name is required to refresh a ModelService"
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
result = await self.get_by_name_async(
|
|
188
|
+
self.model_service_name, config=config
|
|
189
|
+
)
|
|
190
|
+
self.update_self(result)
|
|
191
|
+
|
|
192
|
+
return self
|
|
193
|
+
|
|
194
|
+
async def refresh_async(self, config: Optional[Config] = None):
|
|
195
|
+
"""刷新模型服务信息(异步)
|
|
196
|
+
|
|
197
|
+
Args:
|
|
198
|
+
config: 配置
|
|
199
|
+
|
|
200
|
+
Returns:
|
|
201
|
+
ModelService: 刷新后的模型服务对象
|
|
202
|
+
"""
|
|
203
|
+
return await self.get_async(config=config)
|
|
204
|
+
|
|
205
|
+
def model_info(self, config: Optional[Config] = None) -> BaseInfo:
|
|
206
|
+
cfg = Config.with_configs(self._config, config)
|
|
207
|
+
|
|
208
|
+
assert self.provider_settings is not None
|
|
209
|
+
assert self.provider_settings.base_url is not None
|
|
210
|
+
|
|
211
|
+
api_key = self.provider_settings.api_key or ""
|
|
212
|
+
if not api_key and self.credential_name:
|
|
213
|
+
from agentrun.credential import Credential
|
|
214
|
+
|
|
215
|
+
credential = Credential.get_by_name(
|
|
216
|
+
self.credential_name, config=cfg
|
|
217
|
+
)
|
|
218
|
+
api_key = credential.credential_secret or ""
|
|
219
|
+
|
|
220
|
+
default_model = (
|
|
221
|
+
self.provider_settings.model_names[0]
|
|
222
|
+
if self.provider_settings.model_names is not None
|
|
223
|
+
and len(self.provider_settings.model_names) > 0
|
|
224
|
+
else None
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
return BaseInfo(
|
|
228
|
+
api_key=api_key,
|
|
229
|
+
base_url=self.provider_settings.base_url,
|
|
230
|
+
model=default_model,
|
|
231
|
+
headers=cfg.get_headers(),
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
def completions(
|
|
235
|
+
self,
|
|
236
|
+
messages: list,
|
|
237
|
+
model: Optional[str] = None,
|
|
238
|
+
stream: bool = False,
|
|
239
|
+
**kwargs,
|
|
240
|
+
):
|
|
241
|
+
info = self.model_info(config=kwargs.get("config"))
|
|
242
|
+
|
|
243
|
+
m = ModelCompletionAPI(
|
|
244
|
+
api_key=info.api_key or "",
|
|
245
|
+
base_url=info.base_url or "",
|
|
246
|
+
model=model or info.model or self.model_service_name or "",
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
return m.completions(**kwargs, messages=messages, stream=stream)
|
|
250
|
+
|
|
251
|
+
def responses(
|
|
252
|
+
self,
|
|
253
|
+
messages: list,
|
|
254
|
+
model: Optional[str] = None,
|
|
255
|
+
stream: bool = False,
|
|
256
|
+
**kwargs,
|
|
257
|
+
):
|
|
258
|
+
info = self.model_info(config=kwargs.get("config"))
|
|
259
|
+
|
|
260
|
+
m = ModelCompletionAPI(
|
|
261
|
+
api_key=info.api_key or "",
|
|
262
|
+
base_url=info.base_url or "",
|
|
263
|
+
model=model or info.model or self.model_service_name or "",
|
|
264
|
+
provider=(self.provider or "openai").lower(),
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
return m.responses(**kwargs, messages=messages, stream=stream)
|