agentrun-inner-test 0.0.62__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.

Potentially problematic release.


This version of agentrun-inner-test might be problematic. Click here for more details.

Files changed (154) hide show
  1. agentrun/__init__.py +358 -0
  2. agentrun/agent_runtime/__client_async_template.py +466 -0
  3. agentrun/agent_runtime/__endpoint_async_template.py +345 -0
  4. agentrun/agent_runtime/__init__.py +53 -0
  5. agentrun/agent_runtime/__runtime_async_template.py +477 -0
  6. agentrun/agent_runtime/api/__data_async_template.py +58 -0
  7. agentrun/agent_runtime/api/__init__.py +6 -0
  8. agentrun/agent_runtime/api/control.py +1362 -0
  9. agentrun/agent_runtime/api/data.py +98 -0
  10. agentrun/agent_runtime/client.py +868 -0
  11. agentrun/agent_runtime/endpoint.py +649 -0
  12. agentrun/agent_runtime/model.py +362 -0
  13. agentrun/agent_runtime/runtime.py +904 -0
  14. agentrun/credential/__client_async_template.py +177 -0
  15. agentrun/credential/__credential_async_template.py +216 -0
  16. agentrun/credential/__init__.py +28 -0
  17. agentrun/credential/api/__init__.py +5 -0
  18. agentrun/credential/api/control.py +606 -0
  19. agentrun/credential/client.py +319 -0
  20. agentrun/credential/credential.py +381 -0
  21. agentrun/credential/model.py +248 -0
  22. agentrun/integration/__init__.py +21 -0
  23. agentrun/integration/agentscope/__init__.py +13 -0
  24. agentrun/integration/agentscope/adapter.py +17 -0
  25. agentrun/integration/agentscope/builtin.py +88 -0
  26. agentrun/integration/agentscope/message_adapter.py +185 -0
  27. agentrun/integration/agentscope/model_adapter.py +60 -0
  28. agentrun/integration/agentscope/tool_adapter.py +59 -0
  29. agentrun/integration/builtin/__init__.py +18 -0
  30. agentrun/integration/builtin/knowledgebase.py +137 -0
  31. agentrun/integration/builtin/model.py +93 -0
  32. agentrun/integration/builtin/sandbox.py +1234 -0
  33. agentrun/integration/builtin/toolset.py +47 -0
  34. agentrun/integration/crewai/__init__.py +13 -0
  35. agentrun/integration/crewai/adapter.py +9 -0
  36. agentrun/integration/crewai/builtin.py +88 -0
  37. agentrun/integration/crewai/model_adapter.py +31 -0
  38. agentrun/integration/crewai/tool_adapter.py +26 -0
  39. agentrun/integration/google_adk/__init__.py +13 -0
  40. agentrun/integration/google_adk/adapter.py +15 -0
  41. agentrun/integration/google_adk/builtin.py +88 -0
  42. agentrun/integration/google_adk/message_adapter.py +144 -0
  43. agentrun/integration/google_adk/model_adapter.py +46 -0
  44. agentrun/integration/google_adk/tool_adapter.py +235 -0
  45. agentrun/integration/langchain/__init__.py +31 -0
  46. agentrun/integration/langchain/adapter.py +15 -0
  47. agentrun/integration/langchain/builtin.py +94 -0
  48. agentrun/integration/langchain/message_adapter.py +141 -0
  49. agentrun/integration/langchain/model_adapter.py +37 -0
  50. agentrun/integration/langchain/tool_adapter.py +50 -0
  51. agentrun/integration/langgraph/__init__.py +36 -0
  52. agentrun/integration/langgraph/adapter.py +20 -0
  53. agentrun/integration/langgraph/agent_converter.py +1073 -0
  54. agentrun/integration/langgraph/builtin.py +88 -0
  55. agentrun/integration/pydantic_ai/__init__.py +13 -0
  56. agentrun/integration/pydantic_ai/adapter.py +13 -0
  57. agentrun/integration/pydantic_ai/builtin.py +88 -0
  58. agentrun/integration/pydantic_ai/model_adapter.py +44 -0
  59. agentrun/integration/pydantic_ai/tool_adapter.py +19 -0
  60. agentrun/integration/utils/__init__.py +112 -0
  61. agentrun/integration/utils/adapter.py +560 -0
  62. agentrun/integration/utils/canonical.py +164 -0
  63. agentrun/integration/utils/converter.py +134 -0
  64. agentrun/integration/utils/model.py +110 -0
  65. agentrun/integration/utils/tool.py +1759 -0
  66. agentrun/knowledgebase/__client_async_template.py +173 -0
  67. agentrun/knowledgebase/__init__.py +53 -0
  68. agentrun/knowledgebase/__knowledgebase_async_template.py +438 -0
  69. agentrun/knowledgebase/api/__data_async_template.py +414 -0
  70. agentrun/knowledgebase/api/__init__.py +19 -0
  71. agentrun/knowledgebase/api/control.py +606 -0
  72. agentrun/knowledgebase/api/data.py +624 -0
  73. agentrun/knowledgebase/client.py +311 -0
  74. agentrun/knowledgebase/knowledgebase.py +748 -0
  75. agentrun/knowledgebase/model.py +270 -0
  76. agentrun/memory_collection/__client_async_template.py +178 -0
  77. agentrun/memory_collection/__init__.py +37 -0
  78. agentrun/memory_collection/__memory_collection_async_template.py +457 -0
  79. agentrun/memory_collection/api/__init__.py +5 -0
  80. agentrun/memory_collection/api/control.py +610 -0
  81. agentrun/memory_collection/client.py +323 -0
  82. agentrun/memory_collection/memory_collection.py +844 -0
  83. agentrun/memory_collection/model.py +162 -0
  84. agentrun/model/__client_async_template.py +357 -0
  85. agentrun/model/__init__.py +57 -0
  86. agentrun/model/__model_proxy_async_template.py +270 -0
  87. agentrun/model/__model_service_async_template.py +267 -0
  88. agentrun/model/api/__init__.py +6 -0
  89. agentrun/model/api/control.py +1173 -0
  90. agentrun/model/api/data.py +196 -0
  91. agentrun/model/client.py +674 -0
  92. agentrun/model/model.py +235 -0
  93. agentrun/model/model_proxy.py +439 -0
  94. agentrun/model/model_service.py +438 -0
  95. agentrun/sandbox/__aio_sandbox_async_template.py +523 -0
  96. agentrun/sandbox/__browser_sandbox_async_template.py +110 -0
  97. agentrun/sandbox/__client_async_template.py +491 -0
  98. agentrun/sandbox/__code_interpreter_sandbox_async_template.py +463 -0
  99. agentrun/sandbox/__init__.py +69 -0
  100. agentrun/sandbox/__sandbox_async_template.py +463 -0
  101. agentrun/sandbox/__template_async_template.py +152 -0
  102. agentrun/sandbox/aio_sandbox.py +912 -0
  103. agentrun/sandbox/api/__aio_data_async_template.py +335 -0
  104. agentrun/sandbox/api/__browser_data_async_template.py +140 -0
  105. agentrun/sandbox/api/__code_interpreter_data_async_template.py +206 -0
  106. agentrun/sandbox/api/__init__.py +19 -0
  107. agentrun/sandbox/api/__sandbox_data_async_template.py +107 -0
  108. agentrun/sandbox/api/aio_data.py +551 -0
  109. agentrun/sandbox/api/browser_data.py +172 -0
  110. agentrun/sandbox/api/code_interpreter_data.py +396 -0
  111. agentrun/sandbox/api/control.py +1051 -0
  112. agentrun/sandbox/api/playwright_async.py +492 -0
  113. agentrun/sandbox/api/playwright_sync.py +492 -0
  114. agentrun/sandbox/api/sandbox_data.py +154 -0
  115. agentrun/sandbox/browser_sandbox.py +185 -0
  116. agentrun/sandbox/client.py +925 -0
  117. agentrun/sandbox/code_interpreter_sandbox.py +823 -0
  118. agentrun/sandbox/model.py +384 -0
  119. agentrun/sandbox/sandbox.py +848 -0
  120. agentrun/sandbox/template.py +217 -0
  121. agentrun/server/__init__.py +191 -0
  122. agentrun/server/agui_normalizer.py +180 -0
  123. agentrun/server/agui_protocol.py +797 -0
  124. agentrun/server/invoker.py +309 -0
  125. agentrun/server/model.py +427 -0
  126. agentrun/server/openai_protocol.py +535 -0
  127. agentrun/server/protocol.py +140 -0
  128. agentrun/server/server.py +208 -0
  129. agentrun/toolset/__client_async_template.py +62 -0
  130. agentrun/toolset/__init__.py +51 -0
  131. agentrun/toolset/__toolset_async_template.py +204 -0
  132. agentrun/toolset/api/__init__.py +17 -0
  133. agentrun/toolset/api/control.py +262 -0
  134. agentrun/toolset/api/mcp.py +100 -0
  135. agentrun/toolset/api/openapi.py +1251 -0
  136. agentrun/toolset/client.py +102 -0
  137. agentrun/toolset/model.py +321 -0
  138. agentrun/toolset/toolset.py +271 -0
  139. agentrun/utils/__data_api_async_template.py +721 -0
  140. agentrun/utils/__init__.py +5 -0
  141. agentrun/utils/__resource_async_template.py +158 -0
  142. agentrun/utils/config.py +270 -0
  143. agentrun/utils/control_api.py +105 -0
  144. agentrun/utils/data_api.py +1121 -0
  145. agentrun/utils/exception.py +151 -0
  146. agentrun/utils/helper.py +108 -0
  147. agentrun/utils/log.py +77 -0
  148. agentrun/utils/model.py +168 -0
  149. agentrun/utils/resource.py +291 -0
  150. agentrun_inner_test-0.0.62.dist-info/METADATA +265 -0
  151. agentrun_inner_test-0.0.62.dist-info/RECORD +154 -0
  152. agentrun_inner_test-0.0.62.dist-info/WHEEL +5 -0
  153. agentrun_inner_test-0.0.62.dist-info/licenses/LICENSE +201 -0
  154. agentrun_inner_test-0.0.62.dist-info/top_level.txt +1 -0
@@ -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
+ )
@@ -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)
@@ -0,0 +1,6 @@
1
+ """Model Service API 模块 / Model Service API Module"""
2
+
3
+ from .control import ModelControlAPI
4
+ from .data import ModelCompletionAPI, ModelDataAPI
5
+
6
+ __all__ = ["ModelControlAPI", "ModelCompletionAPI", "ModelDataAPI"]