dashscope 1.20.2__py3-none-any.whl → 1.20.4__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.

@@ -345,7 +345,7 @@ class SpeechSynthesizer:
345
345
  self.__submit_text(text)
346
346
  return None
347
347
 
348
- def streaming_complete(self, complete_timeout_millis=10000):
348
+ def streaming_complete(self, complete_timeout_millis=600000):
349
349
  """
350
350
  Synchronously stop the streaming input speech synthesis task.
351
351
  Wait for all remaining synthesized audio before returning
@@ -376,14 +376,18 @@ class SpeechSynthesizer:
376
376
  self._is_started = False
377
377
 
378
378
  def __waiting_for_complete(self, timeout):
379
- if not self.complete_event.wait(timeout=timeout / 1000):
380
- raise TimeoutError(
381
- 'speech synthesizer wait for complete timeout 10000ms')
379
+ if timeout is not None and timeout > 0:
380
+ if not self.complete_event.wait(timeout=timeout / 1000):
381
+ raise TimeoutError(
382
+ f'speech synthesizer wait for complete timeout {timeout}ms'
383
+ )
384
+ else:
385
+ self.complete_event.wait()
382
386
  self.close()
383
387
  self._stopped.set()
384
388
  self._is_started = False
385
389
 
386
- def async_streaming_complete(self, complete_timeout_millis=10000):
390
+ def async_streaming_complete(self, complete_timeout_millis=600000):
387
391
  """
388
392
  Asynchronously stop the streaming input speech synthesis task, returns immediately.
389
393
  You need to listen and handle the STREAM_INPUT_TTS_EVENT_SYNTHESIS_COMPLETE event in the on_event callback.
@@ -445,6 +449,7 @@ class SpeechSynthesizer:
445
449
  self.callback.on_close()
446
450
  else:
447
451
  logger.error(f'TaskFailed: {message}')
452
+ raise Exception(f'TaskFailed: {message}')
448
453
  elif EventType.GENERATED == event:
449
454
  if self.callback:
450
455
  self.callback.on_event(message)
@@ -452,6 +457,7 @@ class SpeechSynthesizer:
452
457
  pass
453
458
  except json.JSONDecodeError:
454
459
  logger.error('Failed to parse message as JSON.')
460
+ raise Exception('Failed to parse message as JSON.')
455
461
  elif isinstance(message, (bytes, bytearray)):
456
462
  # 如果失败,认为是二进制消息
457
463
  logger.debug('<<<recv binary {}'.format(len(message)))
@@ -510,10 +516,10 @@ class SpeechSynthesizer:
510
516
  # WebSocket关闭的回调函数
511
517
  def on_close(self, ws, close_status_code, close_msg):
512
518
  pass
513
- # print("### websocket closed msg [{}]{} ###".format(close_status_code, close_msg))
514
519
 
515
520
  # WebSocket发生错误的回调函数
516
521
  def on_error(self, ws, error):
522
+ print(f'websocket closed due to {error}')
517
523
  raise Exception(f'websocket closed due to {error}')
518
524
 
519
525
  # 关闭WebSocket连接
@@ -11,10 +11,7 @@ import requests
11
11
 
12
12
  from dashscope.api_entities.dashscope_response import DashScopeAPIResponse
13
13
  from dashscope.client.base_api import GetMixin
14
- from dashscope.common.constants import (FILE_PATH_SCHEMA,
15
- REQUEST_CONTENT_AUDIO,
16
- REQUEST_CONTENT_IMAGE,
17
- REQUEST_CONTENT_TEXT)
14
+ from dashscope.common.constants import FILE_PATH_SCHEMA
18
15
  from dashscope.common.error import InvalidInput, UploadFileException
19
16
  from dashscope.common.logging import logger
20
17
  from dashscope.common.utils import get_user_agent
@@ -124,49 +121,41 @@ def upload_file(model: str, upload_path: str, api_key: str):
124
121
  return None
125
122
 
126
123
 
127
- def check_and_upload(model, elem: dict, key: str, api_key):
124
+ def check_and_upload(model, elem: dict, api_key):
128
125
  is_upload = False
129
- content = elem[key]
130
- if content.startswith(FILE_PATH_SCHEMA):
131
- parse_result = urlparse(content)
132
- if parse_result.netloc:
133
- file_path = parse_result.netloc + unquote_plus(parse_result.path)
134
- else:
135
- file_path = unquote_plus(parse_result.path)
136
- if os.path.exists(file_path):
137
- file_url = OssUtils.upload(model=model,
138
- file_path=file_path,
139
- api_key=api_key)
140
- if file_url is None:
141
- raise UploadFileException('Uploading file: %s failed' %
142
- content)
143
- elem[key] = file_url
144
- is_upload = True
145
- else:
146
- raise InvalidInput('The file: %s is not exists!' % file_path)
147
- elif not content.startswith('http'):
148
- if os.path.exists(content):
149
- file_url = OssUtils.upload(model=model,
150
- file_path=content,
151
- api_key=api_key)
152
- if file_url is None:
153
- raise UploadFileException('Uploading file: %s failed' %
154
- content)
155
- elem[key] = file_url
156
- is_upload = True
126
+ for key, content in elem.items():
127
+ if content.startswith(FILE_PATH_SCHEMA):
128
+ parse_result = urlparse(content)
129
+ if parse_result.netloc:
130
+ file_path = parse_result.netloc + unquote_plus(
131
+ parse_result.path)
132
+ else:
133
+ file_path = unquote_plus(parse_result.path)
134
+ if os.path.exists(file_path):
135
+ file_url = OssUtils.upload(model=model,
136
+ file_path=file_path,
137
+ api_key=api_key)
138
+ if file_url is None:
139
+ raise UploadFileException('Uploading file: %s failed' %
140
+ content)
141
+ elem[key] = file_url
142
+ is_upload = True
143
+ else:
144
+ raise InvalidInput('The file: %s is not exists!' % file_path)
145
+ elif not content.startswith('http'):
146
+ if os.path.exists(content):
147
+ file_url = OssUtils.upload(model=model,
148
+ file_path=content,
149
+ api_key=api_key)
150
+ if file_url is None:
151
+ raise UploadFileException('Uploading file: %s failed' %
152
+ content)
153
+ elem[key] = file_url
154
+ is_upload = True
157
155
 
158
156
  return is_upload
159
157
 
160
158
 
161
159
  def preprocess_message_element(model: str, elem: List[dict], api_key: str):
162
- is_upload = False
163
- if REQUEST_CONTENT_TEXT in elem:
164
- is_upload = check_and_upload(model, elem, REQUEST_CONTENT_TEXT,
165
- api_key)
166
- elif REQUEST_CONTENT_IMAGE in elem:
167
- is_upload = check_and_upload(model, elem, REQUEST_CONTENT_IMAGE,
168
- api_key)
169
- elif REQUEST_CONTENT_AUDIO in elem:
170
- is_upload = check_and_upload(model, elem, REQUEST_CONTENT_AUDIO,
171
- api_key)
160
+ is_upload = check_and_upload(model, elem, api_key)
172
161
  return is_upload
dashscope/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = '1.20.2'
1
+ __version__ = '1.20.4'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dashscope
3
- Version: 1.20.2
3
+ Version: 1.20.4
4
4
  Summary: dashscope client sdk library
5
5
  Home-page: https://dashscope.aliyun.com/
6
6
  Author: Alibaba Cloud
@@ -6,7 +6,7 @@ dashscope/files.py,sha256=QgJjwhtn9F548nCA8jD8OvE6aQEj-20hZqJgYXsUdQU,3930
6
6
  dashscope/finetune.py,sha256=_tflDUvu0KagSoCzLaf0hofpG_P8NU6PylL8CPjVhrA,6243
7
7
  dashscope/model.py,sha256=UPOn1qMYFhX-ovXi3BMxZEBk8qOK7WLJOYHMbPZwYBo,1440
8
8
  dashscope/models.py,sha256=1-bc-Ue68zurgu_y6RhfFr9uzeQMF5AZq-C32lJGMGU,1224
9
- dashscope/version.py,sha256=6KIFuOk_uHObRUtO_hf7gfIcH-9norzWjEkjzb1Dclg,23
9
+ dashscope/version.py,sha256=F9uXsS9G7U6denIIAr8vp6GOvDWEm4lYN6mAx36-rZE,23
10
10
  dashscope/aigc/__init__.py,sha256=s-MCA87KYiVumYtKtJi5IMN7xelSF6TqEU3s3_7RF-Y,327
11
11
  dashscope/aigc/code_generation.py,sha256=KAJVrGp6tiNFBBg64Ovs9RfcP5SrIhrbW3wdA89NKso,10885
12
12
  dashscope/aigc/conversation.py,sha256=xRoJlCR-IXHjSdkDrK74a9ut1FJg0FZhTNXZAJC18MA,14231
@@ -36,7 +36,7 @@ dashscope/audio/asr/transcription.py,sha256=1WAg9WH89antVzRYEKXb5LQP9xylZmX4YKp7
36
36
  dashscope/audio/tts/__init__.py,sha256=fbnieZX9yNFNh5BsxLpLXb63jlxzxrdCJakV3ignjlQ,194
37
37
  dashscope/audio/tts/speech_synthesizer.py,sha256=dnKx9FDDdO_ETHAjhK8zaMVaH6SfoTtN5YxXXqgY1JA,7571
38
38
  dashscope/audio/tts_v2/__init__.py,sha256=ve5a81qTbWDcRaSuritZtJBzryOIol2_dxzfqqdCw-k,345
39
- dashscope/audio/tts_v2/speech_synthesizer.py,sha256=RenOvxp6BOs_-E_K5akMEBFw9G0HXoLnvHw1IOTUgeU,18991
39
+ dashscope/audio/tts_v2/speech_synthesizer.py,sha256=bpzj9gx2D_FfOzgsjU-GBGmeWvEdewNPFd447mOgM-o,19220
40
40
  dashscope/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
41
41
  dashscope/client/base_api.py,sha256=rXN97XGyDhCCaD_dz_clpFDjOJfpGjqiH7yX3LaD-GE,41233
42
42
  dashscope/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -81,10 +81,10 @@ dashscope/tokenizers/tokenization.py,sha256=G6cSEmVLr3pjXUC3EOU9ot8MYxNnOQ4wOB2m
81
81
  dashscope/tokenizers/tokenizer.py,sha256=y6P91qTCYo__pEx_0VHAcj9YECfbUdRqZU1fdGTjF4o,1154
82
82
  dashscope/tokenizers/tokenizer_base.py,sha256=REDhzRyDT13iequ61-a6_KcTy0GFKlihQve5HkyoyRs,656
83
83
  dashscope/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
84
- dashscope/utils/oss_utils.py,sha256=fi8-PPsN-iR-iv5k2NS5Z8nlWkpgUhr56FRWm4BDh4A,6984
85
- dashscope-1.20.2.dist-info/LICENSE,sha256=Izp5L1DF1Mbza6qojkqNNWlE_mYLnr4rmzx2EBF8YFw,11413
86
- dashscope-1.20.2.dist-info/METADATA,sha256=I52DKGYRGq77FO4pFbQwUHN-2g4qLLNz-jMO0DMQ008,6641
87
- dashscope-1.20.2.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
88
- dashscope-1.20.2.dist-info/entry_points.txt,sha256=raEp5dOuj8whJ7yqZlDM8WQ5p2RfnGrGNo0QLQEnatY,50
89
- dashscope-1.20.2.dist-info/top_level.txt,sha256=woqavFJK9zas5xTqynmALqOtlafghjsk63Xk86powTU,10
90
- dashscope-1.20.2.dist-info/RECORD,,
84
+ dashscope/utils/oss_utils.py,sha256=Ha4VdeO5D4lHa-xE3-iUdZFOsHS5pe_Oz1Tg5P605bY,6487
85
+ dashscope-1.20.4.dist-info/LICENSE,sha256=Izp5L1DF1Mbza6qojkqNNWlE_mYLnr4rmzx2EBF8YFw,11413
86
+ dashscope-1.20.4.dist-info/METADATA,sha256=2r20We1APpu60VMdSe6UXLYXuHXywQZC-hkGyF-RYRc,6641
87
+ dashscope-1.20.4.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
88
+ dashscope-1.20.4.dist-info/entry_points.txt,sha256=raEp5dOuj8whJ7yqZlDM8WQ5p2RfnGrGNo0QLQEnatY,50
89
+ dashscope-1.20.4.dist-info/top_level.txt,sha256=woqavFJK9zas5xTqynmALqOtlafghjsk63Xk86powTU,10
90
+ dashscope-1.20.4.dist-info/RECORD,,