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,357 @@
|
|
|
1
|
+
"""Model Service 客户端 / Model Service Client
|
|
2
|
+
|
|
3
|
+
此模块提供模型服务和模型代理的客户端API。
|
|
4
|
+
This module provides the client API for model services and model proxies.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import List, Literal, Optional, overload, Union
|
|
8
|
+
|
|
9
|
+
from alibabacloud_agentrun20250910.models import (
|
|
10
|
+
CreateModelProxyInput,
|
|
11
|
+
CreateModelServiceInput,
|
|
12
|
+
ListModelProxiesRequest,
|
|
13
|
+
ListModelServicesRequest,
|
|
14
|
+
UpdateModelProxyInput,
|
|
15
|
+
UpdateModelServiceInput,
|
|
16
|
+
)
|
|
17
|
+
import pydash
|
|
18
|
+
|
|
19
|
+
from agentrun.utils.config import Config
|
|
20
|
+
from agentrun.utils.exception import HTTPError
|
|
21
|
+
|
|
22
|
+
from .api.control import ModelControlAPI
|
|
23
|
+
from .model import (
|
|
24
|
+
BackendType,
|
|
25
|
+
ModelProxyCreateInput,
|
|
26
|
+
ModelProxyListInput,
|
|
27
|
+
ModelProxyUpdateInput,
|
|
28
|
+
ModelServiceCreateInput,
|
|
29
|
+
ModelServiceListInput,
|
|
30
|
+
ModelServiceUpdateInput,
|
|
31
|
+
ProxyMode,
|
|
32
|
+
)
|
|
33
|
+
from .model_proxy import ModelProxy
|
|
34
|
+
from .model_service import ModelService
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class ModelClient:
|
|
38
|
+
"""Model Service 客户端 / Model Service Client
|
|
39
|
+
|
|
40
|
+
提供模型服务和模型代理的创建、删除、更新和查询功能。
|
|
41
|
+
Provides create, delete, update and query functions for model services and model proxies.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
def __init__(self, config: Optional[Config] = None):
|
|
45
|
+
"""初始化客户端 / Initialize client
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
config: 配置对象,可选 / Configuration object, optional
|
|
49
|
+
"""
|
|
50
|
+
self.__control_api = ModelControlAPI(config)
|
|
51
|
+
|
|
52
|
+
@overload
|
|
53
|
+
async def create_async(
|
|
54
|
+
self, input: ModelServiceCreateInput, config: Optional[Config] = None
|
|
55
|
+
) -> ModelService:
|
|
56
|
+
...
|
|
57
|
+
|
|
58
|
+
@overload
|
|
59
|
+
async def create_async(
|
|
60
|
+
self, input: ModelProxyCreateInput, config: Optional[Config] = None
|
|
61
|
+
) -> ModelProxy:
|
|
62
|
+
...
|
|
63
|
+
|
|
64
|
+
async def create_async(
|
|
65
|
+
self,
|
|
66
|
+
input: Union[ModelServiceCreateInput, ModelProxyCreateInput],
|
|
67
|
+
config: Optional[Config] = None,
|
|
68
|
+
):
|
|
69
|
+
"""创建模型服务(异步)
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
input: 模型服务输入参数
|
|
73
|
+
config: 配置
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
model: 创建的对象
|
|
77
|
+
"""
|
|
78
|
+
try:
|
|
79
|
+
if isinstance(input, ModelProxyCreateInput):
|
|
80
|
+
if not input.proxy_mode:
|
|
81
|
+
input.proxy_mode = (
|
|
82
|
+
ProxyMode.MULTI
|
|
83
|
+
if len(pydash.get(input, "proxy_config.endpoints", []))
|
|
84
|
+
> 1
|
|
85
|
+
else ProxyMode.SINGLE
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
result = await self.__control_api.create_model_proxy_async(
|
|
89
|
+
CreateModelProxyInput().from_map(input.model_dump()),
|
|
90
|
+
config=config,
|
|
91
|
+
)
|
|
92
|
+
return ModelProxy.from_inner_object(result)
|
|
93
|
+
else:
|
|
94
|
+
result = await self.__control_api.create_model_service_async(
|
|
95
|
+
CreateModelServiceInput().from_map(input.model_dump()),
|
|
96
|
+
config=config,
|
|
97
|
+
)
|
|
98
|
+
return ModelService.from_inner_object(result)
|
|
99
|
+
except HTTPError as e:
|
|
100
|
+
raise e.to_resource_error(
|
|
101
|
+
"Model",
|
|
102
|
+
(
|
|
103
|
+
input.model_proxy_name
|
|
104
|
+
if isinstance(input, ModelProxyCreateInput)
|
|
105
|
+
else input.model_service_name
|
|
106
|
+
),
|
|
107
|
+
) from e
|
|
108
|
+
|
|
109
|
+
@overload
|
|
110
|
+
async def delete_async(
|
|
111
|
+
self,
|
|
112
|
+
name: str,
|
|
113
|
+
backend_type: Literal[BackendType.PROXY],
|
|
114
|
+
config: Optional[Config] = None,
|
|
115
|
+
) -> ModelProxy:
|
|
116
|
+
...
|
|
117
|
+
|
|
118
|
+
@overload
|
|
119
|
+
async def delete_async(
|
|
120
|
+
self,
|
|
121
|
+
name: str,
|
|
122
|
+
backend_type: Literal[BackendType.SERVICE],
|
|
123
|
+
config: Optional[Config] = None,
|
|
124
|
+
) -> ModelService:
|
|
125
|
+
...
|
|
126
|
+
|
|
127
|
+
@overload
|
|
128
|
+
async def delete_async(
|
|
129
|
+
self,
|
|
130
|
+
name: str,
|
|
131
|
+
backend_type: None = None,
|
|
132
|
+
config: Optional[Config] = None,
|
|
133
|
+
) -> Union[ModelProxy, ModelService]:
|
|
134
|
+
...
|
|
135
|
+
|
|
136
|
+
async def delete_async(
|
|
137
|
+
self,
|
|
138
|
+
name: str,
|
|
139
|
+
backend_type: Optional[BackendType] = None,
|
|
140
|
+
config: Optional[Config] = None,
|
|
141
|
+
):
|
|
142
|
+
"""删除模型服务(异步)
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
model_service_name: 模型服务名称
|
|
146
|
+
config: 配置
|
|
147
|
+
|
|
148
|
+
Raises:
|
|
149
|
+
ResourceNotExistError: 模型服务不存在
|
|
150
|
+
"""
|
|
151
|
+
|
|
152
|
+
error: Optional[HTTPError] = None
|
|
153
|
+
if backend_type == BackendType.PROXY or backend_type is None:
|
|
154
|
+
try:
|
|
155
|
+
result = await self.__control_api.delete_model_proxy_async(
|
|
156
|
+
model_proxy_name=name, config=config
|
|
157
|
+
)
|
|
158
|
+
return ModelProxy.from_inner_object(result)
|
|
159
|
+
except HTTPError as e:
|
|
160
|
+
error = e
|
|
161
|
+
|
|
162
|
+
if backend_type == BackendType.PROXY and error is not None:
|
|
163
|
+
raise error.to_resource_error("Model", name) from error
|
|
164
|
+
|
|
165
|
+
try:
|
|
166
|
+
result = await self.__control_api.delete_model_service_async(
|
|
167
|
+
model_service_name=name, config=config
|
|
168
|
+
)
|
|
169
|
+
return ModelService.from_inner_object(result)
|
|
170
|
+
except HTTPError as e:
|
|
171
|
+
raise e.to_resource_error("Model", name) from error
|
|
172
|
+
|
|
173
|
+
@overload
|
|
174
|
+
async def update_async(
|
|
175
|
+
self,
|
|
176
|
+
name: str,
|
|
177
|
+
input: ModelServiceUpdateInput,
|
|
178
|
+
config: Optional[Config] = None,
|
|
179
|
+
) -> ModelService:
|
|
180
|
+
...
|
|
181
|
+
|
|
182
|
+
@overload
|
|
183
|
+
async def update_async(
|
|
184
|
+
self,
|
|
185
|
+
name: str,
|
|
186
|
+
input: ModelProxyUpdateInput,
|
|
187
|
+
config: Optional[Config] = None,
|
|
188
|
+
) -> ModelProxy:
|
|
189
|
+
...
|
|
190
|
+
|
|
191
|
+
async def update_async(
|
|
192
|
+
self,
|
|
193
|
+
name: str,
|
|
194
|
+
input: Union[ModelServiceUpdateInput, ModelProxyUpdateInput],
|
|
195
|
+
config: Optional[Config] = None,
|
|
196
|
+
):
|
|
197
|
+
"""更新模型服务(异步)
|
|
198
|
+
|
|
199
|
+
Args:
|
|
200
|
+
model_service_name: 模型服务名称
|
|
201
|
+
input: 模型服务更新输入参数
|
|
202
|
+
config: 配置
|
|
203
|
+
|
|
204
|
+
Returns:
|
|
205
|
+
ModelService: 更新后的模型服务对象
|
|
206
|
+
|
|
207
|
+
Raises:
|
|
208
|
+
ResourceNotExistError: 模型服务不存在
|
|
209
|
+
"""
|
|
210
|
+
|
|
211
|
+
if isinstance(input, ModelProxyUpdateInput):
|
|
212
|
+
try:
|
|
213
|
+
if not input.proxy_mode:
|
|
214
|
+
input.proxy_mode = (
|
|
215
|
+
ProxyMode.MULTI
|
|
216
|
+
if len(pydash.get(input, "proxy_config.endpoints", []))
|
|
217
|
+
> 1
|
|
218
|
+
else ProxyMode.SINGLE
|
|
219
|
+
)
|
|
220
|
+
result = await self.__control_api.update_model_proxy_async(
|
|
221
|
+
model_proxy_name=name,
|
|
222
|
+
input=UpdateModelProxyInput().from_map(input.model_dump()),
|
|
223
|
+
config=config,
|
|
224
|
+
)
|
|
225
|
+
return ModelProxy.from_inner_object(result)
|
|
226
|
+
except HTTPError as e:
|
|
227
|
+
raise e.to_resource_error("Model", name) from e
|
|
228
|
+
|
|
229
|
+
else:
|
|
230
|
+
try:
|
|
231
|
+
result = await self.__control_api.update_model_service_async(
|
|
232
|
+
model_service_name=name,
|
|
233
|
+
input=UpdateModelServiceInput().from_map(
|
|
234
|
+
input.model_dump()
|
|
235
|
+
),
|
|
236
|
+
config=config,
|
|
237
|
+
)
|
|
238
|
+
return ModelService.from_inner_object(result)
|
|
239
|
+
except HTTPError as e:
|
|
240
|
+
raise e.to_resource_error("Model", name) from e
|
|
241
|
+
|
|
242
|
+
@overload
|
|
243
|
+
async def get_async(
|
|
244
|
+
self,
|
|
245
|
+
name: str,
|
|
246
|
+
backend_type: Literal[BackendType.SERVICE],
|
|
247
|
+
config: Optional[Config] = None,
|
|
248
|
+
) -> ModelService:
|
|
249
|
+
...
|
|
250
|
+
|
|
251
|
+
@overload
|
|
252
|
+
async def get_async(
|
|
253
|
+
self,
|
|
254
|
+
name: str,
|
|
255
|
+
backend_type: Literal[BackendType.PROXY],
|
|
256
|
+
config: Optional[Config] = None,
|
|
257
|
+
) -> ModelProxy:
|
|
258
|
+
...
|
|
259
|
+
|
|
260
|
+
@overload
|
|
261
|
+
async def get_async(
|
|
262
|
+
self,
|
|
263
|
+
name: str,
|
|
264
|
+
backend_type: None = None,
|
|
265
|
+
config: Optional[Config] = None,
|
|
266
|
+
) -> Union[ModelService, ModelProxy]:
|
|
267
|
+
...
|
|
268
|
+
|
|
269
|
+
async def get_async(
|
|
270
|
+
self,
|
|
271
|
+
name: str,
|
|
272
|
+
backend_type: Optional[BackendType] = None,
|
|
273
|
+
config: Optional[Config] = None,
|
|
274
|
+
):
|
|
275
|
+
"""获取模型服务(异步)
|
|
276
|
+
|
|
277
|
+
Args:
|
|
278
|
+
model_service_name: 模型服务名称
|
|
279
|
+
config: 配置
|
|
280
|
+
|
|
281
|
+
Returns:
|
|
282
|
+
ModelService: 模型服务对象
|
|
283
|
+
|
|
284
|
+
Raises:
|
|
285
|
+
ResourceNotExistError: 模型服务不存在
|
|
286
|
+
"""
|
|
287
|
+
|
|
288
|
+
error: Optional[HTTPError] = None
|
|
289
|
+
if backend_type == BackendType.PROXY or backend_type is None:
|
|
290
|
+
try:
|
|
291
|
+
result = await self.__control_api.get_model_proxy_async(
|
|
292
|
+
model_proxy_name=name, config=config
|
|
293
|
+
)
|
|
294
|
+
return ModelProxy.from_inner_object(result)
|
|
295
|
+
except HTTPError as e:
|
|
296
|
+
error = e
|
|
297
|
+
|
|
298
|
+
if backend_type == BackendType.PROXY and error is not None:
|
|
299
|
+
raise error.to_resource_error("Model", name) from error
|
|
300
|
+
|
|
301
|
+
try:
|
|
302
|
+
result = await self.__control_api.get_model_service_async(
|
|
303
|
+
model_service_name=name, config=config
|
|
304
|
+
)
|
|
305
|
+
return ModelService.from_inner_object(result)
|
|
306
|
+
except HTTPError as e:
|
|
307
|
+
raise e.to_resource_error("Model", name) from e
|
|
308
|
+
|
|
309
|
+
@overload
|
|
310
|
+
async def list_async(
|
|
311
|
+
self,
|
|
312
|
+
input: ModelProxyListInput,
|
|
313
|
+
config: Optional[Config] = None,
|
|
314
|
+
) -> List[ModelProxy]:
|
|
315
|
+
...
|
|
316
|
+
|
|
317
|
+
@overload
|
|
318
|
+
async def list_async(
|
|
319
|
+
self,
|
|
320
|
+
input: ModelServiceListInput,
|
|
321
|
+
config: Optional[Config] = None,
|
|
322
|
+
) -> List[ModelService]:
|
|
323
|
+
...
|
|
324
|
+
|
|
325
|
+
async def list_async(
|
|
326
|
+
self,
|
|
327
|
+
input: Union[ModelServiceListInput, ModelProxyListInput],
|
|
328
|
+
config: Optional[Config] = None,
|
|
329
|
+
):
|
|
330
|
+
"""列出模型服务(异步)
|
|
331
|
+
|
|
332
|
+
Args:
|
|
333
|
+
input: 分页查询参数
|
|
334
|
+
config: 配置
|
|
335
|
+
|
|
336
|
+
Returns:
|
|
337
|
+
List[ModelService]: 模型服务列表
|
|
338
|
+
"""
|
|
339
|
+
|
|
340
|
+
if isinstance(input, ModelProxyListInput):
|
|
341
|
+
result = await self.__control_api.list_model_proxies_async(
|
|
342
|
+
ListModelProxiesRequest().from_map(input.model_dump()),
|
|
343
|
+
config=config,
|
|
344
|
+
)
|
|
345
|
+
return [
|
|
346
|
+
ModelProxy.from_inner_object(item)
|
|
347
|
+
for item in result.items or []
|
|
348
|
+
]
|
|
349
|
+
else:
|
|
350
|
+
result = await self.__control_api.list_model_services_async(
|
|
351
|
+
ListModelServicesRequest().from_map(input.model_dump()),
|
|
352
|
+
config=config,
|
|
353
|
+
)
|
|
354
|
+
return [
|
|
355
|
+
ModelService.from_inner_object(item)
|
|
356
|
+
for item in result.items or []
|
|
357
|
+
]
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Model Service 模块 / Model Service Module"""
|
|
2
|
+
|
|
3
|
+
from .api import ModelCompletionAPI, ModelControlAPI, ModelDataAPI
|
|
4
|
+
from .client import ModelClient
|
|
5
|
+
from .model import (
|
|
6
|
+
BackendType,
|
|
7
|
+
ModelFeatures,
|
|
8
|
+
ModelInfoConfig,
|
|
9
|
+
ModelParameterRule,
|
|
10
|
+
ModelProperties,
|
|
11
|
+
ModelProxyCreateInput,
|
|
12
|
+
ModelProxyListInput,
|
|
13
|
+
ModelProxyUpdateInput,
|
|
14
|
+
ModelServiceCreateInput,
|
|
15
|
+
ModelServiceListInput,
|
|
16
|
+
ModelServiceUpdateInput,
|
|
17
|
+
ModelType,
|
|
18
|
+
Provider,
|
|
19
|
+
ProviderSettings,
|
|
20
|
+
ProxyConfig,
|
|
21
|
+
ProxyConfigEndpoint,
|
|
22
|
+
ProxyConfigFallback,
|
|
23
|
+
ProxyConfigPolicies,
|
|
24
|
+
)
|
|
25
|
+
from .model_proxy import ModelProxy
|
|
26
|
+
from .model_service import ModelService
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
# base
|
|
30
|
+
"ModelClient",
|
|
31
|
+
"ModelService",
|
|
32
|
+
"ModelProxy",
|
|
33
|
+
"ModelControlAPI",
|
|
34
|
+
"ModelCompletionAPI",
|
|
35
|
+
"ModelDataAPI",
|
|
36
|
+
# enum
|
|
37
|
+
"BackendType",
|
|
38
|
+
"ModelType",
|
|
39
|
+
"Provider",
|
|
40
|
+
# inner model
|
|
41
|
+
"ProviderSettings",
|
|
42
|
+
"ModelFeatures",
|
|
43
|
+
"ModelProperties",
|
|
44
|
+
"ModelParameterRule",
|
|
45
|
+
"ModelInfoConfig",
|
|
46
|
+
"ProxyConfigEndpoint",
|
|
47
|
+
"ProxyConfigFallback",
|
|
48
|
+
"ProxyConfigPolicies",
|
|
49
|
+
"ProxyConfig",
|
|
50
|
+
# api model
|
|
51
|
+
"ModelServiceCreateInput",
|
|
52
|
+
"ModelServiceUpdateInput",
|
|
53
|
+
"ModelServiceListInput",
|
|
54
|
+
"ModelProxyCreateInput",
|
|
55
|
+
"ModelProxyUpdateInput",
|
|
56
|
+
"ModelProxyListInput",
|
|
57
|
+
]
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"""Model Proxy 高层 API / Model Proxy High-Level API
|
|
2
|
+
|
|
3
|
+
此模块定义模型代理资源的高级API。
|
|
4
|
+
This module defines the high-level API for model proxy resources.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import List, Optional
|
|
8
|
+
|
|
9
|
+
import pydash
|
|
10
|
+
|
|
11
|
+
from agentrun.model.api.data import BaseInfo, ModelDataAPI
|
|
12
|
+
from agentrun.utils.config import Config
|
|
13
|
+
from agentrun.utils.model import Status
|
|
14
|
+
from agentrun.utils.resource import ResourceBase
|
|
15
|
+
|
|
16
|
+
from .model import (
|
|
17
|
+
BackendType,
|
|
18
|
+
ModelProxyCreateInput,
|
|
19
|
+
ModelProxyImmutableProps,
|
|
20
|
+
ModelProxyListInput,
|
|
21
|
+
ModelProxyMutableProps,
|
|
22
|
+
ModelProxySystemProps,
|
|
23
|
+
ModelProxyUpdateInput,
|
|
24
|
+
PageableInput,
|
|
25
|
+
ProxyMode,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class ModelProxy(
|
|
30
|
+
ModelProxyImmutableProps,
|
|
31
|
+
ModelProxyMutableProps,
|
|
32
|
+
ModelProxySystemProps,
|
|
33
|
+
ResourceBase,
|
|
34
|
+
):
|
|
35
|
+
"""模型服务"""
|
|
36
|
+
|
|
37
|
+
_data_client: Optional[ModelDataAPI] = None
|
|
38
|
+
|
|
39
|
+
@classmethod
|
|
40
|
+
def __get_client(cls):
|
|
41
|
+
from .client import ModelClient
|
|
42
|
+
|
|
43
|
+
return ModelClient()
|
|
44
|
+
|
|
45
|
+
@classmethod
|
|
46
|
+
async def create_async(
|
|
47
|
+
cls, input: ModelProxyCreateInput, config: Optional[Config] = None
|
|
48
|
+
):
|
|
49
|
+
"""创建模型服务(异步)
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
input: 模型服务输入参数
|
|
53
|
+
config: 配置
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
ModelProxy: 创建的模型服务对象
|
|
57
|
+
"""
|
|
58
|
+
return await cls.__get_client().create_async(input, config=config)
|
|
59
|
+
|
|
60
|
+
@classmethod
|
|
61
|
+
async def delete_by_name_async(
|
|
62
|
+
cls, model_Proxy_name: str, config: Optional[Config] = None
|
|
63
|
+
):
|
|
64
|
+
"""根据名称删除模型服务(异步)
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
model_Proxy_name: 模型服务名称
|
|
68
|
+
config: 配置
|
|
69
|
+
"""
|
|
70
|
+
return await cls.__get_client().delete_async(
|
|
71
|
+
model_Proxy_name, backend_type=BackendType.PROXY, config=config
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
@classmethod
|
|
75
|
+
async def update_by_name_async(
|
|
76
|
+
cls,
|
|
77
|
+
model_proxy_name: str,
|
|
78
|
+
input: ModelProxyUpdateInput,
|
|
79
|
+
config: Optional[Config] = None,
|
|
80
|
+
):
|
|
81
|
+
"""根据名称更新模型服务(异步)
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
model_Proxy_name: 模型服务名称
|
|
85
|
+
input: 模型服务更新输入参数
|
|
86
|
+
config: 配置
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
ModelProxy: 更新后的模型服务对象
|
|
90
|
+
"""
|
|
91
|
+
return await cls.__get_client().update_async(
|
|
92
|
+
model_proxy_name, input, config=config
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
@classmethod
|
|
96
|
+
async def get_by_name_async(
|
|
97
|
+
cls, model_proxy_name: str, config: Optional[Config] = None
|
|
98
|
+
):
|
|
99
|
+
"""根据名称获取模型服务(异步)
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
model_Proxy_name: 模型服务名称
|
|
103
|
+
config: 配置
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
ModelProxy: 模型服务对象
|
|
107
|
+
"""
|
|
108
|
+
return await cls.__get_client().get_async(
|
|
109
|
+
model_proxy_name, backend_type=BackendType.PROXY, config=config
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
@classmethod
|
|
113
|
+
async def _list_page_async(
|
|
114
|
+
cls, page_input: PageableInput, config: Config | None = None, **kwargs
|
|
115
|
+
):
|
|
116
|
+
return await cls.__get_client().list_async(
|
|
117
|
+
input=ModelProxyListInput(
|
|
118
|
+
**kwargs,
|
|
119
|
+
**page_input.model_dump(),
|
|
120
|
+
),
|
|
121
|
+
config=config,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
@classmethod
|
|
125
|
+
async def list_all_async(
|
|
126
|
+
cls,
|
|
127
|
+
*,
|
|
128
|
+
proxy_mode: Optional[str] = None,
|
|
129
|
+
status: Optional[Status] = None,
|
|
130
|
+
config: Optional[Config] = None,
|
|
131
|
+
) -> List["ModelProxy"]:
|
|
132
|
+
return await cls._list_all_async(
|
|
133
|
+
lambda m: m.model_proxy_id or "",
|
|
134
|
+
config=config,
|
|
135
|
+
proxy_mode=proxy_mode,
|
|
136
|
+
status=status,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
async def update_async(
|
|
140
|
+
self, input: ModelProxyUpdateInput, config: Optional[Config] = None
|
|
141
|
+
):
|
|
142
|
+
"""更新模型服务(异步)
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
input: 模型服务更新输入参数
|
|
146
|
+
config: 配置
|
|
147
|
+
|
|
148
|
+
Returns:
|
|
149
|
+
ModelProxy: 更新后的模型服务对象
|
|
150
|
+
"""
|
|
151
|
+
if self.model_proxy_name is None:
|
|
152
|
+
raise ValueError(
|
|
153
|
+
"model_Proxy_name is required to update a ModelProxy"
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
result = await self.update_by_name_async(
|
|
157
|
+
self.model_proxy_name, input, config=config
|
|
158
|
+
)
|
|
159
|
+
self.update_self(result)
|
|
160
|
+
|
|
161
|
+
return self
|
|
162
|
+
|
|
163
|
+
async def delete_async(self, config: Optional[Config] = None):
|
|
164
|
+
"""删除模型服务(异步)
|
|
165
|
+
|
|
166
|
+
Args:
|
|
167
|
+
config: 配置
|
|
168
|
+
"""
|
|
169
|
+
if self.model_proxy_name is None:
|
|
170
|
+
raise ValueError(
|
|
171
|
+
"model_Proxy_name is required to delete a ModelProxy"
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
return await self.delete_by_name_async(
|
|
175
|
+
self.model_proxy_name, config=config
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
async def get_async(self, config: Optional[Config] = None):
|
|
179
|
+
"""刷新模型服务信息(异步)
|
|
180
|
+
|
|
181
|
+
Args:
|
|
182
|
+
config: 配置
|
|
183
|
+
|
|
184
|
+
Returns:
|
|
185
|
+
ModelProxy: 刷新后的模型服务对象
|
|
186
|
+
"""
|
|
187
|
+
if self.model_proxy_name is None:
|
|
188
|
+
raise ValueError(
|
|
189
|
+
"model_Proxy_name is required to refresh a ModelProxy"
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
result = await self.get_by_name_async(
|
|
193
|
+
self.model_proxy_name, config=config
|
|
194
|
+
)
|
|
195
|
+
self.update_self(result)
|
|
196
|
+
|
|
197
|
+
return self
|
|
198
|
+
|
|
199
|
+
async def refresh_async(self, config: Optional[Config] = None):
|
|
200
|
+
"""刷新模型服务信息(异步)
|
|
201
|
+
|
|
202
|
+
Args:
|
|
203
|
+
config: 配置
|
|
204
|
+
|
|
205
|
+
Returns:
|
|
206
|
+
ModelProxy: 刷新后的模型服务对象
|
|
207
|
+
"""
|
|
208
|
+
return await self.get_async(config=config)
|
|
209
|
+
|
|
210
|
+
def model_info(self, config: Optional[Config] = None) -> BaseInfo:
|
|
211
|
+
cfg = Config.with_configs(self._config, config)
|
|
212
|
+
|
|
213
|
+
if self._data_client is None:
|
|
214
|
+
self._data_client = ModelDataAPI(
|
|
215
|
+
self.model_proxy_name or "",
|
|
216
|
+
credential_name=self.credential_name,
|
|
217
|
+
config=cfg,
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
self._data_client.update_model_name(
|
|
221
|
+
model_proxy_name=self.model_proxy_name,
|
|
222
|
+
model_name=(
|
|
223
|
+
pydash.get(self, "proxy_config.endpoints[0].model_names[0]")
|
|
224
|
+
if self.proxy_mode == ProxyMode.SINGLE
|
|
225
|
+
else self.model_proxy_name
|
|
226
|
+
)
|
|
227
|
+
or "",
|
|
228
|
+
credential_name=self.credential_name,
|
|
229
|
+
config=cfg,
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
return self._data_client.model_info()
|
|
233
|
+
|
|
234
|
+
def completions(
|
|
235
|
+
self,
|
|
236
|
+
messages: list,
|
|
237
|
+
model: Optional[str] = None,
|
|
238
|
+
stream: bool = False,
|
|
239
|
+
config: Optional[Config] = None,
|
|
240
|
+
**kwargs,
|
|
241
|
+
):
|
|
242
|
+
self.model_info(config)
|
|
243
|
+
assert self._data_client
|
|
244
|
+
|
|
245
|
+
return self._data_client.completions(
|
|
246
|
+
**kwargs,
|
|
247
|
+
messages=messages,
|
|
248
|
+
model=model,
|
|
249
|
+
stream=stream,
|
|
250
|
+
config=config,
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
def responses(
|
|
254
|
+
self,
|
|
255
|
+
messages: list,
|
|
256
|
+
model: Optional[str] = None,
|
|
257
|
+
stream: bool = False,
|
|
258
|
+
config: Optional[Config] = None,
|
|
259
|
+
**kwargs,
|
|
260
|
+
):
|
|
261
|
+
self.model_info(config)
|
|
262
|
+
assert self._data_client
|
|
263
|
+
|
|
264
|
+
return self._data_client.responses(
|
|
265
|
+
**kwargs,
|
|
266
|
+
messages=messages,
|
|
267
|
+
model=model,
|
|
268
|
+
stream=stream,
|
|
269
|
+
config=config,
|
|
270
|
+
)
|