dashscope 1.21.0__py3-none-any.whl → 1.22.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/aigc/chat_completion.py +271 -0
- dashscope/api_entities/aiohttp_request.py +0 -1
- dashscope/api_entities/api_request_data.py +0 -1
- dashscope/api_entities/api_request_factory.py +3 -1
- dashscope/api_entities/chat_completion_types.py +349 -0
- dashscope/api_entities/dashscope_response.py +1 -1
- dashscope/api_entities/http_request.py +0 -1
- dashscope/api_entities/websocket_request.py +26 -3
- dashscope/audio/asr/__init__.py +10 -1
- dashscope/audio/asr/recognition.py +61 -22
- dashscope/audio/asr/translation_recognizer.py +1004 -0
- dashscope/audio/tts_v2/enrollment.py +1 -1
- dashscope/audio/tts_v2/speech_synthesizer.py +16 -1
- dashscope/client/base_api.py +4 -5
- dashscope/common/utils.py +0 -1
- dashscope/embeddings/batch_text_embedding_response.py +0 -1
- dashscope/utils/oss_utils.py +0 -1
- dashscope/utils/temporary_storage.py +160 -0
- dashscope/version.py +1 -1
- {dashscope-1.21.0.dist-info → dashscope-1.22.1.dist-info}/METADATA +2 -3
- {dashscope-1.21.0.dist-info → dashscope-1.22.1.dist-info}/RECORD +25 -25
- {dashscope-1.21.0.dist-info → dashscope-1.22.1.dist-info}/entry_points.txt +0 -1
- dashscope/audio/asr/transcribe.py +0 -270
- dashscope/deployment.py +0 -163
- dashscope/file.py +0 -94
- dashscope/finetune.py +0 -175
- {dashscope-1.21.0.dist-info → dashscope-1.22.1.dist-info}/LICENSE +0 -0
- {dashscope-1.21.0.dist-info → dashscope-1.22.1.dist-info}/WHEEL +0 -0
- {dashscope-1.21.0.dist-info → dashscope-1.22.1.dist-info}/top_level.txt +0 -0
|
@@ -67,7 +67,7 @@ class VoiceEnrollmentService(BaseApi):
|
|
|
67
67
|
def create_voice(self, target_model: str, prefix: str, url: str) -> str:
|
|
68
68
|
'''
|
|
69
69
|
创建新克隆音色
|
|
70
|
-
param: target_model
|
|
70
|
+
param: target_model 克隆音色对应的语音合成模型版本
|
|
71
71
|
param: prefix 音色自定义前缀,仅允许数字和小写字母,小于十个字符。
|
|
72
72
|
param: url 用于克隆的音频文件url
|
|
73
73
|
return: voice_id
|
|
@@ -275,6 +275,7 @@ class SpeechSynthesizer:
|
|
|
275
275
|
self._start_stream_timestamp = -1
|
|
276
276
|
self._first_package_timestamp = -1
|
|
277
277
|
self._recv_audio_length = 0
|
|
278
|
+
self.last_response = None
|
|
278
279
|
|
|
279
280
|
def __send_str(self, data: str):
|
|
280
281
|
logger.debug('>>>send {}'.format(data))
|
|
@@ -313,6 +314,11 @@ class SpeechSynthesizer:
|
|
|
313
314
|
while (not (self.ws.sock and self.ws.sock.connected)
|
|
314
315
|
and (time.time() - start_time) < timeout):
|
|
315
316
|
time.sleep(0.1) # 短暂休眠,避免密集轮询
|
|
317
|
+
if not (self.ws.sock and self.ws.sock.connected):
|
|
318
|
+
raise TimeoutError(
|
|
319
|
+
'websocket connection could not established within 5s. '
|
|
320
|
+
'Please check your network connection, firewall settings, or server status.'
|
|
321
|
+
)
|
|
316
322
|
self.__send_str(request)
|
|
317
323
|
if not self.start_event.wait(10):
|
|
318
324
|
raise TimeoutError('start speech synthesizer failed within 5s.')
|
|
@@ -434,6 +440,7 @@ class SpeechSynthesizer:
|
|
|
434
440
|
try:
|
|
435
441
|
# 尝试将消息解析为JSON
|
|
436
442
|
json_data = json.loads(message)
|
|
443
|
+
self.last_response = json_data
|
|
437
444
|
event = json_data['header'][EVENT_KEY]
|
|
438
445
|
# 调用JSON回调
|
|
439
446
|
if EventType.STARTED == event:
|
|
@@ -471,7 +478,7 @@ class SpeechSynthesizer:
|
|
|
471
478
|
self._recv_audio_length += len(message) / (2 * self.sample_rate /
|
|
472
479
|
1000)
|
|
473
480
|
current = time.time() * 1000
|
|
474
|
-
current_rtf = (current - self.
|
|
481
|
+
current_rtf = (current - self._start_stream_timestamp
|
|
475
482
|
) / self._recv_audio_length
|
|
476
483
|
logger.debug('total audio {} ms, current_rtf: {}'.format(
|
|
477
484
|
self._recv_audio_length, current_rtf))
|
|
@@ -531,3 +538,11 @@ class SpeechSynthesizer:
|
|
|
531
538
|
# 获取上一个任务的taskId
|
|
532
539
|
def get_last_request_id(self):
|
|
533
540
|
return self.last_request_id
|
|
541
|
+
|
|
542
|
+
def get_first_package_delay(self):
|
|
543
|
+
"""First Package Delay is the time between start sending text and receive first audio package
|
|
544
|
+
"""
|
|
545
|
+
return self._first_package_timestamp - self._start_stream_timestamp
|
|
546
|
+
|
|
547
|
+
def get_response(self):
|
|
548
|
+
return self.last_response
|
dashscope/client/base_api.py
CHANGED
|
@@ -2,9 +2,8 @@ import time
|
|
|
2
2
|
from http import HTTPStatus
|
|
3
3
|
from typing import Any, Dict, Iterator, List, Union
|
|
4
4
|
|
|
5
|
-
import requests
|
|
6
|
-
|
|
7
5
|
import dashscope
|
|
6
|
+
import requests
|
|
8
7
|
from dashscope.api_entities.api_request_factory import _build_api_request
|
|
9
8
|
from dashscope.api_entities.dashscope_response import DashScopeAPIResponse
|
|
10
9
|
from dashscope.common.api_key import get_default_api_key
|
|
@@ -173,9 +172,9 @@ class AsyncTaskGetMixin():
|
|
|
173
172
|
status_url = _normalization_url(base_url, 'tasks', task_id)
|
|
174
173
|
custom_headers = kwargs.pop('headers', None)
|
|
175
174
|
headers = {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
175
|
+
**_workspace_header(workspace),
|
|
176
|
+
**default_headers(api_key),
|
|
177
|
+
}
|
|
179
178
|
if custom_headers:
|
|
180
179
|
headers = {
|
|
181
180
|
**custom_headers,
|
dashscope/common/utils.py
CHANGED
|
@@ -11,7 +11,6 @@ from urllib.parse import urlparse
|
|
|
11
11
|
|
|
12
12
|
import aiohttp
|
|
13
13
|
import requests
|
|
14
|
-
|
|
15
14
|
from dashscope.api_entities.dashscope_response import DashScopeAPIResponse
|
|
16
15
|
from dashscope.common.api_key import get_default_api_key
|
|
17
16
|
from dashscope.common.constants import SSE_CONTENT_TYPE
|
dashscope/utils/oss_utils.py
CHANGED
|
@@ -8,7 +8,6 @@ from urllib.parse import unquote_plus, urlparse
|
|
|
8
8
|
from wsgiref.handlers import format_date_time
|
|
9
9
|
|
|
10
10
|
import requests
|
|
11
|
-
|
|
12
11
|
from dashscope.api_entities.dashscope_response import DashScopeAPIResponse
|
|
13
12
|
from dashscope.client.base_api import GetMixin
|
|
14
13
|
from dashscope.common.constants import FILE_PATH_SCHEMA
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
import mimetypes
|
|
3
|
+
import os
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
from http import HTTPStatus
|
|
6
|
+
from time import mktime
|
|
7
|
+
from typing import List
|
|
8
|
+
from urllib.parse import unquote_plus, urlparse
|
|
9
|
+
from wsgiref.handlers import format_date_time
|
|
10
|
+
import time
|
|
11
|
+
import threading
|
|
12
|
+
|
|
13
|
+
import requests
|
|
14
|
+
|
|
15
|
+
from dashscope.api_entities.dashscope_response import DashScopeAPIResponse
|
|
16
|
+
from dashscope.client.base_api import GetMixin
|
|
17
|
+
from dashscope.common.constants import (FILE_PATH_SCHEMA,
|
|
18
|
+
REQUEST_CONTENT_AUDIO,
|
|
19
|
+
REQUEST_CONTENT_IMAGE,
|
|
20
|
+
REQUEST_CONTENT_TEXT)
|
|
21
|
+
from dashscope.common.error import InvalidInput, UploadFileException
|
|
22
|
+
from dashscope.common.logging import logger
|
|
23
|
+
from dashscope.common.utils import get_user_agent
|
|
24
|
+
|
|
25
|
+
@dataclass
|
|
26
|
+
class UploadToken:
|
|
27
|
+
token: str = None
|
|
28
|
+
expire_time: int = None
|
|
29
|
+
|
|
30
|
+
class UploadTokenMeta(type):
|
|
31
|
+
def __init__(cls):
|
|
32
|
+
cls._tokens = {} # key model, value: token and expire_time
|
|
33
|
+
cls._lock = threading.Lock() # lock set
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def token(cls, model):
|
|
37
|
+
current_time = time.perf_counter()
|
|
38
|
+
upload_token: UploadToken = cls._tokens[model] if model in cls._tokens else None
|
|
39
|
+
if upload_token is not None and current_time < upload_token.expire_time:
|
|
40
|
+
return upload_token.token
|
|
41
|
+
else:
|
|
42
|
+
return None
|
|
43
|
+
|
|
44
|
+
@token.setter
|
|
45
|
+
def token(cls, model: str, upload_token: UploadToken):
|
|
46
|
+
cls._lock.acquire()
|
|
47
|
+
cls._tokens[model] = upload_token
|
|
48
|
+
cls._lock.release()
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class OssUtils(GetMixin, metaclass=UploadTokenMeta):
|
|
52
|
+
SUB_PATH = 'uploads'
|
|
53
|
+
|
|
54
|
+
@classmethod
|
|
55
|
+
def _decode_response_error(cls, response: requests.Response):
|
|
56
|
+
if 'application/json' in response.headers.get('content-type', ''):
|
|
57
|
+
message = response.json()
|
|
58
|
+
else:
|
|
59
|
+
message = response.content.decode('utf-8')
|
|
60
|
+
return message
|
|
61
|
+
|
|
62
|
+
@classmethod
|
|
63
|
+
def upload(cls,
|
|
64
|
+
model: str,
|
|
65
|
+
file_path: str,
|
|
66
|
+
api_key: str = None,
|
|
67
|
+
**kwargs) -> DashScopeAPIResponse:
|
|
68
|
+
"""Upload file for model fine-tune or other tasks.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
file_path (str): The local file name to upload.
|
|
72
|
+
purpose (str): The purpose of the file[fine-tune|inference]
|
|
73
|
+
description (str, optional): The file description message.
|
|
74
|
+
api_key (str, optional): The api key. Defaults to None.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
DashScopeAPIResponse: The upload information
|
|
78
|
+
"""
|
|
79
|
+
upload_token = cls.token(model)
|
|
80
|
+
if upload_token is None:
|
|
81
|
+
upload_info = cls.get_upload_certificate(model=model, api_key=api_key)
|
|
82
|
+
if upload_info.status_code != HTTPStatus.OK:
|
|
83
|
+
raise UploadFileException(
|
|
84
|
+
'Get upload certificate failed, code: %s, message: %s' %
|
|
85
|
+
(upload_info.code, upload_info.message))
|
|
86
|
+
upload_info = upload_info.output
|
|
87
|
+
cls.token = xx
|
|
88
|
+
|
|
89
|
+
upload_info = upload_info.output
|
|
90
|
+
headers = {}
|
|
91
|
+
headers = {'user-agent': get_user_agent()}
|
|
92
|
+
headers['Accept'] = 'application/json'
|
|
93
|
+
headers['Date'] = format_date_time(mktime(datetime.now().timetuple()))
|
|
94
|
+
form_data = {}
|
|
95
|
+
form_data['OSSAccessKeyId'] = upload_info['oss_access_key_id']
|
|
96
|
+
form_data['Signature'] = upload_info['signature']
|
|
97
|
+
form_data['policy'] = upload_info['policy']
|
|
98
|
+
form_data['key'] = upload_info['upload_dir'] + \
|
|
99
|
+
'/' + os.path.basename(file_path)
|
|
100
|
+
form_data['x-oss-object-acl'] = upload_info['x_oss_object_acl']
|
|
101
|
+
form_data['x-oss-forbid-overwrite'] = upload_info[
|
|
102
|
+
'x_oss_forbid_overwrite']
|
|
103
|
+
form_data['success_action_status'] = '200'
|
|
104
|
+
form_data['x-oss-content-type'] = mimetypes.guess_type(file_path)[0]
|
|
105
|
+
url = upload_info['upload_host']
|
|
106
|
+
files = {'file': open(file_path, 'rb')}
|
|
107
|
+
with requests.Session() as session:
|
|
108
|
+
response = session.post(url,
|
|
109
|
+
files=files,
|
|
110
|
+
data=form_data,
|
|
111
|
+
headers=headers,
|
|
112
|
+
timeout=3600)
|
|
113
|
+
if response.status_code == HTTPStatus.OK:
|
|
114
|
+
return 'oss://' + form_data['key']
|
|
115
|
+
else:
|
|
116
|
+
msg = (
|
|
117
|
+
'Uploading file: %s to oss failed, error: %s' %
|
|
118
|
+
(file_path, cls._decode_response_error(response=response)))
|
|
119
|
+
logger.error(msg)
|
|
120
|
+
raise UploadFileException(msg)
|
|
121
|
+
|
|
122
|
+
@classmethod
|
|
123
|
+
def get_upload_certificate(cls,
|
|
124
|
+
model: str,
|
|
125
|
+
api_key: str = None,
|
|
126
|
+
**kwargs) -> DashScopeAPIResponse:
|
|
127
|
+
"""Get a oss upload certificate.
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
api_key (str, optional): The api key. Defaults to None.
|
|
131
|
+
|
|
132
|
+
Returns:
|
|
133
|
+
DashScopeAPIResponse: The job info
|
|
134
|
+
"""
|
|
135
|
+
params = {'action': 'getPolicy'}
|
|
136
|
+
params['model'] = model
|
|
137
|
+
return super().get(None, api_key, params=params, **kwargs)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def upload_file(model: str, upload_path: str, api_key: str):
|
|
141
|
+
if upload_path.startswith(FILE_PATH_SCHEMA):
|
|
142
|
+
parse_result = urlparse(upload_path)
|
|
143
|
+
if parse_result.netloc:
|
|
144
|
+
file_path = parse_result.netloc + unquote_plus(parse_result.path)
|
|
145
|
+
else:
|
|
146
|
+
file_path = unquote_plus(parse_result.path)
|
|
147
|
+
if os.path.exists(file_path):
|
|
148
|
+
file_url = OssUtils.upload(model=model,
|
|
149
|
+
file_path=file_path,
|
|
150
|
+
api_key=api_key)
|
|
151
|
+
if file_url is None:
|
|
152
|
+
raise UploadFileException('Uploading file: %s failed' %
|
|
153
|
+
upload_path)
|
|
154
|
+
return file_url
|
|
155
|
+
else:
|
|
156
|
+
raise InvalidInput('The file: %s is not exists!' % file_path)
|
|
157
|
+
return None
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
dashscope/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = '1.
|
|
1
|
+
__version__ = '1.22.1'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: dashscope
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.22.1
|
|
4
4
|
Summary: dashscope client sdk library
|
|
5
5
|
Home-page: https://dashscope.aliyun.com/
|
|
6
6
|
Author: Alibaba Cloud
|
|
@@ -18,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.11
|
|
19
19
|
Requires-Python: >=3.8.0
|
|
20
20
|
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
21
22
|
Requires-Dist: aiohttp
|
|
22
23
|
Requires-Dist: requests
|
|
23
24
|
Requires-Dist: websocket-client
|
|
@@ -221,5 +222,3 @@ Coming soon.
|
|
|
221
222
|
|
|
222
223
|
## License
|
|
223
224
|
This project is licensed under the Apache License (Version 2.0).
|
|
224
|
-
|
|
225
|
-
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
dashscope/__init__.py,sha256=_9PaKXKpYc6PXO35BjcH3R0As9sTsXGOW2iQ6R5HAVc,3011
|
|
2
2
|
dashscope/cli.py,sha256=amegoTkGOs6TlHMdoo4JVOqBePo3lGs745rc7leEyrE,24020
|
|
3
|
-
dashscope/deployment.py,sha256=ljmVi-ny6SjEs8v4oIGNWIw8UQTorE7dl5QJv7dEPIQ,5728
|
|
4
|
-
dashscope/file.py,sha256=Dv2Fz3DLbcye2uuQxyQwRM7ky27OthouLXIpSQagQy4,3324
|
|
5
3
|
dashscope/files.py,sha256=QgJjwhtn9F548nCA8jD8OvE6aQEj-20hZqJgYXsUdQU,3930
|
|
6
|
-
dashscope/finetune.py,sha256=_tflDUvu0KagSoCzLaf0hofpG_P8NU6PylL8CPjVhrA,6243
|
|
7
4
|
dashscope/model.py,sha256=UPOn1qMYFhX-ovXi3BMxZEBk8qOK7WLJOYHMbPZwYBo,1440
|
|
8
5
|
dashscope/models.py,sha256=1-bc-Ue68zurgu_y6RhfFr9uzeQMF5AZq-C32lJGMGU,1224
|
|
9
|
-
dashscope/version.py,sha256=
|
|
6
|
+
dashscope/version.py,sha256=sUm-r83NIqFP93EJcBrI6UFP5e6fmMbnDa6TglGqS1o,23
|
|
10
7
|
dashscope/aigc/__init__.py,sha256=xmdalVw7wS0cLIuU8Q0qk0q8XGw-iGk8NnQwAQZ3jAc,391
|
|
8
|
+
dashscope/aigc/chat_completion.py,sha256=28puJrtHkqTMZlyKLXb3UjSuICy2OPvysj9a6oNU7Vs,14585
|
|
11
9
|
dashscope/aigc/code_generation.py,sha256=KAJVrGp6tiNFBBg64Ovs9RfcP5SrIhrbW3wdA89NKso,10885
|
|
12
10
|
dashscope/aigc/conversation.py,sha256=xRoJlCR-IXHjSdkDrK74a9ut1FJg0FZhTNXZAJC18MA,14231
|
|
13
11
|
dashscope/aigc/generation.py,sha256=53oMCmN5ZbqeqAsKxmdunXlRh-XP8ZtnA7hB2id4Koo,17897
|
|
@@ -15,13 +13,14 @@ dashscope/aigc/image_synthesis.py,sha256=UWHW-nvf7_aDZKr4uZDusVHjqWr9TSZjCsZI8YS
|
|
|
15
13
|
dashscope/aigc/multimodal_conversation.py,sha256=SlNnnsUPV19gdx8fYJAtsMFWPNGY6vhk5IGHZ5ZczpI,5369
|
|
16
14
|
dashscope/aigc/video_synthesis.py,sha256=gbp5XG_DMVN0JnBOgxftdwsCIyrV7nM2gVnlyO8X-ek,10400
|
|
17
15
|
dashscope/api_entities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
-
dashscope/api_entities/aiohttp_request.py,sha256=
|
|
19
|
-
dashscope/api_entities/api_request_data.py,sha256=
|
|
20
|
-
dashscope/api_entities/api_request_factory.py,sha256=
|
|
16
|
+
dashscope/api_entities/aiohttp_request.py,sha256=ZFbdpJh7SwHnBzbYLhqr_FdcDVRgLVMLhLUS_vXbUGs,10228
|
|
17
|
+
dashscope/api_entities/api_request_data.py,sha256=QHGgIShcQ1jANO1szfsqUGtYix1nD2RN4LyC_fNciCM,5462
|
|
18
|
+
dashscope/api_entities/api_request_factory.py,sha256=iLjOqZkbuQkn9JVduI39XPrhm1UefekAekaNqxFpNLM,5061
|
|
21
19
|
dashscope/api_entities/base_request.py,sha256=cXUL7xqSV8wBr5d-1kx65AO3IsRR9A_ps6Lok-v-MKM,926
|
|
22
|
-
dashscope/api_entities/
|
|
23
|
-
dashscope/api_entities/
|
|
24
|
-
dashscope/api_entities/
|
|
20
|
+
dashscope/api_entities/chat_completion_types.py,sha256=U1nYR5krZYbCedPwlRufJok3hz95mm4kYn2mp20hNAc,12807
|
|
21
|
+
dashscope/api_entities/dashscope_response.py,sha256=FC9zGLNb2iu5fl4bJNcjLnVren_4kNGRW0i9xs4b4Q8,19839
|
|
22
|
+
dashscope/api_entities/http_request.py,sha256=Pr6mr01uXELK9LwIPXrJAhNtGMkWH3gQYORXShRiQRo,13258
|
|
23
|
+
dashscope/api_entities/websocket_request.py,sha256=XzLj9vsJfBAhYMyRRcbEBoJu_dAVm0HpM60k46lBqBw,16281
|
|
25
24
|
dashscope/app/__init__.py,sha256=UiN_9i--z84Dw5wUehOh_Tkk_9Gq_td_Kbz1dobBEKg,62
|
|
26
25
|
dashscope/app/application.py,sha256=Cnd62LFpG70XJUo4Oibry9KzXPhPNmNkKFD4R5YuGTA,9343
|
|
27
26
|
dashscope/app/application_response.py,sha256=0pulI3O3z4R4h_YaDwzVimamo3XwTXGy5TiHCzysTBg,7011
|
|
@@ -30,19 +29,19 @@ dashscope/assistants/assistant_types.py,sha256=1jNL30TOlrkiYhvCaB3E8jkPLG8CnQ6I3
|
|
|
30
29
|
dashscope/assistants/assistants.py,sha256=NYahIDqhtnOcQOmnhZsjc5F5jvBUQcce8-fbrJXHVnQ,10833
|
|
31
30
|
dashscope/assistants/files.py,sha256=pwLVJ_pjpRFWyfI_MRvhH7Si7FzGDj4ChzZgWTpLOhg,6699
|
|
32
31
|
dashscope/audio/__init__.py,sha256=-ZRxrK-gV4QsUtlThIT-XwqB6vmyEsnhxIxdLmhCUuc,61
|
|
33
|
-
dashscope/audio/asr/__init__.py,sha256=
|
|
32
|
+
dashscope/audio/asr/__init__.py,sha256=VaWX5DRWcB81_5z2o7IPwz6Jrs9vFFJ5GEVarzVOvPY,1004
|
|
34
33
|
dashscope/audio/asr/asr_phrase_manager.py,sha256=EjtbI3zz9UQGS1qv6Yb4zzEMj4OJJVXmwkqZyIrzvEA,7642
|
|
35
|
-
dashscope/audio/asr/recognition.py,sha256=
|
|
36
|
-
dashscope/audio/asr/transcribe.py,sha256=HfZYpvpVfvGRAIIIzX65Af33E6vsIFGd_qqhQ8LaNcM,9651
|
|
34
|
+
dashscope/audio/asr/recognition.py,sha256=7ApnKJKVp1JS6e6KBZzM8y1yiMB2fEun07S6BOvqfrs,20699
|
|
37
35
|
dashscope/audio/asr/transcription.py,sha256=D8CW0XDqJuEJVmNFJ6qczTysSV3Sz_rzk2C6NIKTtVc,9042
|
|
36
|
+
dashscope/audio/asr/translation_recognizer.py,sha256=j1oKgggSA2HDdEJAOJ4jY78_bK0FGwpfIf_AxbrAzWM,39629
|
|
38
37
|
dashscope/audio/asr/vocabulary.py,sha256=2MHxeaL0ANWk-TILrHhArKSdj0d5M_YHw0cnjB-E4dY,6476
|
|
39
38
|
dashscope/audio/tts/__init__.py,sha256=fbnieZX9yNFNh5BsxLpLXb63jlxzxrdCJakV3ignjlQ,194
|
|
40
39
|
dashscope/audio/tts/speech_synthesizer.py,sha256=dnKx9FDDdO_ETHAjhK8zaMVaH6SfoTtN5YxXXqgY1JA,7571
|
|
41
40
|
dashscope/audio/tts_v2/__init__.py,sha256=5UfyDBYnuGgOy9KMxEIXA2U2ihcXutdZc1cqJudy-8M,282
|
|
42
|
-
dashscope/audio/tts_v2/enrollment.py,sha256=
|
|
43
|
-
dashscope/audio/tts_v2/speech_synthesizer.py,sha256=
|
|
41
|
+
dashscope/audio/tts_v2/enrollment.py,sha256=pFxiB_F9jmNnyikabA710QVCVih8Q7AQPLIO4aGKfc8,6140
|
|
42
|
+
dashscope/audio/tts_v2/speech_synthesizer.py,sha256=JPS9LRfWX4VD-BZHAJcBh3Vfwn7oVueAnN0zXhnIqhQ,19928
|
|
44
43
|
dashscope/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
45
|
-
dashscope/client/base_api.py,sha256=
|
|
44
|
+
dashscope/client/base_api.py,sha256=RH8ztQgx1WPRXZVfvt5rbhu45IXFdaw8HSbHN5k8AF8,41187
|
|
46
45
|
dashscope/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
47
46
|
dashscope/common/api_key.py,sha256=5Stp0odL5JSuIO3qJBp23QNppuGbqhhvKPS66qbMs0I,1986
|
|
48
47
|
dashscope/common/base_type.py,sha256=C9xP6WuN5pOzviZ2g3X2EPcigldtFE0VlaUmjyNnUUk,4619
|
|
@@ -51,14 +50,14 @@ dashscope/common/env.py,sha256=oQOZW5JyEeTSde394un2lpDJ5RBh4fMU9hBfbtrKKkc,869
|
|
|
51
50
|
dashscope/common/error.py,sha256=Q7GRhniP-7ap4HBpU69frRdKgKLwmH4ySYxCtupsr60,2638
|
|
52
51
|
dashscope/common/logging.py,sha256=ecGxylG3bWES_Xv5-BD6ep4_0Ciu7F6ZPBjiZtu9Jx4,984
|
|
53
52
|
dashscope/common/message_manager.py,sha256=i5149WzDk6nWmdFaHzYx4USXMBeX18GKSI-F4fLwbN0,1097
|
|
54
|
-
dashscope/common/utils.py,sha256=
|
|
53
|
+
dashscope/common/utils.py,sha256=Sw5UB_WH3lFnbwZO3RoA2V6DCHgthjaetW5mN9JM5BE,15387
|
|
55
54
|
dashscope/customize/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
56
55
|
dashscope/customize/customize_types.py,sha256=ZtEwSXA4dbjIYr5vgQQNkMuXyC2BNmznGuaF6b7jwr0,4803
|
|
57
56
|
dashscope/customize/deployments.py,sha256=LIkM-hmJHcJZCKV6WJIPSXQ5CAhB5PUxnt5mqKbVbfE,5189
|
|
58
57
|
dashscope/customize/finetunes.py,sha256=iFnEUMGY6FGogVClIJMEeFhUwfYi7gD05Iq1-eMP2M0,8311
|
|
59
58
|
dashscope/embeddings/__init__.py,sha256=-dxHaoxZZVuP-wAGUIa3sNNh8CQwaeWj2UlqsDy1sV4,240
|
|
60
59
|
dashscope/embeddings/batch_text_embedding.py,sha256=P32LFO9v7ehdJsl0c32In94hUET6K6AaGJ_pDRtFqco,8791
|
|
61
|
-
dashscope/embeddings/batch_text_embedding_response.py,sha256=
|
|
60
|
+
dashscope/embeddings/batch_text_embedding_response.py,sha256=hf17wfhJKvX3ggnigOiTqD4O1lFhx_NG_O1ioKCx0gk,1999
|
|
62
61
|
dashscope/embeddings/multimodal_embedding.py,sha256=yojtGNoT2N54g0jcAYUwNIiwzueun1ouqS0S0tvnyQc,3966
|
|
63
62
|
dashscope/embeddings/text_embedding.py,sha256=I3zRvuT2HWcaZYH-zrtGcAQmzuLQxFswIHJMiQXfaJQ,2009
|
|
64
63
|
dashscope/io/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -85,10 +84,11 @@ dashscope/tokenizers/tokenization.py,sha256=G6cSEmVLr3pjXUC3EOU9ot8MYxNnOQ4wOB2m
|
|
|
85
84
|
dashscope/tokenizers/tokenizer.py,sha256=y6P91qTCYo__pEx_0VHAcj9YECfbUdRqZU1fdGTjF4o,1154
|
|
86
85
|
dashscope/tokenizers/tokenizer_base.py,sha256=REDhzRyDT13iequ61-a6_KcTy0GFKlihQve5HkyoyRs,656
|
|
87
86
|
dashscope/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
88
|
-
dashscope/utils/oss_utils.py,sha256=
|
|
89
|
-
dashscope
|
|
90
|
-
dashscope-1.
|
|
91
|
-
dashscope-1.
|
|
92
|
-
dashscope-1.
|
|
93
|
-
dashscope-1.
|
|
94
|
-
dashscope-1.
|
|
87
|
+
dashscope/utils/oss_utils.py,sha256=TlqaMAmVRtBJIm5aIaXsrRZGKc_7cwWQ7liMB2f9Css,7331
|
|
88
|
+
dashscope/utils/temporary_storage.py,sha256=CWBpEmuIthYg5DhU_qu63DbF2dsmqnLdKFkbWF8yX6A,6072
|
|
89
|
+
dashscope-1.22.1.dist-info/LICENSE,sha256=Izp5L1DF1Mbza6qojkqNNWlE_mYLnr4rmzx2EBF8YFw,11413
|
|
90
|
+
dashscope-1.22.1.dist-info/METADATA,sha256=xk089kHugSTlkhuy17skH7fOIT60VivJMcsYUUKAI-4,6661
|
|
91
|
+
dashscope-1.22.1.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
|
92
|
+
dashscope-1.22.1.dist-info/entry_points.txt,sha256=e9C3sOf9zDYL0O5ROEGX6FT8w-QK_kaGRWmPZDHAFys,49
|
|
93
|
+
dashscope-1.22.1.dist-info/top_level.txt,sha256=woqavFJK9zas5xTqynmALqOtlafghjsk63Xk86powTU,10
|
|
94
|
+
dashscope-1.22.1.dist-info/RECORD,,
|
|
@@ -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
|