dashscope 1.22.2__py3-none-any.whl → 1.23.1__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 +3 -1
- dashscope/aigc/__init__.py +2 -0
- dashscope/aigc/chat_completion.py +282 -0
- dashscope/aigc/code_generation.py +2 -0
- dashscope/aigc/conversation.py +2 -0
- dashscope/aigc/generation.py +2 -0
- dashscope/aigc/image_synthesis.py +2 -0
- dashscope/aigc/multimodal_conversation.py +2 -0
- dashscope/aigc/video_synthesis.py +2 -0
- dashscope/api_entities/aiohttp_request.py +3 -0
- dashscope/api_entities/api_request_data.py +3 -0
- dashscope/api_entities/api_request_factory.py +2 -0
- dashscope/api_entities/base_request.py +2 -0
- dashscope/api_entities/chat_completion_types.py +344 -0
- dashscope/api_entities/dashscope_response.py +63 -0
- dashscope/api_entities/http_request.py +3 -0
- dashscope/api_entities/websocket_request.py +3 -0
- dashscope/app/__init__.py +2 -0
- dashscope/app/application.py +17 -15
- dashscope/app/application_response.py +1 -1
- dashscope/assistants/__init__.py +2 -0
- dashscope/assistants/assistant_types.py +2 -0
- dashscope/assistants/assistants.py +2 -0
- dashscope/assistants/files.py +2 -0
- dashscope/audio/__init__.py +4 -2
- dashscope/audio/asr/__init__.py +2 -0
- dashscope/audio/asr/asr_phrase_manager.py +2 -0
- dashscope/audio/asr/recognition.py +5 -0
- dashscope/audio/asr/transcription.py +3 -0
- dashscope/audio/asr/translation_recognizer.py +2 -0
- dashscope/audio/asr/vocabulary.py +3 -0
- dashscope/audio/qwen_tts/__init__.py +5 -0
- dashscope/audio/qwen_tts/speech_synthesizer.py +77 -0
- dashscope/audio/tts/__init__.py +2 -0
- dashscope/audio/tts/speech_synthesizer.py +2 -0
- dashscope/audio/tts_v2/__init__.py +2 -0
- dashscope/audio/tts_v2/enrollment.py +3 -0
- dashscope/audio/tts_v2/speech_synthesizer.py +4 -1
- dashscope/client/base_api.py +4 -1
- dashscope/common/api_key.py +2 -0
- dashscope/common/base_type.py +2 -0
- dashscope/common/constants.py +2 -0
- dashscope/common/env.py +2 -0
- dashscope/common/error.py +3 -0
- dashscope/common/logging.py +2 -0
- dashscope/common/message_manager.py +2 -0
- dashscope/common/utils.py +3 -0
- dashscope/customize/customize_types.py +2 -0
- dashscope/customize/deployments.py +2 -0
- dashscope/customize/finetunes.py +2 -0
- dashscope/embeddings/__init__.py +2 -0
- dashscope/embeddings/batch_text_embedding.py +2 -0
- dashscope/embeddings/batch_text_embedding_response.py +4 -1
- dashscope/embeddings/multimodal_embedding.py +2 -0
- dashscope/embeddings/text_embedding.py +2 -0
- dashscope/files.py +2 -0
- dashscope/io/input_output.py +2 -0
- dashscope/model.py +2 -0
- dashscope/models.py +2 -0
- dashscope/nlp/understanding.py +2 -0
- dashscope/protocol/websocket.py +3 -0
- dashscope/rerank/text_rerank.py +2 -0
- dashscope/threads/__init__.py +2 -0
- dashscope/threads/messages/files.py +2 -0
- dashscope/threads/messages/messages.py +2 -0
- dashscope/threads/runs/runs.py +2 -0
- dashscope/threads/runs/steps.py +2 -0
- dashscope/threads/thread_types.py +2 -0
- dashscope/threads/threads.py +2 -0
- dashscope/tokenizers/__init__.py +2 -0
- dashscope/tokenizers/qwen_tokenizer.py +2 -0
- dashscope/tokenizers/tokenization.py +2 -0
- dashscope/tokenizers/tokenizer.py +2 -0
- dashscope/tokenizers/tokenizer_base.py +2 -0
- dashscope/utils/oss_utils.py +3 -0
- dashscope/version.py +3 -1
- {dashscope-1.22.2.dist-info → dashscope-1.23.1.dist-info}/LICENSE +2 -4
- {dashscope-1.22.2.dist-info → dashscope-1.23.1.dist-info}/METADATA +1 -1
- dashscope-1.23.1.dist-info/RECORD +95 -0
- dashscope/audio/asr/transcribe.py +0 -270
- dashscope/deployment.py +0 -163
- dashscope/file.py +0 -94
- dashscope/finetune.py +0 -175
- dashscope-1.22.2.dist-info/RECORD +0 -95
- {dashscope-1.22.2.dist-info → dashscope-1.23.1.dist-info}/WHEEL +0 -0
- {dashscope-1.22.2.dist-info → dashscope-1.23.1.dist-info}/entry_points.txt +0 -0
- {dashscope-1.22.2.dist-info → dashscope-1.23.1.dist-info}/top_level.txt +0 -0
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
import os
|
|
3
|
-
from http import HTTPStatus
|
|
4
|
-
from typing import Any, Dict
|
|
5
|
-
from urllib.parse import urlparse
|
|
6
|
-
|
|
7
|
-
import aiohttp
|
|
8
|
-
|
|
9
|
-
from dashscope.api_entities.dashscope_response import DashScopeAPIResponse
|
|
10
|
-
from dashscope.client.base_api import BaseApi
|
|
11
|
-
from dashscope.common.constants import ApiProtocol, HTTPMethod
|
|
12
|
-
from dashscope.common.error import InputRequired
|
|
13
|
-
from dashscope.common.utils import _get_task_group_and_task
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class Transcribe(BaseApi):
|
|
17
|
-
"""API for File Transcriber models.
|
|
18
|
-
|
|
19
|
-
"""
|
|
20
|
-
|
|
21
|
-
MAX_QUERY_TRY_COUNT = 3
|
|
22
|
-
|
|
23
|
-
@classmethod
|
|
24
|
-
def call(cls, model: str, file: str, **kwargs) -> DashScopeAPIResponse:
|
|
25
|
-
"""Call file transcriber model service.
|
|
26
|
-
|
|
27
|
-
Args:
|
|
28
|
-
model (str): The requested model, such as paraformer-16k-1
|
|
29
|
-
file (str): The local path or URL of the file.
|
|
30
|
-
channel_id (List[int], optional): The selected channel_id of audio file. # noqa: E501
|
|
31
|
-
|
|
32
|
-
Returns:
|
|
33
|
-
DashScopeAPIResponse: The response body.
|
|
34
|
-
|
|
35
|
-
Raises:
|
|
36
|
-
InputRequired: The file cannot be empty.
|
|
37
|
-
"""
|
|
38
|
-
loop = asyncio.new_event_loop()
|
|
39
|
-
asyncio.set_event_loop(loop)
|
|
40
|
-
return loop.run_until_complete(cls.async_call(model, file, **kwargs))
|
|
41
|
-
|
|
42
|
-
@classmethod
|
|
43
|
-
async def async_call(cls, model: str, file: str,
|
|
44
|
-
**kwargs) -> DashScopeAPIResponse:
|
|
45
|
-
"""Async call file transcriber model service.
|
|
46
|
-
|
|
47
|
-
Args:
|
|
48
|
-
model (str): The requested model, such as paraformer-16k-1
|
|
49
|
-
file (str): The local path or URL of the file.
|
|
50
|
-
channel_id (List[int], optional): The selected channel_id of audio file. # noqa: E501
|
|
51
|
-
|
|
52
|
-
Returns:
|
|
53
|
-
DashScopeAPIResponse: The response body.
|
|
54
|
-
|
|
55
|
-
Raises:
|
|
56
|
-
InputRequired: The file cannot be empty.
|
|
57
|
-
"""
|
|
58
|
-
cls.is_url = cls._validate_file(file)
|
|
59
|
-
cls.file_name = file
|
|
60
|
-
cls.model_id = model
|
|
61
|
-
|
|
62
|
-
request = {'file': cls.file_name, 'is_url': cls.is_url}
|
|
63
|
-
|
|
64
|
-
# launch transcribe request, and get task info.
|
|
65
|
-
task = await cls._async_launch_requests(request, **kwargs)
|
|
66
|
-
|
|
67
|
-
response = await cls._async_get_result(task, **kwargs)
|
|
68
|
-
|
|
69
|
-
return response
|
|
70
|
-
|
|
71
|
-
@classmethod
|
|
72
|
-
async def _async_launch_requests(cls, request: Dict[str, Any], **kwargs):
|
|
73
|
-
"""Async submit transcribe request.
|
|
74
|
-
|
|
75
|
-
Args:
|
|
76
|
-
inputs (Dict[str, Any]): The input parameters.
|
|
77
|
-
|
|
78
|
-
Returns:
|
|
79
|
-
task (Dict[str, Any]): The result of the task request.
|
|
80
|
-
"""
|
|
81
|
-
inputs = {'file_link': request['file']}
|
|
82
|
-
task = {'file': request['file']}
|
|
83
|
-
local_file = None
|
|
84
|
-
try_count: int = 0
|
|
85
|
-
response = DashScopeAPIResponse(id='', code=HTTPStatus.OK, output=None)
|
|
86
|
-
if not request['is_url']:
|
|
87
|
-
try:
|
|
88
|
-
local_file = open(inputs['file_link'], 'rb')
|
|
89
|
-
except IOError as e:
|
|
90
|
-
raise InputRequired(f'File cannot be opened. {e}')
|
|
91
|
-
|
|
92
|
-
kwargs['form'] = {'av_file': local_file}
|
|
93
|
-
|
|
94
|
-
task_name, function = _get_task_group_and_task(__name__)
|
|
95
|
-
kwargs['async_request'] = True
|
|
96
|
-
kwargs['query'] = False
|
|
97
|
-
|
|
98
|
-
while True:
|
|
99
|
-
try:
|
|
100
|
-
response = await super().async_call(
|
|
101
|
-
model=cls.model_id,
|
|
102
|
-
task_group='audio',
|
|
103
|
-
task=task_name,
|
|
104
|
-
function=function,
|
|
105
|
-
input=inputs,
|
|
106
|
-
api_protocol=ApiProtocol.HTTP,
|
|
107
|
-
http_method=HTTPMethod.POST,
|
|
108
|
-
**kwargs)
|
|
109
|
-
|
|
110
|
-
task['request_id'] = response.id
|
|
111
|
-
task['code'] = response.code
|
|
112
|
-
task['status'] = response.status
|
|
113
|
-
|
|
114
|
-
if response.code == HTTPStatus.OK and response.output is not None: # noqa: E501
|
|
115
|
-
task.update(response.output)
|
|
116
|
-
else:
|
|
117
|
-
task['message'] = response.message
|
|
118
|
-
|
|
119
|
-
break
|
|
120
|
-
|
|
121
|
-
except (asyncio.TimeoutError, aiohttp.ClientConnectorError) as e:
|
|
122
|
-
try_count += 1
|
|
123
|
-
if try_count > Transcribe.MAX_QUERY_TRY_COUNT:
|
|
124
|
-
task['request_id'] = response.id
|
|
125
|
-
task['code'] = HTTPStatus.REQUEST_TIMEOUT
|
|
126
|
-
task['status'] = response.status
|
|
127
|
-
task['message'] = str(e)
|
|
128
|
-
break
|
|
129
|
-
else:
|
|
130
|
-
await asyncio.sleep(2)
|
|
131
|
-
continue
|
|
132
|
-
except Exception as e:
|
|
133
|
-
task['request_id'] = response.id
|
|
134
|
-
task['code'] = HTTPStatus.BAD_REQUEST
|
|
135
|
-
task['status'] = response.status
|
|
136
|
-
task['message'] = str(e)
|
|
137
|
-
break
|
|
138
|
-
|
|
139
|
-
if local_file is not None:
|
|
140
|
-
local_file.close()
|
|
141
|
-
|
|
142
|
-
return task
|
|
143
|
-
|
|
144
|
-
@classmethod
|
|
145
|
-
async def _async_get_result(cls, task, **kwargs):
|
|
146
|
-
"""Async get transcribe result by polling.
|
|
147
|
-
|
|
148
|
-
Args:
|
|
149
|
-
task (Dict[str, Any]): The info of the task request.
|
|
150
|
-
|
|
151
|
-
Returns:
|
|
152
|
-
DashScopeAPIResponse: The response body.
|
|
153
|
-
"""
|
|
154
|
-
request = task
|
|
155
|
-
responses = []
|
|
156
|
-
item = {}
|
|
157
|
-
response = DashScopeAPIResponse(id=request['request_id'],
|
|
158
|
-
code=request['code'],
|
|
159
|
-
output=None,
|
|
160
|
-
status=request['status'],
|
|
161
|
-
message=request['message'])
|
|
162
|
-
|
|
163
|
-
if request['code'] != HTTPStatus.OK:
|
|
164
|
-
item['file'] = request['file']
|
|
165
|
-
item['request_id'] = response.id
|
|
166
|
-
item['code'] = request['code']
|
|
167
|
-
item['status'] = request['status']
|
|
168
|
-
item['message'] = request['message']
|
|
169
|
-
responses.append(item)
|
|
170
|
-
else:
|
|
171
|
-
try_count: int = 0
|
|
172
|
-
while True:
|
|
173
|
-
item['file'] = request['file']
|
|
174
|
-
item['task_Id'] = request['task_id']
|
|
175
|
-
|
|
176
|
-
try:
|
|
177
|
-
inputs = {}
|
|
178
|
-
inputs['task_Id'] = request['task_id']
|
|
179
|
-
kwargs['async_request'] = True
|
|
180
|
-
kwargs['query'] = True
|
|
181
|
-
|
|
182
|
-
response = await super().async_call(
|
|
183
|
-
model=cls.model_id,
|
|
184
|
-
task_group=None,
|
|
185
|
-
task='tasks',
|
|
186
|
-
input=inputs,
|
|
187
|
-
task_id=inputs['task_Id'],
|
|
188
|
-
api_protocol=ApiProtocol.HTTP,
|
|
189
|
-
http_method=HTTPMethod.GET,
|
|
190
|
-
**kwargs)
|
|
191
|
-
except (asyncio.TimeoutError,
|
|
192
|
-
aiohttp.ClientConnectorError) as e:
|
|
193
|
-
try_count += 1
|
|
194
|
-
if try_count > Transcribe.MAX_QUERY_TRY_COUNT:
|
|
195
|
-
item['request_id'] = response.id
|
|
196
|
-
item['code'] = HTTPStatus.REQUEST_TIMEOUT
|
|
197
|
-
item['status'] = response.status
|
|
198
|
-
item['message'] = str(e)
|
|
199
|
-
responses.append(item)
|
|
200
|
-
break
|
|
201
|
-
else:
|
|
202
|
-
await asyncio.sleep(2)
|
|
203
|
-
continue
|
|
204
|
-
except Exception as e:
|
|
205
|
-
item['request_id'] = response.id
|
|
206
|
-
item['code'] = HTTPStatus.BAD_REQUEST
|
|
207
|
-
item['status'] = response.status
|
|
208
|
-
item['message'] = str(e)
|
|
209
|
-
responses.append(item)
|
|
210
|
-
break
|
|
211
|
-
|
|
212
|
-
try_count = 0
|
|
213
|
-
item['request_id'] = response.id
|
|
214
|
-
item['code'] = response.code
|
|
215
|
-
item['status'] = response.status
|
|
216
|
-
|
|
217
|
-
if response.code == HTTPStatus.OK:
|
|
218
|
-
if 'task_status' in response.output:
|
|
219
|
-
task_status = response.output['task_status']
|
|
220
|
-
if task_status == 'QUEUING' or task_status == 'PROCESSING': # noqa: E501
|
|
221
|
-
await asyncio.sleep(2)
|
|
222
|
-
continue
|
|
223
|
-
|
|
224
|
-
item.update(response.output)
|
|
225
|
-
else:
|
|
226
|
-
item['message'] = response.message
|
|
227
|
-
|
|
228
|
-
responses.append(item)
|
|
229
|
-
break
|
|
230
|
-
|
|
231
|
-
output = {}
|
|
232
|
-
output['results'] = responses
|
|
233
|
-
|
|
234
|
-
return DashScopeAPIResponse(id=response.id,
|
|
235
|
-
code=response.code,
|
|
236
|
-
status=response.status,
|
|
237
|
-
message=response.message,
|
|
238
|
-
output=output)
|
|
239
|
-
|
|
240
|
-
@classmethod
|
|
241
|
-
def _validate_file(cls, file: str):
|
|
242
|
-
"""Check the validity of the file
|
|
243
|
-
and whether the file is a URL or a local path.
|
|
244
|
-
|
|
245
|
-
Args:
|
|
246
|
-
file (str): The local path or URL of the file.
|
|
247
|
-
|
|
248
|
-
Returns:
|
|
249
|
-
bool: Whether the file is a URL.
|
|
250
|
-
"""
|
|
251
|
-
if file is None or len(file) == 0:
|
|
252
|
-
raise InputRequired(
|
|
253
|
-
'Input an illegal file, please ensure that the file type is a local path or URL!' # noqa: *
|
|
254
|
-
)
|
|
255
|
-
|
|
256
|
-
if os.path.isfile(file):
|
|
257
|
-
return False
|
|
258
|
-
else:
|
|
259
|
-
result = urlparse(file)
|
|
260
|
-
if result.scheme is not None and len(result.scheme) > 0:
|
|
261
|
-
if result.scheme != 'http' and result.scheme != 'https':
|
|
262
|
-
raise InputRequired(
|
|
263
|
-
f'The URL protocol({result.scheme}) of file({file}) is not http or https.' # noqa: *
|
|
264
|
-
)
|
|
265
|
-
else:
|
|
266
|
-
raise InputRequired(
|
|
267
|
-
f'Input an illegal file({file}), maybe the file is inexistent.' # noqa: *
|
|
268
|
-
)
|
|
269
|
-
|
|
270
|
-
return True
|
dashscope/deployment.py
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
from dashscope.api_entities.dashscope_response import DashScopeAPIResponse
|
|
2
|
-
from dashscope.client.base_api import (CreateMixin, DeleteMixin, GetMixin,
|
|
3
|
-
ListMixin, PutMixin, StreamEventMixin)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class Deployment(CreateMixin, DeleteMixin, ListMixin, GetMixin,
|
|
7
|
-
StreamEventMixin, PutMixin):
|
|
8
|
-
SUB_PATH = 'deployments'
|
|
9
|
-
"""Deploy a model.
|
|
10
|
-
"""
|
|
11
|
-
@classmethod
|
|
12
|
-
def call(cls,
|
|
13
|
-
model: str,
|
|
14
|
-
capacity: int,
|
|
15
|
-
version: str = None,
|
|
16
|
-
suffix: str = None,
|
|
17
|
-
api_key: str = None,
|
|
18
|
-
workspace: str = None,
|
|
19
|
-
**kwargs) -> DashScopeAPIResponse:
|
|
20
|
-
"""Call to deployment a model service.
|
|
21
|
-
|
|
22
|
-
Args:
|
|
23
|
-
model (str): The model name.
|
|
24
|
-
version (str, optional): The model version, unnecessary
|
|
25
|
-
for fine-tuned model. Defaults to None.
|
|
26
|
-
suffix (str, optional): The name suffix of the model deployment,
|
|
27
|
-
If specified, the final model name will be model_suffix.
|
|
28
|
-
Defaults to None.
|
|
29
|
-
capacity (int, optional): The model service capacity.
|
|
30
|
-
api_key (str, optional): The api-key. Defaults to None.
|
|
31
|
-
workspace (str): The dashscope workspace id.
|
|
32
|
-
|
|
33
|
-
Returns:
|
|
34
|
-
DashScopeAPIResponse: _description_
|
|
35
|
-
"""
|
|
36
|
-
req = {'model_name': model, 'capacity': capacity}
|
|
37
|
-
|
|
38
|
-
if version is not None:
|
|
39
|
-
req['model_version'] = version
|
|
40
|
-
if suffix is not None:
|
|
41
|
-
req['suffix'] = suffix
|
|
42
|
-
return super().call(req,
|
|
43
|
-
api_key=api_key,
|
|
44
|
-
workspace=workspace,
|
|
45
|
-
**kwargs)
|
|
46
|
-
|
|
47
|
-
@classmethod
|
|
48
|
-
def list(cls,
|
|
49
|
-
page_no=1,
|
|
50
|
-
page_size=10,
|
|
51
|
-
api_key: str = None,
|
|
52
|
-
workspace: str = None,
|
|
53
|
-
**kwargs) -> DashScopeAPIResponse:
|
|
54
|
-
"""List deployments.
|
|
55
|
-
|
|
56
|
-
Args:
|
|
57
|
-
api_key (str, optional): The api api_key, if not present,
|
|
58
|
-
will get by default rule(TODO: api key doc). Defaults to None.
|
|
59
|
-
page_no (int, optional): Page number. Defaults to 1.
|
|
60
|
-
page_size (int, optional): Items per page. Defaults to 10.
|
|
61
|
-
workspace (str): The dashscope workspace id.
|
|
62
|
-
|
|
63
|
-
Returns:
|
|
64
|
-
DashScopeAPIResponse: The deployment list.
|
|
65
|
-
"""
|
|
66
|
-
return super().list(page_no,
|
|
67
|
-
page_size,
|
|
68
|
-
api_key,
|
|
69
|
-
workspace=workspace,
|
|
70
|
-
**kwargs)
|
|
71
|
-
|
|
72
|
-
@classmethod
|
|
73
|
-
def get(cls,
|
|
74
|
-
deployed_model: str,
|
|
75
|
-
api_key: str = None,
|
|
76
|
-
workspace: str = None,
|
|
77
|
-
**kwargs) -> DashScopeAPIResponse:
|
|
78
|
-
"""Get model deployment information.
|
|
79
|
-
|
|
80
|
-
Args:
|
|
81
|
-
deployed_model (str): The deployment_id.
|
|
82
|
-
api_key (str, optional): The api key. Defaults to None.
|
|
83
|
-
workspace (str): The dashscope workspace id.
|
|
84
|
-
|
|
85
|
-
Returns:
|
|
86
|
-
DashScopeAPIResponse: The deployment information.
|
|
87
|
-
"""
|
|
88
|
-
return super().get(deployed_model,
|
|
89
|
-
api_key,
|
|
90
|
-
workspace=workspace,
|
|
91
|
-
**kwargs)
|
|
92
|
-
|
|
93
|
-
@classmethod
|
|
94
|
-
def delete(cls,
|
|
95
|
-
deployment_id: str,
|
|
96
|
-
api_key: str = None,
|
|
97
|
-
workspace: str = None,
|
|
98
|
-
**kwargs) -> DashScopeAPIResponse:
|
|
99
|
-
"""Delete model deployment.
|
|
100
|
-
|
|
101
|
-
Args:
|
|
102
|
-
deployment_id (str): The deployment id.
|
|
103
|
-
api_key (str, optional): The api key. Defaults to None.
|
|
104
|
-
workspace (str): The dashscope workspace id.
|
|
105
|
-
|
|
106
|
-
Returns:
|
|
107
|
-
DashScopeAPIResponse: The delete result.
|
|
108
|
-
"""
|
|
109
|
-
return super().delete(deployment_id,
|
|
110
|
-
api_key,
|
|
111
|
-
workspace=workspace,
|
|
112
|
-
**kwargs)
|
|
113
|
-
|
|
114
|
-
@classmethod
|
|
115
|
-
def update(cls,
|
|
116
|
-
deployment_id: str,
|
|
117
|
-
version: str,
|
|
118
|
-
api_key: str = None,
|
|
119
|
-
workspace: str = None,
|
|
120
|
-
**kwargs) -> DashScopeAPIResponse:
|
|
121
|
-
"""Update model deployment.
|
|
122
|
-
|
|
123
|
-
Args:
|
|
124
|
-
deployment_id (str): The deployment id.
|
|
125
|
-
version (str): The target model version.
|
|
126
|
-
api_key (str, optional): The api key. Defaults to None.
|
|
127
|
-
workspace (str): The dashscope workspace id.
|
|
128
|
-
|
|
129
|
-
Returns:
|
|
130
|
-
DashScopeAPIResponse: The delete result.
|
|
131
|
-
"""
|
|
132
|
-
req = {'deployment_model': deployment_id, 'model_version': version}
|
|
133
|
-
return super().put(deployment_id,
|
|
134
|
-
req,
|
|
135
|
-
api_key,
|
|
136
|
-
workspace=workspace,
|
|
137
|
-
**kwargs)
|
|
138
|
-
|
|
139
|
-
@classmethod
|
|
140
|
-
def scale(cls,
|
|
141
|
-
deployment_id: str,
|
|
142
|
-
capacity: int,
|
|
143
|
-
api_key: str = None,
|
|
144
|
-
workspace: str = None,
|
|
145
|
-
**kwargs) -> DashScopeAPIResponse:
|
|
146
|
-
"""Scaling model deployment.
|
|
147
|
-
|
|
148
|
-
Args:
|
|
149
|
-
deployment_id (str): The deployment id.
|
|
150
|
-
capacity (int): The target service capacity.
|
|
151
|
-
api_key (str, optional): The api key. Defaults to None.
|
|
152
|
-
|
|
153
|
-
Returns:
|
|
154
|
-
DashScopeAPIResponse: The delete result.
|
|
155
|
-
"""
|
|
156
|
-
req = {'deployed_model': deployment_id, 'capacity': capacity}
|
|
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)
|
dashscope/file.py
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
|
|
3
|
-
from dashscope.api_entities.dashscope_response import DashScopeAPIResponse
|
|
4
|
-
from dashscope.client.base_api import (DeleteMixin, FileUploadMixin, GetMixin,
|
|
5
|
-
ListMixin)
|
|
6
|
-
from dashscope.common.constants import FilePurpose
|
|
7
|
-
from dashscope.common.error import InvalidFileFormat
|
|
8
|
-
from dashscope.common.utils import is_validate_fine_tune_file
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class File(FileUploadMixin, ListMixin, DeleteMixin, GetMixin):
|
|
12
|
-
SUB_PATH = 'files'
|
|
13
|
-
|
|
14
|
-
@classmethod
|
|
15
|
-
def upload(cls,
|
|
16
|
-
file_path: str,
|
|
17
|
-
purpose: str = FilePurpose.fine_tune,
|
|
18
|
-
description: str = None,
|
|
19
|
-
api_key: str = None,
|
|
20
|
-
**kwargs) -> DashScopeAPIResponse:
|
|
21
|
-
"""Upload file for model fine-tune or other tasks.
|
|
22
|
-
|
|
23
|
-
Args:
|
|
24
|
-
file_path (str): The local file name to upload.
|
|
25
|
-
purpose (str): The purpose of the file[fine-tune|inference]
|
|
26
|
-
description (str, optional): The file description message.
|
|
27
|
-
api_key (str, optional): The api key. Defaults to None.
|
|
28
|
-
|
|
29
|
-
Returns:
|
|
30
|
-
DashScopeAPIResponse: The upload information
|
|
31
|
-
"""
|
|
32
|
-
if purpose == FilePurpose.fine_tune:
|
|
33
|
-
if not is_validate_fine_tune_file(file_path):
|
|
34
|
-
raise InvalidFileFormat(
|
|
35
|
-
'The file %s is not in valid jsonl format' % file_path)
|
|
36
|
-
with open(file_path, 'rb') as f:
|
|
37
|
-
return super().upload(files=[('files', (os.path.basename(f.name),
|
|
38
|
-
f, None))],
|
|
39
|
-
descriptions=[description]
|
|
40
|
-
if description is not None else None,
|
|
41
|
-
api_key=api_key,
|
|
42
|
-
**kwargs)
|
|
43
|
-
|
|
44
|
-
@classmethod
|
|
45
|
-
def list(cls,
|
|
46
|
-
page=1,
|
|
47
|
-
page_size=10,
|
|
48
|
-
api_key: str = None,
|
|
49
|
-
**kwargs) -> DashScopeAPIResponse:
|
|
50
|
-
"""List uploaded files.
|
|
51
|
-
|
|
52
|
-
Args:
|
|
53
|
-
api_key (str, optional):
|
|
54
|
-
The api api_key, can be None,
|
|
55
|
-
if None, will get by default rule(TODO: api key doc).
|
|
56
|
-
page (int, optional): Page number. Defaults to 1.
|
|
57
|
-
page_size (int, optional): Items per page. Defaults to 10.
|
|
58
|
-
|
|
59
|
-
Returns:
|
|
60
|
-
DashScopeAPIResponse: The fine-tune jobs in the result.
|
|
61
|
-
"""
|
|
62
|
-
return super().list(page, page_size, api_key, **kwargs)
|
|
63
|
-
|
|
64
|
-
@classmethod
|
|
65
|
-
def get(cls,
|
|
66
|
-
file_id: str,
|
|
67
|
-
api_key: str = None,
|
|
68
|
-
**kwargs) -> DashScopeAPIResponse:
|
|
69
|
-
"""Get the file info.
|
|
70
|
-
|
|
71
|
-
Args:
|
|
72
|
-
file_id (str): The file id.
|
|
73
|
-
api_key (str, optional): The api key. Defaults to None.
|
|
74
|
-
|
|
75
|
-
Returns:
|
|
76
|
-
DashScopeAPIResponse: The job info
|
|
77
|
-
"""
|
|
78
|
-
return super().get(file_id, api_key, **kwargs)
|
|
79
|
-
|
|
80
|
-
@classmethod
|
|
81
|
-
def delete(cls,
|
|
82
|
-
file_id: str,
|
|
83
|
-
api_key: str = None,
|
|
84
|
-
**kwargs) -> DashScopeAPIResponse:
|
|
85
|
-
"""Delete uploaded file.
|
|
86
|
-
|
|
87
|
-
Args:
|
|
88
|
-
file_id (str): The file id want to delete.
|
|
89
|
-
api_key (str, optional): The api key. Defaults to None.
|
|
90
|
-
|
|
91
|
-
Returns:
|
|
92
|
-
DashScopeAPIResponse: Delete result.
|
|
93
|
-
"""
|
|
94
|
-
return super().delete(file_id, api_key, **kwargs)
|
dashscope/finetune.py
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
from typing import Union
|
|
2
|
-
|
|
3
|
-
from dashscope.api_entities.dashscope_response import DashScopeAPIResponse
|
|
4
|
-
from dashscope.client.base_api import (CancelMixin, CreateMixin, DeleteMixin,
|
|
5
|
-
GetStatusMixin, ListMixin, LogMixin,
|
|
6
|
-
StreamEventMixin)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class FineTune(CreateMixin, CancelMixin, DeleteMixin, ListMixin,
|
|
10
|
-
GetStatusMixin, StreamEventMixin, LogMixin):
|
|
11
|
-
SUB_PATH = 'fine-tunes'
|
|
12
|
-
|
|
13
|
-
@classmethod
|
|
14
|
-
def call(cls,
|
|
15
|
-
model: str,
|
|
16
|
-
training_file_ids: Union[list, str],
|
|
17
|
-
validation_file_ids: Union[list, str] = None,
|
|
18
|
-
mode: str = None,
|
|
19
|
-
hyper_parameters: dict = {},
|
|
20
|
-
api_key: str = None,
|
|
21
|
-
workspace: str = None,
|
|
22
|
-
**kwargs) -> DashScopeAPIResponse:
|
|
23
|
-
"""Create fine-tune job
|
|
24
|
-
|
|
25
|
-
Args:
|
|
26
|
-
model (str): The model to be fine-tuned
|
|
27
|
-
training_file_ids (list, str): Ids of the fine-tune training data,
|
|
28
|
-
which can be pre-uploaded using the File API.
|
|
29
|
-
validation_file_ids ([list,str], optional): Ids of the fine-tune
|
|
30
|
-
validating data, which can be pre-uploaded using the File API.
|
|
31
|
-
mode (str): The fine-tune mode, sft or efficient_sft.
|
|
32
|
-
hyper_parameters (dict, optional): The fine-tune hyper parameters.
|
|
33
|
-
Defaults to empty.
|
|
34
|
-
api_key (str, optional): The api key. Defaults to None.
|
|
35
|
-
workspace (str): The dashscope workspace id.
|
|
36
|
-
|
|
37
|
-
Returns:
|
|
38
|
-
DashScopeAPIResponse: The request result.
|
|
39
|
-
"""
|
|
40
|
-
request = {
|
|
41
|
-
'model': model,
|
|
42
|
-
'training_file_ids': training_file_ids,
|
|
43
|
-
'validation_file_ids': validation_file_ids,
|
|
44
|
-
'hyper_parameters': hyper_parameters if hyper_parameters else {},
|
|
45
|
-
}
|
|
46
|
-
if mode is not None:
|
|
47
|
-
request['training_type'] = mode
|
|
48
|
-
if 'finetuned_output' in kwargs:
|
|
49
|
-
request['finetuned_output'] = kwargs['finetuned_output']
|
|
50
|
-
return super().call(request,
|
|
51
|
-
api_key=api_key,
|
|
52
|
-
workspace=workspace,
|
|
53
|
-
**kwargs)
|
|
54
|
-
|
|
55
|
-
@classmethod
|
|
56
|
-
def cancel(cls,
|
|
57
|
-
job_id: str,
|
|
58
|
-
api_key: str = None,
|
|
59
|
-
workspace: str = None,
|
|
60
|
-
**kwargs) -> DashScopeAPIResponse:
|
|
61
|
-
"""Cancel a running fine-tune job.
|
|
62
|
-
|
|
63
|
-
Args:
|
|
64
|
-
job_id (str): The fine-tune job id.
|
|
65
|
-
api_key (str, optional): The api api_key, can be None,
|
|
66
|
-
if None, will get by default rule(TODO: api key doc).
|
|
67
|
-
workspace (str): The dashscope workspace id.
|
|
68
|
-
|
|
69
|
-
Returns:
|
|
70
|
-
DashScopeAPIResponse: The request result.
|
|
71
|
-
"""
|
|
72
|
-
return super().cancel(job_id, api_key, workspace=workspace, **kwargs)
|
|
73
|
-
|
|
74
|
-
@classmethod
|
|
75
|
-
def list(cls,
|
|
76
|
-
page=1,
|
|
77
|
-
page_size=10,
|
|
78
|
-
api_key: str = None,
|
|
79
|
-
workspace: str = None,
|
|
80
|
-
**kwargs) -> DashScopeAPIResponse:
|
|
81
|
-
"""List fine-tune job.
|
|
82
|
-
|
|
83
|
-
Args:
|
|
84
|
-
api_key (str, optional): The api key
|
|
85
|
-
page (int, optional): Page number. Defaults to 1.
|
|
86
|
-
page_size (int, optional): Items per page. Defaults to 10.
|
|
87
|
-
workspace (str): The dashscope workspace id.
|
|
88
|
-
|
|
89
|
-
Returns:
|
|
90
|
-
DashScopeAPIResponse: The fine-tune jobs in the result.
|
|
91
|
-
"""
|
|
92
|
-
return super().list(page,
|
|
93
|
-
page_size,
|
|
94
|
-
api_key,
|
|
95
|
-
workspace=workspace,
|
|
96
|
-
**kwargs)
|
|
97
|
-
|
|
98
|
-
@classmethod
|
|
99
|
-
def get(cls,
|
|
100
|
-
job_id: str,
|
|
101
|
-
api_key: str = None,
|
|
102
|
-
workspace: str = None,
|
|
103
|
-
**kwargs) -> DashScopeAPIResponse:
|
|
104
|
-
"""Get fine-tune job information.
|
|
105
|
-
|
|
106
|
-
Args:
|
|
107
|
-
job_id (str): The fine-tune job id
|
|
108
|
-
api_key (str, optional): The api key. Defaults to None.
|
|
109
|
-
workspace (str): The dashscope workspace id.
|
|
110
|
-
|
|
111
|
-
Returns:
|
|
112
|
-
DashScopeAPIResponse: The job info
|
|
113
|
-
"""
|
|
114
|
-
return super().get(job_id, api_key, workspace=workspace, **kwargs)
|
|
115
|
-
|
|
116
|
-
@classmethod
|
|
117
|
-
def delete(cls,
|
|
118
|
-
job_id: str,
|
|
119
|
-
api_key: str = None,
|
|
120
|
-
workspace: str = None,
|
|
121
|
-
**kwargs) -> DashScopeAPIResponse:
|
|
122
|
-
"""Delete a fine-tune job.
|
|
123
|
-
|
|
124
|
-
Args:
|
|
125
|
-
job_id (str): The fine-tune job id.
|
|
126
|
-
api_key (str, optional): The api key. Defaults to None.
|
|
127
|
-
workspace (str): The dashscope workspace id.
|
|
128
|
-
|
|
129
|
-
Returns:
|
|
130
|
-
DashScopeAPIResponse: The delete result.
|
|
131
|
-
"""
|
|
132
|
-
return super().delete(job_id, api_key, workspace=workspace, **kwargs)
|
|
133
|
-
|
|
134
|
-
@classmethod
|
|
135
|
-
def stream_events(cls,
|
|
136
|
-
job_id: str,
|
|
137
|
-
api_key: str = None,
|
|
138
|
-
workspace: str = None,
|
|
139
|
-
**kwargs) -> DashScopeAPIResponse:
|
|
140
|
-
"""Get fine-tune job events.
|
|
141
|
-
|
|
142
|
-
Args:
|
|
143
|
-
job_id (str): The fine-tune job id
|
|
144
|
-
api_key (str, optional): the api key. Defaults to None.
|
|
145
|
-
workspace (str): The dashscope workspace id.
|
|
146
|
-
|
|
147
|
-
Returns:
|
|
148
|
-
DashScopeAPIResponse: The job log events.
|
|
149
|
-
"""
|
|
150
|
-
return super().stream_events(job_id,
|
|
151
|
-
api_key,
|
|
152
|
-
workspace=workspace,
|
|
153
|
-
**kwargs)
|
|
154
|
-
|
|
155
|
-
@classmethod
|
|
156
|
-
def logs(cls,
|
|
157
|
-
job_id: str,
|
|
158
|
-
offset=1,
|
|
159
|
-
line=1000,
|
|
160
|
-
api_key: str = None,
|
|
161
|
-
workspace: str = None,
|
|
162
|
-
**kwargs) -> DashScopeAPIResponse:
|
|
163
|
-
"""Get log of the job.
|
|
164
|
-
|
|
165
|
-
Args:
|
|
166
|
-
job_id (str): The job id(used for fine-tune)
|
|
167
|
-
offset (int, optional): start log line. Defaults to 1.
|
|
168
|
-
line (int, optional): total line return. Defaults to 1000.
|
|
169
|
-
api_key (str, optional): The api key. Defaults to None.
|
|
170
|
-
workspace (str): The dashscope workspace id.
|
|
171
|
-
|
|
172
|
-
Returns:
|
|
173
|
-
DashScopeAPIResponse: The response
|
|
174
|
-
"""
|
|
175
|
-
return super().logs(job_id, offset, line, workspace=workspace)
|