dashscope 1.8.0__py3-none-any.whl → 1.25.6__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.
Files changed (110) hide show
  1. dashscope/__init__.py +61 -14
  2. dashscope/aigc/__init__.py +10 -3
  3. dashscope/aigc/chat_completion.py +282 -0
  4. dashscope/aigc/code_generation.py +145 -0
  5. dashscope/aigc/conversation.py +71 -12
  6. dashscope/aigc/generation.py +288 -16
  7. dashscope/aigc/image_synthesis.py +473 -31
  8. dashscope/aigc/multimodal_conversation.py +299 -14
  9. dashscope/aigc/video_synthesis.py +610 -0
  10. dashscope/api_entities/aiohttp_request.py +8 -5
  11. dashscope/api_entities/api_request_data.py +4 -2
  12. dashscope/api_entities/api_request_factory.py +68 -20
  13. dashscope/api_entities/base_request.py +20 -3
  14. dashscope/api_entities/chat_completion_types.py +344 -0
  15. dashscope/api_entities/dashscope_response.py +243 -15
  16. dashscope/api_entities/encryption.py +179 -0
  17. dashscope/api_entities/http_request.py +216 -62
  18. dashscope/api_entities/websocket_request.py +43 -34
  19. dashscope/app/__init__.py +5 -0
  20. dashscope/app/application.py +203 -0
  21. dashscope/app/application_response.py +246 -0
  22. dashscope/assistants/__init__.py +16 -0
  23. dashscope/assistants/assistant_types.py +175 -0
  24. dashscope/assistants/assistants.py +311 -0
  25. dashscope/assistants/files.py +197 -0
  26. dashscope/audio/__init__.py +4 -2
  27. dashscope/audio/asr/__init__.py +17 -1
  28. dashscope/audio/asr/asr_phrase_manager.py +203 -0
  29. dashscope/audio/asr/recognition.py +167 -27
  30. dashscope/audio/asr/transcription.py +107 -14
  31. dashscope/audio/asr/translation_recognizer.py +1006 -0
  32. dashscope/audio/asr/vocabulary.py +177 -0
  33. dashscope/audio/qwen_asr/__init__.py +7 -0
  34. dashscope/audio/qwen_asr/qwen_transcription.py +189 -0
  35. dashscope/audio/qwen_omni/__init__.py +11 -0
  36. dashscope/audio/qwen_omni/omni_realtime.py +524 -0
  37. dashscope/audio/qwen_tts/__init__.py +5 -0
  38. dashscope/audio/qwen_tts/speech_synthesizer.py +77 -0
  39. dashscope/audio/qwen_tts_realtime/__init__.py +10 -0
  40. dashscope/audio/qwen_tts_realtime/qwen_tts_realtime.py +355 -0
  41. dashscope/audio/tts/__init__.py +2 -0
  42. dashscope/audio/tts/speech_synthesizer.py +5 -0
  43. dashscope/audio/tts_v2/__init__.py +12 -0
  44. dashscope/audio/tts_v2/enrollment.py +179 -0
  45. dashscope/audio/tts_v2/speech_synthesizer.py +886 -0
  46. dashscope/cli.py +157 -37
  47. dashscope/client/base_api.py +652 -87
  48. dashscope/common/api_key.py +2 -0
  49. dashscope/common/base_type.py +135 -0
  50. dashscope/common/constants.py +13 -16
  51. dashscope/common/env.py +2 -0
  52. dashscope/common/error.py +58 -22
  53. dashscope/common/logging.py +2 -0
  54. dashscope/common/message_manager.py +2 -0
  55. dashscope/common/utils.py +276 -46
  56. dashscope/customize/__init__.py +0 -0
  57. dashscope/customize/customize_types.py +192 -0
  58. dashscope/customize/deployments.py +146 -0
  59. dashscope/customize/finetunes.py +234 -0
  60. dashscope/embeddings/__init__.py +5 -1
  61. dashscope/embeddings/batch_text_embedding.py +208 -0
  62. dashscope/embeddings/batch_text_embedding_response.py +65 -0
  63. dashscope/embeddings/multimodal_embedding.py +118 -10
  64. dashscope/embeddings/text_embedding.py +13 -1
  65. dashscope/{file.py → files.py} +19 -4
  66. dashscope/io/input_output.py +2 -0
  67. dashscope/model.py +11 -2
  68. dashscope/models.py +43 -0
  69. dashscope/multimodal/__init__.py +20 -0
  70. dashscope/multimodal/dialog_state.py +56 -0
  71. dashscope/multimodal/multimodal_constants.py +28 -0
  72. dashscope/multimodal/multimodal_dialog.py +648 -0
  73. dashscope/multimodal/multimodal_request_params.py +313 -0
  74. dashscope/multimodal/tingwu/__init__.py +10 -0
  75. dashscope/multimodal/tingwu/tingwu.py +80 -0
  76. dashscope/multimodal/tingwu/tingwu_realtime.py +579 -0
  77. dashscope/nlp/__init__.py +0 -0
  78. dashscope/nlp/understanding.py +64 -0
  79. dashscope/protocol/websocket.py +3 -0
  80. dashscope/rerank/__init__.py +0 -0
  81. dashscope/rerank/text_rerank.py +69 -0
  82. dashscope/resources/qwen.tiktoken +151643 -0
  83. dashscope/threads/__init__.py +26 -0
  84. dashscope/threads/messages/__init__.py +0 -0
  85. dashscope/threads/messages/files.py +113 -0
  86. dashscope/threads/messages/messages.py +220 -0
  87. dashscope/threads/runs/__init__.py +0 -0
  88. dashscope/threads/runs/runs.py +501 -0
  89. dashscope/threads/runs/steps.py +112 -0
  90. dashscope/threads/thread_types.py +665 -0
  91. dashscope/threads/threads.py +212 -0
  92. dashscope/tokenizers/__init__.py +7 -0
  93. dashscope/tokenizers/qwen_tokenizer.py +111 -0
  94. dashscope/tokenizers/tokenization.py +125 -0
  95. dashscope/tokenizers/tokenizer.py +45 -0
  96. dashscope/tokenizers/tokenizer_base.py +32 -0
  97. dashscope/utils/__init__.py +0 -0
  98. dashscope/utils/message_utils.py +838 -0
  99. dashscope/utils/oss_utils.py +243 -0
  100. dashscope/utils/param_utils.py +29 -0
  101. dashscope/version.py +3 -1
  102. {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info}/METADATA +53 -50
  103. dashscope-1.25.6.dist-info/RECORD +112 -0
  104. {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info}/WHEEL +1 -1
  105. {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info}/entry_points.txt +0 -1
  106. {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info/licenses}/LICENSE +2 -4
  107. dashscope/deployment.py +0 -129
  108. dashscope/finetune.py +0 -149
  109. dashscope-1.8.0.dist-info/RECORD +0 -49
  110. {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info}/top_level.txt +0 -0
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  import asyncio
2
4
  import time
3
5
  from typing import List, Union
@@ -24,23 +26,54 @@ class Transcription(BaseAsyncApi):
24
26
  paraformer_mtl_v1 = 'paraformer-mtl-v1'
25
27
 
26
28
  @classmethod
27
- def call(cls, model: str, file_urls: List[str],
29
+ def call(cls,
30
+ model: str,
31
+ file_urls: List[str],
32
+ phrase_id: str = None,
33
+ api_key: str = None,
34
+ workspace: str = None,
28
35
  **kwargs) -> TranscriptionResponse:
29
36
  """Transcribe the given files synchronously.
30
37
 
31
38
  Args:
32
39
  model (str): The requested model_id.
33
40
  file_urls (List[str]): List of stored URLs.
34
- channel_id (List[int], optional): The selected channel_id of audio file. # noqa: E501
41
+ phrase_id (str, `optional`): The ID of phrase.
42
+ workspace (str): The dashscope workspace id.
43
+
44
+ **kwargs:
45
+ channel_id (List[int], optional):
46
+ The selected channel_id of audio file.
47
+ disfluency_removal_enabled(bool, `optional`):
48
+ Filter mood words, turned off by default.
49
+ diarization_enabled (bool, `optional`):
50
+ Speech auto diarization, turned off by default.
51
+ speaker_count (int, `optional`): The number of speakers.
52
+ timestamp_alignment_enabled (bool, `optional`):
53
+ Timestamp-alignment calibration, turned off by default.
54
+ special_word_filter(str, `optional`): Sensitive word filter.
55
+ audio_event_detection_enabled(bool, `optional`):
56
+ Audio event detection, turned off by default.
35
57
 
36
58
  Returns:
37
59
  TranscriptionResponse: The result of batch transcription.
38
60
  """
39
- response = super().call(model, file_urls, **kwargs)
61
+ kwargs.update(cls._fill_resource_id(phrase_id, **kwargs))
62
+ kwargs = cls._tidy_kwargs(**kwargs)
63
+ response = super().call(model,
64
+ file_urls,
65
+ api_key=api_key,
66
+ workspace=workspace,
67
+ **kwargs)
40
68
  return TranscriptionResponse.from_api_response(response)
41
69
 
42
70
  @classmethod
43
- def async_call(cls, model: str, file_urls: List[str],
71
+ def async_call(cls,
72
+ model: str,
73
+ file_urls: List[str],
74
+ phrase_id: str = None,
75
+ api_key: str = None,
76
+ workspace: str = None,
44
77
  **kwargs) -> TranscriptionResponse:
45
78
  """Transcribe the given files asynchronously,
46
79
  return the status of task submission for querying results subsequently.
@@ -48,23 +81,47 @@ class Transcription(BaseAsyncApi):
48
81
  Args:
49
82
  model (str): The requested model, such as paraformer-16k-1
50
83
  file_urls (List[str]): List of stored URLs.
51
- channel_id (List[int], optional): The selected channel_id of audio file. # noqa: E501
84
+ phrase_id (str, `optional`): The ID of phrase.
85
+ workspace (str): The dashscope workspace id.
86
+
87
+ **kwargs:
88
+ channel_id (List[int], optional):
89
+ The selected channel_id of audio file.
90
+ disfluency_removal_enabled(bool, `optional`):
91
+ Filter mood words, turned off by default.
92
+ diarization_enabled (bool, `optional`):
93
+ Speech auto diarization, turned off by default.
94
+ speaker_count (int, `optional`): The number of speakers.
95
+ timestamp_alignment_enabled (bool, `optional`):
96
+ Timestamp-alignment calibration, turned off by default.
97
+ special_word_filter(str, `optional`): Sensitive word filter.
98
+ audio_event_detection_enabled(bool, `optional`):
99
+ Audio event detection, turned off by default.
52
100
 
53
101
  Returns:
54
102
  TranscriptionResponse: The response including task_id.
55
103
  """
56
- response = cls._launch_request(model, file_urls, **kwargs)
104
+ kwargs.update(cls._fill_resource_id(phrase_id, **kwargs))
105
+ kwargs = cls._tidy_kwargs(**kwargs)
106
+ response = cls._launch_request(model,
107
+ file_urls,
108
+ api_key=api_key,
109
+ workspace=workspace,
110
+ **kwargs)
57
111
  return TranscriptionResponse.from_api_response(response)
58
112
 
59
113
  @classmethod
60
- def fetch(
61
- cls, task: Union[str,
62
- TranscriptionResponse]) -> TranscriptionResponse:
114
+ def fetch(cls,
115
+ task: Union[str, TranscriptionResponse],
116
+ api_key: str = None,
117
+ workspace: str = None,
118
+ **kwargs) -> TranscriptionResponse:
63
119
  """Fetch the status of task, including results of batch transcription when task_status is SUCCEEDED. # noqa: E501
64
120
 
65
121
  Args:
66
122
  task (Union[str, TranscriptionResponse]): The task_id or
67
123
  response including task_id returned from async_call().
124
+ workspace (str): The dashscope workspace id.
68
125
 
69
126
  Returns:
70
127
  TranscriptionResponse: The status of task_id,
@@ -73,7 +130,10 @@ class Transcription(BaseAsyncApi):
73
130
  try_count: int = 0
74
131
  while True:
75
132
  try:
76
- response = super().fetch(task)
133
+ response = super().fetch(task,
134
+ api_key=api_key,
135
+ workspace=workspace,
136
+ **kwargs)
77
137
  except (asyncio.TimeoutError, aiohttp.ClientConnectorError) as e:
78
138
  logger.error(e)
79
139
  try_count += 1
@@ -87,28 +147,40 @@ class Transcription(BaseAsyncApi):
87
147
  return TranscriptionResponse.from_api_response(response)
88
148
 
89
149
  @classmethod
90
- def wait(cls, task: Union[str,
91
- TranscriptionResponse]) -> TranscriptionResponse:
150
+ def wait(cls,
151
+ task: Union[str, TranscriptionResponse],
152
+ api_key: str = None,
153
+ workspace: str = None,
154
+ **kwargs) -> TranscriptionResponse:
92
155
  """Poll task until the final results of transcription is obtained.
93
156
 
94
157
  Args:
95
158
  task (Union[str, TranscriptionResponse]): The task_id or
96
159
  response including task_id returned from async_call().
160
+ workspace (str): The dashscope workspace id.
97
161
 
98
162
  Returns:
99
163
  TranscriptionResponse: The result of batch transcription.
100
164
  """
101
- response = super().wait(task)
165
+ response = super().wait(task,
166
+ api_key=api_key,
167
+ workspace=workspace,
168
+ **kwargs)
102
169
  return TranscriptionResponse.from_api_response(response)
103
170
 
104
171
  @classmethod
105
- def _launch_request(cls, model: str, files: List[str],
172
+ def _launch_request(cls,
173
+ model: str,
174
+ files: List[str],
175
+ api_key: str = None,
176
+ workspace: str = None,
106
177
  **kwargs) -> DashScopeAPIResponse:
107
178
  """Submit transcribe request.
108
179
 
109
180
  Args:
110
181
  model (str): The requested model, such as paraformer-16k-1
111
182
  files (List[str]): List of stored URLs.
183
+ workspace (str): The dashscope workspace id.
112
184
 
113
185
  Returns:
114
186
  DashScopeAPIResponse: The result of task submission.
@@ -125,6 +197,8 @@ class Transcription(BaseAsyncApi):
125
197
  input={'file_urls': files},
126
198
  api_protocol=ApiProtocol.HTTP,
127
199
  http_method=HTTPMethod.POST,
200
+ api_key=api_key,
201
+ workspace=workspace,
128
202
  **kwargs)
129
203
  except (asyncio.TimeoutError, aiohttp.ClientConnectorError) as e:
130
204
  logger.error(e)
@@ -136,3 +210,22 @@ class Transcription(BaseAsyncApi):
136
210
  break
137
211
 
138
212
  return response
213
+
214
+ @classmethod
215
+ def _fill_resource_id(cls, phrase_id: str, **kwargs):
216
+ resources_list: list = []
217
+ if phrase_id is not None and len(phrase_id) > 0:
218
+ item = {'resource_id': phrase_id, 'resource_type': 'asr_phrase'}
219
+ resources_list.append(item)
220
+
221
+ if len(resources_list) > 0:
222
+ kwargs['resources'] = resources_list
223
+
224
+ return kwargs
225
+
226
+ @classmethod
227
+ def _tidy_kwargs(cls, **kwargs):
228
+ for k in kwargs.copy():
229
+ if kwargs[k] is None:
230
+ kwargs.pop(k, None)
231
+ return kwargs