dashscope 1.15.0__py3-none-any.whl → 1.18.0__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 dashscope might be problematic. Click here for more details.
- dashscope/__init__.py +57 -10
- dashscope/aigc/code_generation.py +12 -9
- dashscope/aigc/conversation.py +3 -0
- dashscope/aigc/generation.py +3 -0
- dashscope/aigc/image_synthesis.py +26 -6
- dashscope/aigc/multimodal_conversation.py +3 -0
- dashscope/api_entities/aiohttp_request.py +1 -0
- dashscope/api_entities/api_request_factory.py +28 -12
- dashscope/api_entities/dashscope_response.py +63 -0
- dashscope/api_entities/http_request.py +21 -31
- dashscope/api_entities/websocket_request.py +3 -0
- dashscope/app/application.py +16 -18
- dashscope/assistants/__init__.py +14 -0
- dashscope/assistants/assistant_types.py +164 -0
- dashscope/assistants/assistants.py +280 -0
- dashscope/assistants/files.py +189 -0
- dashscope/audio/asr/asr_phrase_manager.py +27 -5
- dashscope/audio/asr/recognition.py +10 -2
- dashscope/audio/asr/transcription.py +21 -3
- dashscope/audio/tts/speech_synthesizer.py +3 -0
- dashscope/cli.py +7 -7
- dashscope/client/base_api.py +317 -70
- dashscope/common/base_type.py +130 -0
- dashscope/common/constants.py +1 -0
- dashscope/common/error.py +4 -0
- dashscope/common/utils.py +159 -27
- dashscope/deployment.py +40 -6
- dashscope/embeddings/batch_text_embedding.py +24 -7
- dashscope/embeddings/multimodal_embedding.py +3 -0
- dashscope/embeddings/text_embedding.py +8 -1
- dashscope/files.py +107 -0
- dashscope/finetune.py +31 -7
- dashscope/model.py +9 -2
- dashscope/models.py +47 -0
- dashscope/nlp/understanding.py +2 -2
- dashscope/rerank/__init__.py +0 -0
- dashscope/rerank/text_rerank.py +67 -0
- dashscope/threads/__init__.py +24 -0
- dashscope/threads/messages/__init__.py +0 -0
- dashscope/threads/messages/files.py +111 -0
- dashscope/threads/messages/messages.py +218 -0
- dashscope/threads/runs/__init__.py +0 -0
- dashscope/threads/runs/runs.py +483 -0
- dashscope/threads/runs/steps.py +110 -0
- dashscope/threads/thread_types.py +651 -0
- dashscope/threads/threads.py +210 -0
- dashscope/tokenizers/tokenization.py +3 -0
- dashscope/utils/oss_utils.py +11 -0
- dashscope/version.py +1 -1
- {dashscope-1.15.0.dist-info → dashscope-1.18.0.dist-info}/METADATA +2 -3
- dashscope-1.18.0.dist-info/RECORD +84 -0
- dashscope-1.15.0.dist-info/RECORD +0 -66
- {dashscope-1.15.0.dist-info → dashscope-1.18.0.dist-info}/LICENSE +0 -0
- {dashscope-1.15.0.dist-info → dashscope-1.18.0.dist-info}/WHEEL +0 -0
- {dashscope-1.15.0.dist-info → dashscope-1.18.0.dist-info}/entry_points.txt +0 -0
- {dashscope-1.15.0.dist-info → dashscope-1.18.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import dataclasses
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from typing import Any, List
|
|
4
|
+
|
|
5
|
+
import dashscope
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def get_object_type(name: str):
|
|
9
|
+
dashscope_objects = {
|
|
10
|
+
'assistant': dashscope.Assistant,
|
|
11
|
+
'assistant.deleted': dashscope.DeleteResponse,
|
|
12
|
+
'thread.message': dashscope.ThreadMessage,
|
|
13
|
+
'thread.run': dashscope.Run,
|
|
14
|
+
'thread.run.step': dashscope.RunStep,
|
|
15
|
+
'thread.message.file': dashscope.MessageFile,
|
|
16
|
+
'assistant.file': dashscope.AssistantFile,
|
|
17
|
+
'thread': dashscope.Thread,
|
|
18
|
+
}
|
|
19
|
+
return dashscope_objects.get(name, None)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass(init=False)
|
|
23
|
+
class BaseObjectMixin(object):
|
|
24
|
+
__slots__ = ()
|
|
25
|
+
|
|
26
|
+
def __init__(self, **kwargs):
|
|
27
|
+
field_type_map = self._get_fields_type()
|
|
28
|
+
for k, v in kwargs.items():
|
|
29
|
+
field = field_type_map.get(k, None)
|
|
30
|
+
if field:
|
|
31
|
+
if dataclasses.is_dataclass(field.type): # process dataclasses
|
|
32
|
+
self.__setattr__(k, field.type(**v))
|
|
33
|
+
continue
|
|
34
|
+
|
|
35
|
+
if isinstance(v, dict):
|
|
36
|
+
object_name = v.get('object', None)
|
|
37
|
+
if object_name:
|
|
38
|
+
object_type = get_object_type(object_name)
|
|
39
|
+
if object_type:
|
|
40
|
+
self.__setattr__(k, object_type(**v))
|
|
41
|
+
else:
|
|
42
|
+
self.__setattr__(k, v)
|
|
43
|
+
else:
|
|
44
|
+
self.__setattr__(k, v)
|
|
45
|
+
elif isinstance(v, list):
|
|
46
|
+
obj_list = self._init_list_element_recursive(field, v)
|
|
47
|
+
self.__setattr__(k, obj_list)
|
|
48
|
+
else:
|
|
49
|
+
self.__setattr__(k, v)
|
|
50
|
+
|
|
51
|
+
def _init_list_element_recursive(self, field, items: list) -> List[Any]:
|
|
52
|
+
obj_list = []
|
|
53
|
+
for item in items:
|
|
54
|
+
if field:
|
|
55
|
+
# current only support List[cls_name],
|
|
56
|
+
# not support List[cls_nam1, cls_name2]
|
|
57
|
+
element_type = field.type.__args__[0]
|
|
58
|
+
if dataclasses.is_dataclass(element_type):
|
|
59
|
+
obj_list.append(element_type(**item))
|
|
60
|
+
continue
|
|
61
|
+
|
|
62
|
+
if isinstance(item, dict):
|
|
63
|
+
object_name = item.get('object', None)
|
|
64
|
+
if object_name:
|
|
65
|
+
object_type = get_object_type(object_name)
|
|
66
|
+
if object_type:
|
|
67
|
+
obj_list.append(object_type(**item))
|
|
68
|
+
else:
|
|
69
|
+
obj_list.append(item)
|
|
70
|
+
else:
|
|
71
|
+
obj_list.append(item)
|
|
72
|
+
elif isinstance(item, list):
|
|
73
|
+
obj_list.append(self._init_list_element_recursive(item))
|
|
74
|
+
else:
|
|
75
|
+
obj_list.append(item)
|
|
76
|
+
return obj_list
|
|
77
|
+
|
|
78
|
+
def _get_fields_type(self):
|
|
79
|
+
field_type_map = {}
|
|
80
|
+
if dataclasses.is_dataclass(self):
|
|
81
|
+
for field in dataclasses.fields(self):
|
|
82
|
+
field_type_map[field.name] = field
|
|
83
|
+
return field_type_map
|
|
84
|
+
|
|
85
|
+
def __setitem__(self, __key: Any, __value: Any) -> None:
|
|
86
|
+
return self.__setattr__(__key, __value)
|
|
87
|
+
|
|
88
|
+
def __getitem__(self, __key: Any) -> Any:
|
|
89
|
+
return self.__getattribute__(__key)
|
|
90
|
+
|
|
91
|
+
def __delitem__(self, key):
|
|
92
|
+
self.__delattr__(key)
|
|
93
|
+
|
|
94
|
+
def _recursive_to_str__(self, input_object) -> Any:
|
|
95
|
+
if isinstance(input_object, list):
|
|
96
|
+
output_object = []
|
|
97
|
+
for item in input_object:
|
|
98
|
+
output_object.append(self._recursive_to_str__(item))
|
|
99
|
+
return output_object
|
|
100
|
+
elif dataclasses.is_dataclass(input_object):
|
|
101
|
+
output_object = {}
|
|
102
|
+
for field in dataclasses.fields(input_object):
|
|
103
|
+
if hasattr(input_object, field.name):
|
|
104
|
+
output_object[field.name] = self._recursive_to_str__(
|
|
105
|
+
getattr(input_object, field.name))
|
|
106
|
+
return output_object
|
|
107
|
+
else:
|
|
108
|
+
return input_object
|
|
109
|
+
|
|
110
|
+
def __str__(self) -> str:
|
|
111
|
+
real_dict = self.__dict__
|
|
112
|
+
self_fields = dataclasses.fields(self)
|
|
113
|
+
for field in self_fields:
|
|
114
|
+
if hasattr(self, field.name):
|
|
115
|
+
real_dict[field.name] = getattr(self, field.name)
|
|
116
|
+
output_object = {}
|
|
117
|
+
for key, value in real_dict.items():
|
|
118
|
+
output_object[key] = self._recursive_to_str__(value)
|
|
119
|
+
return str(output_object)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
@dataclass(init=False)
|
|
123
|
+
class BaseList(BaseObjectMixin):
|
|
124
|
+
status_code: int
|
|
125
|
+
has_more: bool
|
|
126
|
+
last_id: str
|
|
127
|
+
first_id: str
|
|
128
|
+
|
|
129
|
+
def __init__(self, **kwargs):
|
|
130
|
+
super().__init__(**kwargs)
|
dashscope/common/constants.py
CHANGED
dashscope/common/error.py
CHANGED
dashscope/common/utils.py
CHANGED
|
@@ -2,14 +2,18 @@ import asyncio
|
|
|
2
2
|
import json
|
|
3
3
|
import os
|
|
4
4
|
import platform
|
|
5
|
+
from dataclasses import dataclass
|
|
5
6
|
from http import HTTPStatus
|
|
6
7
|
from typing import Dict
|
|
7
8
|
from urllib.parse import urlparse
|
|
8
9
|
|
|
9
10
|
import aiohttp
|
|
10
11
|
import requests
|
|
12
|
+
|
|
11
13
|
from dashscope.api_entities.dashscope_response import DashScopeAPIResponse
|
|
12
14
|
from dashscope.common.api_key import get_default_api_key
|
|
15
|
+
from dashscope.common.constants import SSE_CONTENT_TYPE
|
|
16
|
+
from dashscope.common.logging import logger
|
|
13
17
|
from dashscope.version import __version__
|
|
14
18
|
|
|
15
19
|
|
|
@@ -126,7 +130,7 @@ def join_url(base_url, *args):
|
|
|
126
130
|
base_url = base_url + '/'
|
|
127
131
|
url = base_url
|
|
128
132
|
for arg in args:
|
|
129
|
-
if arg:
|
|
133
|
+
if arg is not None:
|
|
130
134
|
url += arg + '/'
|
|
131
135
|
return url[:-1]
|
|
132
136
|
|
|
@@ -162,13 +166,63 @@ async def _handle_aiohttp_response(response: aiohttp.ClientResponse):
|
|
|
162
166
|
message=msg)
|
|
163
167
|
|
|
164
168
|
|
|
169
|
+
@dataclass
|
|
170
|
+
class SSEEvent:
|
|
171
|
+
id: str
|
|
172
|
+
eventType: str
|
|
173
|
+
data: str
|
|
174
|
+
|
|
175
|
+
def __init__(self, id: str, type: str, data: str):
|
|
176
|
+
self.id = id
|
|
177
|
+
self.eventType = type
|
|
178
|
+
self.data = data
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _handle_stream(response: requests.Response):
|
|
182
|
+
# TODO define done message.
|
|
183
|
+
is_error = False
|
|
184
|
+
status_code = HTTPStatus.INTERNAL_SERVER_ERROR
|
|
185
|
+
event = SSEEvent(None, None, None)
|
|
186
|
+
eventType = None
|
|
187
|
+
for line in response.iter_lines():
|
|
188
|
+
if line:
|
|
189
|
+
line = line.decode('utf8')
|
|
190
|
+
line = line.rstrip('\n').rstrip('\r')
|
|
191
|
+
print(line)
|
|
192
|
+
if line.startswith('id:'):
|
|
193
|
+
id = line[len('id:'):]
|
|
194
|
+
event.id = id.strip()
|
|
195
|
+
elif line.startswith('event:'):
|
|
196
|
+
eventType = line[len('event:'):]
|
|
197
|
+
event.eventType = eventType.strip()
|
|
198
|
+
if eventType == 'error':
|
|
199
|
+
is_error = True
|
|
200
|
+
elif line.startswith('status:'):
|
|
201
|
+
status_code = line[len('status:'):]
|
|
202
|
+
status_code = int(status_code.strip())
|
|
203
|
+
elif line.startswith('data:'):
|
|
204
|
+
line = line[len('data:'):]
|
|
205
|
+
event.data = line.strip()
|
|
206
|
+
if eventType is not None and eventType == 'done':
|
|
207
|
+
continue
|
|
208
|
+
yield (is_error, status_code, event)
|
|
209
|
+
if is_error:
|
|
210
|
+
break
|
|
211
|
+
else:
|
|
212
|
+
continue # ignore heartbeat...
|
|
213
|
+
|
|
214
|
+
|
|
165
215
|
def _handle_http_failed_response(
|
|
166
|
-
response: requests.Response
|
|
216
|
+
response: requests.Response,
|
|
217
|
+
flattened_output: bool = False) -> DashScopeAPIResponse:
|
|
167
218
|
msg = ''
|
|
168
219
|
code = None
|
|
169
220
|
request_id = ''
|
|
170
221
|
if 'application/json' in response.headers.get('content-type', ''):
|
|
171
222
|
error = response.json()
|
|
223
|
+
if flattened_output:
|
|
224
|
+
error['status_code'] = response.status_code
|
|
225
|
+
return error
|
|
172
226
|
if 'message' in error:
|
|
173
227
|
msg = error['message']
|
|
174
228
|
if 'msg' in error:
|
|
@@ -183,37 +237,115 @@ def _handle_http_failed_response(
|
|
|
183
237
|
message=msg)
|
|
184
238
|
else:
|
|
185
239
|
msg = response.content.decode('utf-8')
|
|
240
|
+
if flattened_output:
|
|
241
|
+
return {'status_code': response.status_code, 'message': msg}
|
|
186
242
|
return DashScopeAPIResponse(request_id=request_id,
|
|
187
243
|
status_code=response.status_code,
|
|
188
244
|
code='Unknown',
|
|
189
245
|
message=msg)
|
|
190
246
|
|
|
191
247
|
|
|
192
|
-
def _handle_http_response(response: requests.Response
|
|
248
|
+
def _handle_http_response(response: requests.Response,
|
|
249
|
+
flattened_output: bool = False):
|
|
250
|
+
response = _handle_http_stream_response(response, flattened_output)
|
|
251
|
+
_, output = next(response)
|
|
252
|
+
try:
|
|
253
|
+
next(response)
|
|
254
|
+
except StopIteration:
|
|
255
|
+
pass
|
|
256
|
+
return output
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def _handle_http_stream_response(response: requests.Response,
|
|
260
|
+
flattened_output: bool = False):
|
|
193
261
|
request_id = ''
|
|
194
|
-
if response.status_code == HTTPStatus.OK
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
262
|
+
if (response.status_code == HTTPStatus.OK
|
|
263
|
+
and SSE_CONTENT_TYPE in response.headers.get('content-type', '')):
|
|
264
|
+
for is_error, status_code, event in _handle_stream(response):
|
|
265
|
+
if not is_error:
|
|
266
|
+
try:
|
|
267
|
+
output = None
|
|
268
|
+
usage = None
|
|
269
|
+
msg = json.loads(event.data)
|
|
270
|
+
if flattened_output:
|
|
271
|
+
msg['status_code'] = response.status_code
|
|
272
|
+
yield event.eventType, msg
|
|
273
|
+
else:
|
|
274
|
+
logger.debug('Stream message: %s' % msg)
|
|
275
|
+
if not is_error:
|
|
276
|
+
if 'output' in msg:
|
|
277
|
+
output = msg['output']
|
|
278
|
+
if 'usage' in msg:
|
|
279
|
+
usage = msg['usage']
|
|
280
|
+
if 'request_id' in msg:
|
|
281
|
+
request_id = msg['request_id']
|
|
282
|
+
yield event.eventType, DashScopeAPIResponse(
|
|
283
|
+
request_id=request_id,
|
|
284
|
+
status_code=HTTPStatus.OK,
|
|
285
|
+
output=output,
|
|
286
|
+
usage=usage)
|
|
287
|
+
except json.JSONDecodeError as e:
|
|
288
|
+
if flattened_output:
|
|
289
|
+
yield event.eventType, {
|
|
290
|
+
'status_code': response.status_code,
|
|
291
|
+
'message': e.message
|
|
292
|
+
}
|
|
293
|
+
else:
|
|
294
|
+
yield event.eventType, DashScopeAPIResponse(
|
|
295
|
+
request_id=request_id,
|
|
296
|
+
status_code=HTTPStatus.BAD_REQUEST,
|
|
297
|
+
output=None,
|
|
298
|
+
code='Unknown',
|
|
299
|
+
message=event.data)
|
|
300
|
+
continue
|
|
301
|
+
else:
|
|
302
|
+
if flattened_output:
|
|
303
|
+
yield event.eventType, {
|
|
304
|
+
'status_code': status_code,
|
|
305
|
+
'message': event.data
|
|
306
|
+
}
|
|
307
|
+
else:
|
|
308
|
+
msg = json.loads(event.eventType)
|
|
309
|
+
yield event.eventType, DashScopeAPIResponse(
|
|
310
|
+
request_id=request_id,
|
|
311
|
+
status_code=status_code,
|
|
312
|
+
output=None,
|
|
313
|
+
code=msg['code']
|
|
314
|
+
if 'code' in msg else None, # noqa E501
|
|
315
|
+
message=msg['message']
|
|
316
|
+
if 'message' in msg else None) # noqa E501
|
|
317
|
+
elif response.status_code == HTTPStatus.OK or response.status_code == HTTPStatus.CREATED:
|
|
199
318
|
json_content = response.json()
|
|
200
|
-
if
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
319
|
+
if flattened_output:
|
|
320
|
+
json_content['status_code'] = response.status_code
|
|
321
|
+
yield None, json_content
|
|
322
|
+
else:
|
|
323
|
+
output = None
|
|
324
|
+
usage = None
|
|
325
|
+
code = None
|
|
326
|
+
msg = ''
|
|
327
|
+
if 'data' in json_content:
|
|
328
|
+
output = json_content['data']
|
|
329
|
+
if 'code' in json_content:
|
|
330
|
+
code = json_content['code']
|
|
331
|
+
if 'message' in json_content:
|
|
332
|
+
msg = json_content['message']
|
|
333
|
+
if 'output' in json_content:
|
|
334
|
+
output = json_content['output']
|
|
335
|
+
if 'usage' in json_content:
|
|
336
|
+
usage = json_content['usage']
|
|
337
|
+
if 'request_id' in json_content:
|
|
338
|
+
request_id = json_content['request_id']
|
|
339
|
+
json_content.pop('request_id', None)
|
|
340
|
+
|
|
341
|
+
if 'data' not in json_content and 'output' not in json_content:
|
|
342
|
+
output = json_content
|
|
343
|
+
|
|
344
|
+
yield None, DashScopeAPIResponse(request_id=request_id,
|
|
345
|
+
status_code=response.status_code,
|
|
346
|
+
code=code,
|
|
347
|
+
output=output,
|
|
348
|
+
usage=usage,
|
|
349
|
+
message=msg)
|
|
218
350
|
else:
|
|
219
|
-
|
|
351
|
+
yield None, _handle_http_failed_response(response, flattened_output)
|
dashscope/deployment.py
CHANGED
|
@@ -15,6 +15,7 @@ class Deployment(CreateMixin, DeleteMixin, ListMixin, GetMixin,
|
|
|
15
15
|
version: str = None,
|
|
16
16
|
suffix: str = None,
|
|
17
17
|
api_key: str = None,
|
|
18
|
+
workspace: str = None,
|
|
18
19
|
**kwargs) -> DashScopeAPIResponse:
|
|
19
20
|
"""Call to deployment a model service.
|
|
20
21
|
|
|
@@ -27,6 +28,7 @@ class Deployment(CreateMixin, DeleteMixin, ListMixin, GetMixin,
|
|
|
27
28
|
Defaults to None.
|
|
28
29
|
capacity (int, optional): The model service capacity.
|
|
29
30
|
api_key (str, optional): The api-key. Defaults to None.
|
|
31
|
+
workspace (str): The dashscope workspace id.
|
|
30
32
|
|
|
31
33
|
Returns:
|
|
32
34
|
DashScopeAPIResponse: _description_
|
|
@@ -37,13 +39,17 @@ class Deployment(CreateMixin, DeleteMixin, ListMixin, GetMixin,
|
|
|
37
39
|
req['model_version'] = version
|
|
38
40
|
if suffix is not None:
|
|
39
41
|
req['suffix'] = suffix
|
|
40
|
-
return super().call(req,
|
|
42
|
+
return super().call(req,
|
|
43
|
+
api_key=api_key,
|
|
44
|
+
workspace=workspace,
|
|
45
|
+
**kwargs)
|
|
41
46
|
|
|
42
47
|
@classmethod
|
|
43
48
|
def list(cls,
|
|
44
49
|
page_no=1,
|
|
45
50
|
page_size=10,
|
|
46
51
|
api_key: str = None,
|
|
52
|
+
workspace: str = None,
|
|
47
53
|
**kwargs) -> DashScopeAPIResponse:
|
|
48
54
|
"""List deployments.
|
|
49
55
|
|
|
@@ -52,49 +58,65 @@ class Deployment(CreateMixin, DeleteMixin, ListMixin, GetMixin,
|
|
|
52
58
|
will get by default rule(TODO: api key doc). Defaults to None.
|
|
53
59
|
page_no (int, optional): Page number. Defaults to 1.
|
|
54
60
|
page_size (int, optional): Items per page. Defaults to 10.
|
|
61
|
+
workspace (str): The dashscope workspace id.
|
|
55
62
|
|
|
56
63
|
Returns:
|
|
57
64
|
DashScopeAPIResponse: The deployment list.
|
|
58
65
|
"""
|
|
59
|
-
return super().list(page_no,
|
|
66
|
+
return super().list(page_no,
|
|
67
|
+
page_size,
|
|
68
|
+
api_key,
|
|
69
|
+
workspace=workspace,
|
|
70
|
+
**kwargs)
|
|
60
71
|
|
|
61
72
|
@classmethod
|
|
62
73
|
def get(cls,
|
|
63
74
|
deployed_model: str,
|
|
64
75
|
api_key: str = None,
|
|
76
|
+
workspace: str = None,
|
|
65
77
|
**kwargs) -> DashScopeAPIResponse:
|
|
66
78
|
"""Get model deployment information.
|
|
67
79
|
|
|
68
80
|
Args:
|
|
69
81
|
deployed_model (str): The deployment_id.
|
|
70
82
|
api_key (str, optional): The api key. Defaults to None.
|
|
83
|
+
workspace (str): The dashscope workspace id.
|
|
71
84
|
|
|
72
85
|
Returns:
|
|
73
86
|
DashScopeAPIResponse: The deployment information.
|
|
74
87
|
"""
|
|
75
|
-
return super().get(deployed_model,
|
|
88
|
+
return super().get(deployed_model,
|
|
89
|
+
api_key,
|
|
90
|
+
workspace=workspace,
|
|
91
|
+
**kwargs)
|
|
76
92
|
|
|
77
93
|
@classmethod
|
|
78
94
|
def delete(cls,
|
|
79
95
|
deployment_id: str,
|
|
80
96
|
api_key: str = None,
|
|
97
|
+
workspace: str = None,
|
|
81
98
|
**kwargs) -> DashScopeAPIResponse:
|
|
82
99
|
"""Delete model deployment.
|
|
83
100
|
|
|
84
101
|
Args:
|
|
85
102
|
deployment_id (str): The deployment id.
|
|
86
103
|
api_key (str, optional): The api key. Defaults to None.
|
|
104
|
+
workspace (str): The dashscope workspace id.
|
|
87
105
|
|
|
88
106
|
Returns:
|
|
89
107
|
DashScopeAPIResponse: The delete result.
|
|
90
108
|
"""
|
|
91
|
-
return super().delete(deployment_id,
|
|
109
|
+
return super().delete(deployment_id,
|
|
110
|
+
api_key,
|
|
111
|
+
workspace=workspace,
|
|
112
|
+
**kwargs)
|
|
92
113
|
|
|
93
114
|
@classmethod
|
|
94
115
|
def update(cls,
|
|
95
116
|
deployment_id: str,
|
|
96
117
|
version: str,
|
|
97
118
|
api_key: str = None,
|
|
119
|
+
workspace: str = None,
|
|
98
120
|
**kwargs) -> DashScopeAPIResponse:
|
|
99
121
|
"""Update model deployment.
|
|
100
122
|
|
|
@@ -102,18 +124,24 @@ class Deployment(CreateMixin, DeleteMixin, ListMixin, GetMixin,
|
|
|
102
124
|
deployment_id (str): The deployment id.
|
|
103
125
|
version (str): The target model version.
|
|
104
126
|
api_key (str, optional): The api key. Defaults to None.
|
|
127
|
+
workspace (str): The dashscope workspace id.
|
|
105
128
|
|
|
106
129
|
Returns:
|
|
107
130
|
DashScopeAPIResponse: The delete result.
|
|
108
131
|
"""
|
|
109
132
|
req = {'deployment_model': deployment_id, 'model_version': version}
|
|
110
|
-
return super().put(deployment_id,
|
|
133
|
+
return super().put(deployment_id,
|
|
134
|
+
req,
|
|
135
|
+
api_key,
|
|
136
|
+
workspace=workspace,
|
|
137
|
+
**kwargs)
|
|
111
138
|
|
|
112
139
|
@classmethod
|
|
113
140
|
def scale(cls,
|
|
114
141
|
deployment_id: str,
|
|
115
142
|
capacity: int,
|
|
116
143
|
api_key: str = None,
|
|
144
|
+
workspace: str = None,
|
|
117
145
|
**kwargs) -> DashScopeAPIResponse:
|
|
118
146
|
"""Scaling model deployment.
|
|
119
147
|
|
|
@@ -126,4 +154,10 @@ class Deployment(CreateMixin, DeleteMixin, ListMixin, GetMixin,
|
|
|
126
154
|
DashScopeAPIResponse: The delete result.
|
|
127
155
|
"""
|
|
128
156
|
req = {'deployed_model': deployment_id, 'capacity': capacity}
|
|
129
|
-
|
|
157
|
+
path = '%s/%s/scale' % (cls.SUB_PATH.lower(), deployment_id)
|
|
158
|
+
return super().put(deployment_id,
|
|
159
|
+
req,
|
|
160
|
+
path=path,
|
|
161
|
+
api_key=api_key,
|
|
162
|
+
workspace=workspace,
|
|
163
|
+
**kwargs)
|
|
@@ -22,6 +22,7 @@ class BatchTextEmbedding(BaseAsyncApi):
|
|
|
22
22
|
model: str,
|
|
23
23
|
url: str,
|
|
24
24
|
api_key: str = None,
|
|
25
|
+
workspace: str = None,
|
|
25
26
|
**kwargs) -> BatchTextEmbeddingResponse:
|
|
26
27
|
"""Call async text embedding service and get result.
|
|
27
28
|
|
|
@@ -30,6 +31,7 @@ class BatchTextEmbedding(BaseAsyncApi):
|
|
|
30
31
|
url (Any): The async request file url, which contains text
|
|
31
32
|
to embedding line by line.
|
|
32
33
|
api_key (str, optional): The api api_key. Defaults to None.
|
|
34
|
+
workspace (str): The dashscope workspace id.
|
|
33
35
|
**kwargs:
|
|
34
36
|
text_type(str, `optional`): [query|document], After the
|
|
35
37
|
text is converted into a vector, it can be applied to
|
|
@@ -47,13 +49,18 @@ class BatchTextEmbedding(BaseAsyncApi):
|
|
|
47
49
|
Returns:
|
|
48
50
|
AsyncTextEmbeddingResponse: The async text embedding task result.
|
|
49
51
|
"""
|
|
50
|
-
return super().call(model,
|
|
52
|
+
return super().call(model,
|
|
53
|
+
url,
|
|
54
|
+
api_key=api_key,
|
|
55
|
+
workspace=workspace,
|
|
56
|
+
**kwargs)
|
|
51
57
|
|
|
52
58
|
@classmethod
|
|
53
59
|
def async_call(cls,
|
|
54
60
|
model: str,
|
|
55
61
|
url: str,
|
|
56
62
|
api_key: str = None,
|
|
63
|
+
workspace: str = None,
|
|
57
64
|
**kwargs) -> BatchTextEmbeddingResponse:
|
|
58
65
|
"""Create a async text embedding task, and return task information.
|
|
59
66
|
|
|
@@ -62,6 +69,7 @@ class BatchTextEmbedding(BaseAsyncApi):
|
|
|
62
69
|
url (Any): The async request file url, which contains text
|
|
63
70
|
to embedding line by line.
|
|
64
71
|
api_key (str, optional): The api api_key. Defaults to None.
|
|
72
|
+
workspace (str): The dashscope workspace id.
|
|
65
73
|
**kwargs:
|
|
66
74
|
text_type(str, `optional`): [query|document], After the
|
|
67
75
|
text is converted into a vector, it can be applied to
|
|
@@ -91,47 +99,53 @@ class BatchTextEmbedding(BaseAsyncApi):
|
|
|
91
99
|
function=BatchTextEmbedding.function,
|
|
92
100
|
api_key=api_key,
|
|
93
101
|
input=input,
|
|
102
|
+
workspace=workspace,
|
|
94
103
|
**kwargs)
|
|
95
104
|
return BatchTextEmbeddingResponse.from_api_response(response)
|
|
96
105
|
|
|
97
106
|
@classmethod
|
|
98
107
|
def fetch(cls,
|
|
99
108
|
task: Union[str, BatchTextEmbeddingResponse],
|
|
100
|
-
api_key: str = None
|
|
109
|
+
api_key: str = None,
|
|
110
|
+
workspace: str = None) -> BatchTextEmbeddingResponse:
|
|
101
111
|
"""Fetch async text embedding task status or result.
|
|
102
112
|
|
|
103
113
|
Args:
|
|
104
114
|
task (Union[str, AsyncTextEmbeddingResponse]): The task_id or
|
|
105
115
|
AsyncTextEmbeddingResponse return by async_call().
|
|
106
116
|
api_key (str, optional): The api api_key. Defaults to None.
|
|
117
|
+
workspace (str): The dashscope workspace id.
|
|
107
118
|
|
|
108
119
|
Returns:
|
|
109
120
|
AsyncTextEmbeddingResponse: The task status or result.
|
|
110
121
|
"""
|
|
111
|
-
response = super().fetch(task, api_key)
|
|
122
|
+
response = super().fetch(task, api_key, workspace=workspace)
|
|
112
123
|
return BatchTextEmbeddingResponse.from_api_response(response)
|
|
113
124
|
|
|
114
125
|
@classmethod
|
|
115
126
|
def wait(cls,
|
|
116
127
|
task: Union[str, BatchTextEmbeddingResponse],
|
|
117
|
-
api_key: str = None
|
|
128
|
+
api_key: str = None,
|
|
129
|
+
workspace: str = None) -> BatchTextEmbeddingResponse:
|
|
118
130
|
"""Wait for async text embedding task to complete, and return the result.
|
|
119
131
|
|
|
120
132
|
Args:
|
|
121
133
|
task (Union[str, AsyncTextEmbeddingResponse]): The task_id or
|
|
122
134
|
AsyncTextEmbeddingResponse return by async_call().
|
|
123
135
|
api_key (str, optional): The api api_key. Defaults to None.
|
|
136
|
+
workspace (str): The dashscope workspace id.
|
|
124
137
|
|
|
125
138
|
Returns:
|
|
126
139
|
AsyncTextEmbeddingResponse: The task result.
|
|
127
140
|
"""
|
|
128
|
-
response = super().wait(task, api_key)
|
|
141
|
+
response = super().wait(task, api_key, workspace=workspace)
|
|
129
142
|
return BatchTextEmbeddingResponse.from_api_response(response)
|
|
130
143
|
|
|
131
144
|
@classmethod
|
|
132
145
|
def cancel(cls,
|
|
133
146
|
task: Union[str, BatchTextEmbeddingResponse],
|
|
134
|
-
api_key: str = None
|
|
147
|
+
api_key: str = None,
|
|
148
|
+
workspace: str = None) -> DashScopeAPIResponse:
|
|
135
149
|
"""Cancel async text embedding task.
|
|
136
150
|
Only tasks whose status is PENDING can be canceled.
|
|
137
151
|
|
|
@@ -139,11 +153,12 @@ class BatchTextEmbedding(BaseAsyncApi):
|
|
|
139
153
|
task (Union[str, AsyncTextEmbeddingResponse]): The task_id or
|
|
140
154
|
AsyncTextEmbeddingResponse return by async_call().
|
|
141
155
|
api_key (str, optional): The api api_key. Defaults to None.
|
|
156
|
+
workspace (str): The dashscope workspace id.
|
|
142
157
|
|
|
143
158
|
Returns:
|
|
144
159
|
DashScopeAPIResponse: The response data.
|
|
145
160
|
"""
|
|
146
|
-
return super().cancel(task, api_key)
|
|
161
|
+
return super().cancel(task, api_key, workspace=workspace)
|
|
147
162
|
|
|
148
163
|
@classmethod
|
|
149
164
|
def list(cls,
|
|
@@ -156,6 +171,7 @@ class BatchTextEmbedding(BaseAsyncApi):
|
|
|
156
171
|
page_no: int = 1,
|
|
157
172
|
page_size: int = 10,
|
|
158
173
|
api_key: str = None,
|
|
174
|
+
workspace: str = None,
|
|
159
175
|
**kwargs) -> DashScopeAPIResponse:
|
|
160
176
|
"""List async tasks.
|
|
161
177
|
|
|
@@ -186,4 +202,5 @@ class BatchTextEmbedding(BaseAsyncApi):
|
|
|
186
202
|
page_no=page_no,
|
|
187
203
|
page_size=page_size,
|
|
188
204
|
api_key=api_key,
|
|
205
|
+
workspace=workspace,
|
|
189
206
|
**kwargs)
|
|
@@ -55,6 +55,7 @@ class MultiModalEmbedding(BaseApi):
|
|
|
55
55
|
model: str,
|
|
56
56
|
input: List[MultiModalEmbeddingItemBase],
|
|
57
57
|
api_key: str = None,
|
|
58
|
+
workspace: str = None,
|
|
58
59
|
**kwargs) -> DashScopeAPIResponse:
|
|
59
60
|
"""Get embedding multimodal contents..
|
|
60
61
|
|
|
@@ -62,6 +63,7 @@ class MultiModalEmbedding(BaseApi):
|
|
|
62
63
|
model (str): The embedding model name.
|
|
63
64
|
input (List[MultiModalEmbeddingElement]): The embedding elements,
|
|
64
65
|
every element include data, modal, factor field.
|
|
66
|
+
workspace (str): The dashscope workspace id.
|
|
65
67
|
**kwargs:
|
|
66
68
|
auto_truncation(bool, `optional`): Automatically truncate
|
|
67
69
|
audio longer than 15 seconds or text longer than 70 words.
|
|
@@ -89,6 +91,7 @@ class MultiModalEmbedding(BaseApi):
|
|
|
89
91
|
task=MultiModalEmbedding.task,
|
|
90
92
|
function=function,
|
|
91
93
|
api_key=api_key,
|
|
94
|
+
workspace=workspace,
|
|
92
95
|
**kwargs)
|
|
93
96
|
|
|
94
97
|
@classmethod
|