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
agentrun/model/client.py
ADDED
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This file is auto generated by the code generation script.
|
|
3
|
+
Do not modify this file manually.
|
|
4
|
+
Use the `make codegen` command to regenerate.
|
|
5
|
+
|
|
6
|
+
当前文件为自动生成的控制 API 客户端代码。请勿手动修改此文件。
|
|
7
|
+
使用 `make codegen` 命令重新生成。
|
|
8
|
+
|
|
9
|
+
source: agentrun/model/__client_async_template.py
|
|
10
|
+
|
|
11
|
+
Model Service 客户端 / Model Service Client
|
|
12
|
+
|
|
13
|
+
此模块提供模型服务和模型代理的客户端API。
|
|
14
|
+
This module provides the client API for model services and model proxies.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from typing import List, Literal, Optional, overload, Union
|
|
18
|
+
|
|
19
|
+
from alibabacloud_agentrun20250910.models import (
|
|
20
|
+
CreateModelProxyInput,
|
|
21
|
+
CreateModelServiceInput,
|
|
22
|
+
ListModelProxiesRequest,
|
|
23
|
+
ListModelServicesRequest,
|
|
24
|
+
UpdateModelProxyInput,
|
|
25
|
+
UpdateModelServiceInput,
|
|
26
|
+
)
|
|
27
|
+
import pydash
|
|
28
|
+
|
|
29
|
+
from agentrun.utils.config import Config
|
|
30
|
+
from agentrun.utils.exception import HTTPError
|
|
31
|
+
|
|
32
|
+
from .api.control import ModelControlAPI
|
|
33
|
+
from .model import (
|
|
34
|
+
BackendType,
|
|
35
|
+
ModelProxyCreateInput,
|
|
36
|
+
ModelProxyListInput,
|
|
37
|
+
ModelProxyUpdateInput,
|
|
38
|
+
ModelServiceCreateInput,
|
|
39
|
+
ModelServiceListInput,
|
|
40
|
+
ModelServiceUpdateInput,
|
|
41
|
+
ProxyMode,
|
|
42
|
+
)
|
|
43
|
+
from .model_proxy import ModelProxy
|
|
44
|
+
from .model_service import ModelService
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class ModelClient:
|
|
48
|
+
"""Model Service 客户端 / Model Service Client
|
|
49
|
+
|
|
50
|
+
提供模型服务和模型代理的创建、删除、更新和查询功能。
|
|
51
|
+
Provides create, delete, update and query functions for model services and model proxies.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
def __init__(self, config: Optional[Config] = None):
|
|
55
|
+
"""初始化客户端 / Initialize client
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
config: 配置对象,可选 / Configuration object, optional
|
|
59
|
+
"""
|
|
60
|
+
self.__control_api = ModelControlAPI(config)
|
|
61
|
+
|
|
62
|
+
@overload
|
|
63
|
+
async def create_async(
|
|
64
|
+
self, input: ModelServiceCreateInput, config: Optional[Config] = None
|
|
65
|
+
) -> ModelService:
|
|
66
|
+
...
|
|
67
|
+
|
|
68
|
+
@overload
|
|
69
|
+
def create(
|
|
70
|
+
self, input: ModelServiceCreateInput, config: Optional[Config] = None
|
|
71
|
+
) -> ModelService:
|
|
72
|
+
...
|
|
73
|
+
|
|
74
|
+
@overload
|
|
75
|
+
async def create_async(
|
|
76
|
+
self, input: ModelProxyCreateInput, config: Optional[Config] = None
|
|
77
|
+
) -> ModelProxy:
|
|
78
|
+
...
|
|
79
|
+
|
|
80
|
+
@overload
|
|
81
|
+
def create(
|
|
82
|
+
self, input: ModelProxyCreateInput, config: Optional[Config] = None
|
|
83
|
+
) -> ModelProxy:
|
|
84
|
+
...
|
|
85
|
+
|
|
86
|
+
async def create_async(
|
|
87
|
+
self,
|
|
88
|
+
input: Union[ModelServiceCreateInput, ModelProxyCreateInput],
|
|
89
|
+
config: Optional[Config] = None,
|
|
90
|
+
):
|
|
91
|
+
"""创建模型服务(异步)
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
input: 模型服务输入参数
|
|
95
|
+
config: 配置
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
model: 创建的对象
|
|
99
|
+
"""
|
|
100
|
+
try:
|
|
101
|
+
if isinstance(input, ModelProxyCreateInput):
|
|
102
|
+
if not input.proxy_mode:
|
|
103
|
+
input.proxy_mode = (
|
|
104
|
+
ProxyMode.MULTI
|
|
105
|
+
if len(pydash.get(input, "proxy_config.endpoints", []))
|
|
106
|
+
> 1
|
|
107
|
+
else ProxyMode.SINGLE
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
result = await self.__control_api.create_model_proxy_async(
|
|
111
|
+
CreateModelProxyInput().from_map(input.model_dump()),
|
|
112
|
+
config=config,
|
|
113
|
+
)
|
|
114
|
+
return ModelProxy.from_inner_object(result)
|
|
115
|
+
else:
|
|
116
|
+
result = await self.__control_api.create_model_service_async(
|
|
117
|
+
CreateModelServiceInput().from_map(input.model_dump()),
|
|
118
|
+
config=config,
|
|
119
|
+
)
|
|
120
|
+
return ModelService.from_inner_object(result)
|
|
121
|
+
except HTTPError as e:
|
|
122
|
+
raise e.to_resource_error(
|
|
123
|
+
"Model",
|
|
124
|
+
(
|
|
125
|
+
input.model_proxy_name
|
|
126
|
+
if isinstance(input, ModelProxyCreateInput)
|
|
127
|
+
else input.model_service_name
|
|
128
|
+
),
|
|
129
|
+
) from e
|
|
130
|
+
|
|
131
|
+
def create(
|
|
132
|
+
self,
|
|
133
|
+
input: Union[ModelServiceCreateInput, ModelProxyCreateInput],
|
|
134
|
+
config: Optional[Config] = None,
|
|
135
|
+
):
|
|
136
|
+
"""创建模型服务(同步)
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
input: 模型服务输入参数
|
|
140
|
+
config: 配置
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
model: 创建的对象
|
|
144
|
+
"""
|
|
145
|
+
try:
|
|
146
|
+
if isinstance(input, ModelProxyCreateInput):
|
|
147
|
+
if not input.proxy_mode:
|
|
148
|
+
input.proxy_mode = (
|
|
149
|
+
ProxyMode.MULTI
|
|
150
|
+
if len(pydash.get(input, "proxy_config.endpoints", []))
|
|
151
|
+
> 1
|
|
152
|
+
else ProxyMode.SINGLE
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
result = self.__control_api.create_model_proxy(
|
|
156
|
+
CreateModelProxyInput().from_map(input.model_dump()),
|
|
157
|
+
config=config,
|
|
158
|
+
)
|
|
159
|
+
return ModelProxy.from_inner_object(result)
|
|
160
|
+
else:
|
|
161
|
+
result = self.__control_api.create_model_service(
|
|
162
|
+
CreateModelServiceInput().from_map(input.model_dump()),
|
|
163
|
+
config=config,
|
|
164
|
+
)
|
|
165
|
+
return ModelService.from_inner_object(result)
|
|
166
|
+
except HTTPError as e:
|
|
167
|
+
raise e.to_resource_error(
|
|
168
|
+
"Model",
|
|
169
|
+
(
|
|
170
|
+
input.model_proxy_name
|
|
171
|
+
if isinstance(input, ModelProxyCreateInput)
|
|
172
|
+
else input.model_service_name
|
|
173
|
+
),
|
|
174
|
+
) from e
|
|
175
|
+
|
|
176
|
+
@overload
|
|
177
|
+
async def delete_async(
|
|
178
|
+
self,
|
|
179
|
+
name: str,
|
|
180
|
+
backend_type: Literal[BackendType.PROXY],
|
|
181
|
+
config: Optional[Config] = None,
|
|
182
|
+
) -> ModelProxy:
|
|
183
|
+
...
|
|
184
|
+
|
|
185
|
+
@overload
|
|
186
|
+
def delete(
|
|
187
|
+
self,
|
|
188
|
+
name: str,
|
|
189
|
+
backend_type: Literal[BackendType.PROXY],
|
|
190
|
+
config: Optional[Config] = None,
|
|
191
|
+
) -> ModelProxy:
|
|
192
|
+
...
|
|
193
|
+
|
|
194
|
+
@overload
|
|
195
|
+
async def delete_async(
|
|
196
|
+
self,
|
|
197
|
+
name: str,
|
|
198
|
+
backend_type: Literal[BackendType.SERVICE],
|
|
199
|
+
config: Optional[Config] = None,
|
|
200
|
+
) -> ModelService:
|
|
201
|
+
...
|
|
202
|
+
|
|
203
|
+
@overload
|
|
204
|
+
def delete(
|
|
205
|
+
self,
|
|
206
|
+
name: str,
|
|
207
|
+
backend_type: Literal[BackendType.SERVICE],
|
|
208
|
+
config: Optional[Config] = None,
|
|
209
|
+
) -> ModelService:
|
|
210
|
+
...
|
|
211
|
+
|
|
212
|
+
@overload
|
|
213
|
+
async def delete_async(
|
|
214
|
+
self,
|
|
215
|
+
name: str,
|
|
216
|
+
backend_type: None = None,
|
|
217
|
+
config: Optional[Config] = None,
|
|
218
|
+
) -> Union[ModelProxy, ModelService]:
|
|
219
|
+
...
|
|
220
|
+
|
|
221
|
+
@overload
|
|
222
|
+
def delete(
|
|
223
|
+
self,
|
|
224
|
+
name: str,
|
|
225
|
+
backend_type: None = None,
|
|
226
|
+
config: Optional[Config] = None,
|
|
227
|
+
) -> Union[ModelProxy, ModelService]:
|
|
228
|
+
...
|
|
229
|
+
|
|
230
|
+
async def delete_async(
|
|
231
|
+
self,
|
|
232
|
+
name: str,
|
|
233
|
+
backend_type: Optional[BackendType] = None,
|
|
234
|
+
config: Optional[Config] = None,
|
|
235
|
+
):
|
|
236
|
+
"""删除模型服务(异步)
|
|
237
|
+
|
|
238
|
+
Args:
|
|
239
|
+
model_service_name: 模型服务名称
|
|
240
|
+
config: 配置
|
|
241
|
+
|
|
242
|
+
Raises:
|
|
243
|
+
ResourceNotExistError: 模型服务不存在
|
|
244
|
+
"""
|
|
245
|
+
|
|
246
|
+
error: Optional[HTTPError] = None
|
|
247
|
+
if backend_type == BackendType.PROXY or backend_type is None:
|
|
248
|
+
try:
|
|
249
|
+
result = await self.__control_api.delete_model_proxy_async(
|
|
250
|
+
model_proxy_name=name, config=config
|
|
251
|
+
)
|
|
252
|
+
return ModelProxy.from_inner_object(result)
|
|
253
|
+
except HTTPError as e:
|
|
254
|
+
error = e
|
|
255
|
+
|
|
256
|
+
if backend_type == BackendType.PROXY and error is not None:
|
|
257
|
+
raise error.to_resource_error("Model", name) from error
|
|
258
|
+
|
|
259
|
+
try:
|
|
260
|
+
result = await self.__control_api.delete_model_service_async(
|
|
261
|
+
model_service_name=name, config=config
|
|
262
|
+
)
|
|
263
|
+
return ModelService.from_inner_object(result)
|
|
264
|
+
except HTTPError as e:
|
|
265
|
+
raise e.to_resource_error("Model", name) from error
|
|
266
|
+
|
|
267
|
+
def delete(
|
|
268
|
+
self,
|
|
269
|
+
name: str,
|
|
270
|
+
backend_type: Optional[BackendType] = None,
|
|
271
|
+
config: Optional[Config] = None,
|
|
272
|
+
):
|
|
273
|
+
"""删除模型服务(同步)
|
|
274
|
+
|
|
275
|
+
Args:
|
|
276
|
+
model_service_name: 模型服务名称
|
|
277
|
+
config: 配置
|
|
278
|
+
|
|
279
|
+
Raises:
|
|
280
|
+
ResourceNotExistError: 模型服务不存在
|
|
281
|
+
"""
|
|
282
|
+
|
|
283
|
+
error: Optional[HTTPError] = None
|
|
284
|
+
if backend_type == BackendType.PROXY or backend_type is None:
|
|
285
|
+
try:
|
|
286
|
+
result = self.__control_api.delete_model_proxy(
|
|
287
|
+
model_proxy_name=name, config=config
|
|
288
|
+
)
|
|
289
|
+
return ModelProxy.from_inner_object(result)
|
|
290
|
+
except HTTPError as e:
|
|
291
|
+
error = e
|
|
292
|
+
|
|
293
|
+
if backend_type == BackendType.PROXY and error is not None:
|
|
294
|
+
raise error.to_resource_error("Model", name) from error
|
|
295
|
+
|
|
296
|
+
try:
|
|
297
|
+
result = self.__control_api.delete_model_service(
|
|
298
|
+
model_service_name=name, config=config
|
|
299
|
+
)
|
|
300
|
+
return ModelService.from_inner_object(result)
|
|
301
|
+
except HTTPError as e:
|
|
302
|
+
raise e.to_resource_error("Model", name) from error
|
|
303
|
+
|
|
304
|
+
@overload
|
|
305
|
+
async def update_async(
|
|
306
|
+
self,
|
|
307
|
+
name: str,
|
|
308
|
+
input: ModelServiceUpdateInput,
|
|
309
|
+
config: Optional[Config] = None,
|
|
310
|
+
) -> ModelService:
|
|
311
|
+
...
|
|
312
|
+
|
|
313
|
+
@overload
|
|
314
|
+
def update(
|
|
315
|
+
self,
|
|
316
|
+
name: str,
|
|
317
|
+
input: ModelServiceUpdateInput,
|
|
318
|
+
config: Optional[Config] = None,
|
|
319
|
+
) -> ModelService:
|
|
320
|
+
...
|
|
321
|
+
|
|
322
|
+
@overload
|
|
323
|
+
async def update_async(
|
|
324
|
+
self,
|
|
325
|
+
name: str,
|
|
326
|
+
input: ModelProxyUpdateInput,
|
|
327
|
+
config: Optional[Config] = None,
|
|
328
|
+
) -> ModelProxy:
|
|
329
|
+
...
|
|
330
|
+
|
|
331
|
+
@overload
|
|
332
|
+
def update(
|
|
333
|
+
self,
|
|
334
|
+
name: str,
|
|
335
|
+
input: ModelProxyUpdateInput,
|
|
336
|
+
config: Optional[Config] = None,
|
|
337
|
+
) -> ModelProxy:
|
|
338
|
+
...
|
|
339
|
+
|
|
340
|
+
async def update_async(
|
|
341
|
+
self,
|
|
342
|
+
name: str,
|
|
343
|
+
input: Union[ModelServiceUpdateInput, ModelProxyUpdateInput],
|
|
344
|
+
config: Optional[Config] = None,
|
|
345
|
+
):
|
|
346
|
+
"""更新模型服务(异步)
|
|
347
|
+
|
|
348
|
+
Args:
|
|
349
|
+
model_service_name: 模型服务名称
|
|
350
|
+
input: 模型服务更新输入参数
|
|
351
|
+
config: 配置
|
|
352
|
+
|
|
353
|
+
Returns:
|
|
354
|
+
ModelService: 更新后的模型服务对象
|
|
355
|
+
|
|
356
|
+
Raises:
|
|
357
|
+
ResourceNotExistError: 模型服务不存在
|
|
358
|
+
"""
|
|
359
|
+
|
|
360
|
+
if isinstance(input, ModelProxyUpdateInput):
|
|
361
|
+
try:
|
|
362
|
+
if not input.proxy_mode:
|
|
363
|
+
input.proxy_mode = (
|
|
364
|
+
ProxyMode.MULTI
|
|
365
|
+
if len(pydash.get(input, "proxy_config.endpoints", []))
|
|
366
|
+
> 1
|
|
367
|
+
else ProxyMode.SINGLE
|
|
368
|
+
)
|
|
369
|
+
result = await self.__control_api.update_model_proxy_async(
|
|
370
|
+
model_proxy_name=name,
|
|
371
|
+
input=UpdateModelProxyInput().from_map(input.model_dump()),
|
|
372
|
+
config=config,
|
|
373
|
+
)
|
|
374
|
+
return ModelProxy.from_inner_object(result)
|
|
375
|
+
except HTTPError as e:
|
|
376
|
+
raise e.to_resource_error("Model", name) from e
|
|
377
|
+
|
|
378
|
+
else:
|
|
379
|
+
try:
|
|
380
|
+
result = await self.__control_api.update_model_service_async(
|
|
381
|
+
model_service_name=name,
|
|
382
|
+
input=UpdateModelServiceInput().from_map(
|
|
383
|
+
input.model_dump()
|
|
384
|
+
),
|
|
385
|
+
config=config,
|
|
386
|
+
)
|
|
387
|
+
return ModelService.from_inner_object(result)
|
|
388
|
+
except HTTPError as e:
|
|
389
|
+
raise e.to_resource_error("Model", name) from e
|
|
390
|
+
|
|
391
|
+
def update(
|
|
392
|
+
self,
|
|
393
|
+
name: str,
|
|
394
|
+
input: Union[ModelServiceUpdateInput, ModelProxyUpdateInput],
|
|
395
|
+
config: Optional[Config] = None,
|
|
396
|
+
):
|
|
397
|
+
"""更新模型服务(同步)
|
|
398
|
+
|
|
399
|
+
Args:
|
|
400
|
+
model_service_name: 模型服务名称
|
|
401
|
+
input: 模型服务更新输入参数
|
|
402
|
+
config: 配置
|
|
403
|
+
|
|
404
|
+
Returns:
|
|
405
|
+
ModelService: 更新后的模型服务对象
|
|
406
|
+
|
|
407
|
+
Raises:
|
|
408
|
+
ResourceNotExistError: 模型服务不存在
|
|
409
|
+
"""
|
|
410
|
+
|
|
411
|
+
if isinstance(input, ModelProxyUpdateInput):
|
|
412
|
+
try:
|
|
413
|
+
if not input.proxy_mode:
|
|
414
|
+
input.proxy_mode = (
|
|
415
|
+
ProxyMode.MULTI
|
|
416
|
+
if len(pydash.get(input, "proxy_config.endpoints", []))
|
|
417
|
+
> 1
|
|
418
|
+
else ProxyMode.SINGLE
|
|
419
|
+
)
|
|
420
|
+
result = self.__control_api.update_model_proxy(
|
|
421
|
+
model_proxy_name=name,
|
|
422
|
+
input=UpdateModelProxyInput().from_map(input.model_dump()),
|
|
423
|
+
config=config,
|
|
424
|
+
)
|
|
425
|
+
return ModelProxy.from_inner_object(result)
|
|
426
|
+
except HTTPError as e:
|
|
427
|
+
raise e.to_resource_error("Model", name) from e
|
|
428
|
+
|
|
429
|
+
else:
|
|
430
|
+
try:
|
|
431
|
+
result = self.__control_api.update_model_service(
|
|
432
|
+
model_service_name=name,
|
|
433
|
+
input=UpdateModelServiceInput().from_map(
|
|
434
|
+
input.model_dump()
|
|
435
|
+
),
|
|
436
|
+
config=config,
|
|
437
|
+
)
|
|
438
|
+
return ModelService.from_inner_object(result)
|
|
439
|
+
except HTTPError as e:
|
|
440
|
+
raise e.to_resource_error("Model", name) from e
|
|
441
|
+
|
|
442
|
+
@overload
|
|
443
|
+
async def get_async(
|
|
444
|
+
self,
|
|
445
|
+
name: str,
|
|
446
|
+
backend_type: Literal[BackendType.SERVICE],
|
|
447
|
+
config: Optional[Config] = None,
|
|
448
|
+
) -> ModelService:
|
|
449
|
+
...
|
|
450
|
+
|
|
451
|
+
@overload
|
|
452
|
+
def get(
|
|
453
|
+
self,
|
|
454
|
+
name: str,
|
|
455
|
+
backend_type: Literal[BackendType.SERVICE],
|
|
456
|
+
config: Optional[Config] = None,
|
|
457
|
+
) -> ModelService:
|
|
458
|
+
...
|
|
459
|
+
|
|
460
|
+
@overload
|
|
461
|
+
async def get_async(
|
|
462
|
+
self,
|
|
463
|
+
name: str,
|
|
464
|
+
backend_type: Literal[BackendType.PROXY],
|
|
465
|
+
config: Optional[Config] = None,
|
|
466
|
+
) -> ModelProxy:
|
|
467
|
+
...
|
|
468
|
+
|
|
469
|
+
@overload
|
|
470
|
+
def get(
|
|
471
|
+
self,
|
|
472
|
+
name: str,
|
|
473
|
+
backend_type: Literal[BackendType.PROXY],
|
|
474
|
+
config: Optional[Config] = None,
|
|
475
|
+
) -> ModelProxy:
|
|
476
|
+
...
|
|
477
|
+
|
|
478
|
+
@overload
|
|
479
|
+
async def get_async(
|
|
480
|
+
self,
|
|
481
|
+
name: str,
|
|
482
|
+
backend_type: None = None,
|
|
483
|
+
config: Optional[Config] = None,
|
|
484
|
+
) -> Union[ModelService, ModelProxy]:
|
|
485
|
+
...
|
|
486
|
+
|
|
487
|
+
@overload
|
|
488
|
+
def get(
|
|
489
|
+
self,
|
|
490
|
+
name: str,
|
|
491
|
+
backend_type: None = None,
|
|
492
|
+
config: Optional[Config] = None,
|
|
493
|
+
) -> Union[ModelService, ModelProxy]:
|
|
494
|
+
...
|
|
495
|
+
|
|
496
|
+
async def get_async(
|
|
497
|
+
self,
|
|
498
|
+
name: str,
|
|
499
|
+
backend_type: Optional[BackendType] = None,
|
|
500
|
+
config: Optional[Config] = None,
|
|
501
|
+
):
|
|
502
|
+
"""获取模型服务(异步)
|
|
503
|
+
|
|
504
|
+
Args:
|
|
505
|
+
model_service_name: 模型服务名称
|
|
506
|
+
config: 配置
|
|
507
|
+
|
|
508
|
+
Returns:
|
|
509
|
+
ModelService: 模型服务对象
|
|
510
|
+
|
|
511
|
+
Raises:
|
|
512
|
+
ResourceNotExistError: 模型服务不存在
|
|
513
|
+
"""
|
|
514
|
+
|
|
515
|
+
error: Optional[HTTPError] = None
|
|
516
|
+
if backend_type == BackendType.PROXY or backend_type is None:
|
|
517
|
+
try:
|
|
518
|
+
result = await self.__control_api.get_model_proxy_async(
|
|
519
|
+
model_proxy_name=name, config=config
|
|
520
|
+
)
|
|
521
|
+
return ModelProxy.from_inner_object(result)
|
|
522
|
+
except HTTPError as e:
|
|
523
|
+
error = e
|
|
524
|
+
|
|
525
|
+
if backend_type == BackendType.PROXY and error is not None:
|
|
526
|
+
raise error.to_resource_error("Model", name) from error
|
|
527
|
+
|
|
528
|
+
try:
|
|
529
|
+
result = await self.__control_api.get_model_service_async(
|
|
530
|
+
model_service_name=name, config=config
|
|
531
|
+
)
|
|
532
|
+
return ModelService.from_inner_object(result)
|
|
533
|
+
except HTTPError as e:
|
|
534
|
+
raise e.to_resource_error("Model", name) from e
|
|
535
|
+
|
|
536
|
+
def get(
|
|
537
|
+
self,
|
|
538
|
+
name: str,
|
|
539
|
+
backend_type: Optional[BackendType] = None,
|
|
540
|
+
config: Optional[Config] = None,
|
|
541
|
+
):
|
|
542
|
+
"""获取模型服务(同步)
|
|
543
|
+
|
|
544
|
+
Args:
|
|
545
|
+
model_service_name: 模型服务名称
|
|
546
|
+
config: 配置
|
|
547
|
+
|
|
548
|
+
Returns:
|
|
549
|
+
ModelService: 模型服务对象
|
|
550
|
+
|
|
551
|
+
Raises:
|
|
552
|
+
ResourceNotExistError: 模型服务不存在
|
|
553
|
+
"""
|
|
554
|
+
|
|
555
|
+
error: Optional[HTTPError] = None
|
|
556
|
+
if backend_type == BackendType.PROXY or backend_type is None:
|
|
557
|
+
try:
|
|
558
|
+
result = self.__control_api.get_model_proxy(
|
|
559
|
+
model_proxy_name=name, config=config
|
|
560
|
+
)
|
|
561
|
+
return ModelProxy.from_inner_object(result)
|
|
562
|
+
except HTTPError as e:
|
|
563
|
+
error = e
|
|
564
|
+
|
|
565
|
+
if backend_type == BackendType.PROXY and error is not None:
|
|
566
|
+
raise error.to_resource_error("Model", name) from error
|
|
567
|
+
|
|
568
|
+
try:
|
|
569
|
+
result = self.__control_api.get_model_service(
|
|
570
|
+
model_service_name=name, config=config
|
|
571
|
+
)
|
|
572
|
+
return ModelService.from_inner_object(result)
|
|
573
|
+
except HTTPError as e:
|
|
574
|
+
raise e.to_resource_error("Model", name) from e
|
|
575
|
+
|
|
576
|
+
@overload
|
|
577
|
+
async def list_async(
|
|
578
|
+
self,
|
|
579
|
+
input: ModelProxyListInput,
|
|
580
|
+
config: Optional[Config] = None,
|
|
581
|
+
) -> List[ModelProxy]:
|
|
582
|
+
...
|
|
583
|
+
|
|
584
|
+
@overload
|
|
585
|
+
def list(
|
|
586
|
+
self,
|
|
587
|
+
input: ModelProxyListInput,
|
|
588
|
+
config: Optional[Config] = None,
|
|
589
|
+
) -> List[ModelProxy]:
|
|
590
|
+
...
|
|
591
|
+
|
|
592
|
+
@overload
|
|
593
|
+
async def list_async(
|
|
594
|
+
self,
|
|
595
|
+
input: ModelServiceListInput,
|
|
596
|
+
config: Optional[Config] = None,
|
|
597
|
+
) -> List[ModelService]:
|
|
598
|
+
...
|
|
599
|
+
|
|
600
|
+
@overload
|
|
601
|
+
def list(
|
|
602
|
+
self,
|
|
603
|
+
input: ModelServiceListInput,
|
|
604
|
+
config: Optional[Config] = None,
|
|
605
|
+
) -> List[ModelService]:
|
|
606
|
+
...
|
|
607
|
+
|
|
608
|
+
async def list_async(
|
|
609
|
+
self,
|
|
610
|
+
input: Union[ModelServiceListInput, ModelProxyListInput],
|
|
611
|
+
config: Optional[Config] = None,
|
|
612
|
+
):
|
|
613
|
+
"""列出模型服务(异步)
|
|
614
|
+
|
|
615
|
+
Args:
|
|
616
|
+
input: 分页查询参数
|
|
617
|
+
config: 配置
|
|
618
|
+
|
|
619
|
+
Returns:
|
|
620
|
+
List[ModelService]: 模型服务列表
|
|
621
|
+
"""
|
|
622
|
+
|
|
623
|
+
if isinstance(input, ModelProxyListInput):
|
|
624
|
+
result = await self.__control_api.list_model_proxies_async(
|
|
625
|
+
ListModelProxiesRequest().from_map(input.model_dump()),
|
|
626
|
+
config=config,
|
|
627
|
+
)
|
|
628
|
+
return [
|
|
629
|
+
ModelProxy.from_inner_object(item)
|
|
630
|
+
for item in result.items or []
|
|
631
|
+
]
|
|
632
|
+
else:
|
|
633
|
+
result = await self.__control_api.list_model_services_async(
|
|
634
|
+
ListModelServicesRequest().from_map(input.model_dump()),
|
|
635
|
+
config=config,
|
|
636
|
+
)
|
|
637
|
+
return [
|
|
638
|
+
ModelService.from_inner_object(item)
|
|
639
|
+
for item in result.items or []
|
|
640
|
+
]
|
|
641
|
+
|
|
642
|
+
def list(
|
|
643
|
+
self,
|
|
644
|
+
input: Union[ModelServiceListInput, ModelProxyListInput],
|
|
645
|
+
config: Optional[Config] = None,
|
|
646
|
+
):
|
|
647
|
+
"""列出模型服务(同步)
|
|
648
|
+
|
|
649
|
+
Args:
|
|
650
|
+
input: 分页查询参数
|
|
651
|
+
config: 配置
|
|
652
|
+
|
|
653
|
+
Returns:
|
|
654
|
+
List[ModelService]: 模型服务列表
|
|
655
|
+
"""
|
|
656
|
+
|
|
657
|
+
if isinstance(input, ModelProxyListInput):
|
|
658
|
+
result = self.__control_api.list_model_proxies(
|
|
659
|
+
ListModelProxiesRequest().from_map(input.model_dump()),
|
|
660
|
+
config=config,
|
|
661
|
+
)
|
|
662
|
+
return [
|
|
663
|
+
ModelProxy.from_inner_object(item)
|
|
664
|
+
for item in result.items or []
|
|
665
|
+
]
|
|
666
|
+
else:
|
|
667
|
+
result = self.__control_api.list_model_services(
|
|
668
|
+
ListModelServicesRequest().from_map(input.model_dump()),
|
|
669
|
+
config=config,
|
|
670
|
+
)
|
|
671
|
+
return [
|
|
672
|
+
ModelService.from_inner_object(item)
|
|
673
|
+
for item in result.items or []
|
|
674
|
+
]
|