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
@@ -0,0 +1,243 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
3
+ import mimetypes
4
+ import os
5
+ from datetime import datetime
6
+ from http import HTTPStatus
7
+ from time import mktime
8
+ from typing import List
9
+ from urllib.parse import unquote_plus, urlparse
10
+ from wsgiref.handlers import format_date_time
11
+
12
+ import requests
13
+
14
+ from dashscope.api_entities.dashscope_response import DashScopeAPIResponse
15
+ from dashscope.client.base_api import GetMixin
16
+ from dashscope.common.constants import FILE_PATH_SCHEMA
17
+ from dashscope.common.error import InvalidInput, UploadFileException
18
+ from dashscope.common.logging import logger
19
+ from dashscope.common.utils import get_user_agent
20
+
21
+
22
+ class OssUtils(GetMixin):
23
+ SUB_PATH = 'uploads'
24
+
25
+ @classmethod
26
+ def _decode_response_error(cls, response: requests.Response):
27
+ if 'application/json' in response.headers.get('content-type', ''):
28
+ message = response.json()
29
+ else:
30
+ message = response.content.decode('utf-8')
31
+ return message
32
+
33
+ @classmethod
34
+ def upload(cls,
35
+ model: str,
36
+ file_path: str,
37
+ api_key: str = None,
38
+ upload_certificate: dict = None,
39
+ **kwargs):
40
+ """Upload file for model fine-tune or other tasks.
41
+
42
+ Args:
43
+ file_path (str): The local file name to upload.
44
+ purpose (str): The purpose of the file[fine-tune|inference]
45
+ description (str, optional): The file description message.
46
+ api_key (str, optional): The api key. Defaults to None.
47
+ upload_certificate (dict, optional): Reusable upload
48
+ certificate. Defaults to None.
49
+
50
+ Returns:
51
+ tuple: (file_url, upload_certificate) where file_url is the
52
+ OSS URL and upload_certificate is the certificate used
53
+ """
54
+ if upload_certificate is None:
55
+ upload_info = cls.get_upload_certificate(model=model,
56
+ api_key=api_key,
57
+ **kwargs)
58
+ if upload_info.status_code != HTTPStatus.OK:
59
+ raise UploadFileException(
60
+ 'Get upload certificate failed, code: %s, message: %s' %
61
+ (upload_info.code, upload_info.message))
62
+ upload_info = upload_info.output
63
+ else:
64
+ upload_info = upload_certificate
65
+ headers = {}
66
+ headers = {'user-agent': get_user_agent()}
67
+ headers['Accept'] = 'application/json'
68
+ headers['Date'] = format_date_time(mktime(datetime.now().timetuple()))
69
+ form_data = {}
70
+ form_data['OSSAccessKeyId'] = upload_info['oss_access_key_id']
71
+ form_data['Signature'] = upload_info['signature']
72
+ form_data['policy'] = upload_info['policy']
73
+ form_data['key'] = upload_info['upload_dir'] + \
74
+ '/' + os.path.basename(file_path)
75
+ form_data['x-oss-object-acl'] = upload_info['x_oss_object_acl']
76
+ form_data['x-oss-forbid-overwrite'] = upload_info[
77
+ 'x_oss_forbid_overwrite']
78
+ form_data['success_action_status'] = '200'
79
+ form_data['x-oss-content-type'] = mimetypes.guess_type(file_path)[0]
80
+ url = upload_info['upload_host']
81
+ files = {'file': open(file_path, 'rb')}
82
+ with requests.Session() as session:
83
+ response = session.post(url,
84
+ files=files,
85
+ data=form_data,
86
+ headers=headers,
87
+ timeout=3600)
88
+ if response.status_code == HTTPStatus.OK:
89
+ return 'oss://' + form_data['key'], upload_info
90
+ else:
91
+ msg = (
92
+ 'Uploading file: %s to oss failed, error: %s' %
93
+ (file_path, cls._decode_response_error(response=response)))
94
+ logger.error(msg)
95
+ raise UploadFileException(msg)
96
+
97
+ @classmethod
98
+ def get_upload_certificate(cls,
99
+ model: str,
100
+ api_key: str = None,
101
+ **kwargs) -> DashScopeAPIResponse:
102
+ """Get a oss upload certificate.
103
+
104
+ Args:
105
+ api_key (str, optional): The api key. Defaults to None.
106
+
107
+ Returns:
108
+ DashScopeAPIResponse: The job info
109
+ """
110
+ params = {'action': 'getPolicy'}
111
+ params['model'] = model
112
+ return super().get(None, api_key, params=params, **kwargs)
113
+
114
+
115
+ def upload_file(model: str, upload_path: str, api_key: str,
116
+ upload_certificate: dict = None):
117
+ if upload_path.startswith(FILE_PATH_SCHEMA):
118
+ parse_result = urlparse(upload_path)
119
+ if parse_result.netloc:
120
+ file_path = parse_result.netloc + unquote_plus(parse_result.path)
121
+ else:
122
+ file_path = unquote_plus(parse_result.path)
123
+ if os.path.exists(file_path):
124
+ file_url, _ = OssUtils.upload(model=model,
125
+ file_path=file_path,
126
+ api_key=api_key,
127
+ upload_certificate=upload_certificate)
128
+ if file_url is None:
129
+ raise UploadFileException('Uploading file: %s failed' %
130
+ upload_path)
131
+ return file_url
132
+ else:
133
+ raise InvalidInput('The file: %s is not exists!' % file_path)
134
+ return None
135
+
136
+
137
+ def check_and_upload_local(model: str, content: str, api_key: str,
138
+ upload_certificate: dict = None):
139
+ """Check the content is local file path, upload and return the url
140
+
141
+ Args:
142
+ model (str): Which model to upload.
143
+ content (str): The content.
144
+ api_key (_type_): The api key.
145
+ upload_certificate (dict, optional): Reusable upload certificate.
146
+ Defaults to None.
147
+
148
+ Raises:
149
+ UploadFileException: Upload failed.
150
+ InvalidInput: The input is invalid
151
+
152
+ Returns:
153
+ tuple: (is_upload, file_url_or_content, upload_certificate)
154
+ where is_upload indicates if file was uploaded, file_url_or_content
155
+ is the result URL or original content, and upload_certificate
156
+ is the certificate (newly obtained or passed in)
157
+ """
158
+ if content.startswith(FILE_PATH_SCHEMA):
159
+ parse_result = urlparse(content)
160
+ if parse_result.netloc:
161
+ file_path = parse_result.netloc + unquote_plus(parse_result.path)
162
+ else:
163
+ file_path = unquote_plus(parse_result.path)
164
+ if os.path.isfile(file_path):
165
+ file_url, cert = OssUtils.upload(model=model,
166
+ file_path=file_path,
167
+ api_key=api_key,
168
+ upload_certificate=upload_certificate)
169
+ if file_url is None:
170
+ raise UploadFileException('Uploading file: %s failed' %
171
+ content)
172
+ return True, file_url, cert
173
+ else:
174
+ raise InvalidInput('The file: %s is not exists!' % file_path)
175
+ elif content.startswith('oss://'):
176
+ return True, content, upload_certificate
177
+ elif not content.startswith('http'):
178
+ content = os.path.expanduser(content)
179
+ if os.path.isfile(content):
180
+ file_url, cert = OssUtils.upload(model=model,
181
+ file_path=content,
182
+ api_key=api_key,
183
+ upload_certificate=upload_certificate)
184
+ if file_url is None:
185
+ raise UploadFileException('Uploading file: %s failed' %
186
+ content)
187
+ return True, file_url, cert
188
+ return False, content, upload_certificate
189
+
190
+
191
+ def check_and_upload(model, elem: dict, api_key,
192
+ upload_certificate: dict = None):
193
+ """Check and upload files in element.
194
+
195
+ Args:
196
+ model: Model name
197
+ elem: Element dict containing file references
198
+ api_key: API key
199
+ upload_certificate: Optional upload certificate to reuse
200
+
201
+ Returns:
202
+ tuple: (has_upload, upload_certificate) where has_upload is bool
203
+ indicating if any file was uploaded, and upload_certificate
204
+ is the certificate (newly obtained or passed in)
205
+ """
206
+ has_upload = False
207
+ obtained_certificate = upload_certificate
208
+
209
+ for key, content in elem.items():
210
+ # support video:[images] for qwen2-vl
211
+ is_list = isinstance(content, list)
212
+ contents = content if is_list else [content]
213
+
214
+ if key in ['image', 'video', 'audio', 'text']:
215
+ for i, content in enumerate(contents):
216
+ is_upload, file_url, obtained_certificate = check_and_upload_local(
217
+ model, content, api_key, obtained_certificate)
218
+ if is_upload:
219
+ contents[i] = file_url
220
+ has_upload = True
221
+ elem[key] = contents if is_list else contents[0]
222
+
223
+ return has_upload, obtained_certificate
224
+
225
+
226
+ def preprocess_message_element(model: str, elem: dict, api_key: str,
227
+ upload_certificate: dict = None):
228
+ """Preprocess message element and upload files if needed.
229
+
230
+ Args:
231
+ model: Model name
232
+ elem: Element dict containing file references
233
+ api_key: API key
234
+ upload_certificate: Optional upload certificate to reuse
235
+
236
+ Returns:
237
+ tuple: (is_upload, upload_certificate) where is_upload is bool
238
+ indicating if any file was uploaded, and upload_certificate
239
+ is the certificate (newly obtained or passed in)
240
+ """
241
+ is_upload, cert = check_and_upload(model, elem, api_key,
242
+ upload_certificate)
243
+ return is_upload, cert
@@ -0,0 +1,29 @@
1
+
2
+ class ParamUtil:
3
+ @staticmethod
4
+ def should_modify_incremental_output(model_name: str) -> bool:
5
+ """
6
+ Determine if increment_output parameter needs to be modified based on
7
+ model name.
8
+
9
+ Args:
10
+ model_name (str): The name of the model to check
11
+
12
+ Returns:
13
+ bool: False if model contains 'tts', 'omni', or
14
+ 'qwen-deep-research', True otherwise
15
+ """
16
+ if not isinstance(model_name, str):
17
+ return True
18
+
19
+ model_name_lower = model_name.lower()
20
+
21
+ # Check for conditions that return False
22
+ if 'tts' in model_name_lower:
23
+ return False
24
+ if 'omni' in model_name_lower:
25
+ return False
26
+ if 'qwen-deep-research' in model_name_lower:
27
+ return False
28
+
29
+ return True
dashscope/version.py CHANGED
@@ -1 +1,3 @@
1
- __version__ = '1.8.0'
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
3
+ __version__ = '1.25.6'
@@ -1,10 +1,10 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: dashscope
3
- Version: 1.8.0
3
+ Version: 1.25.6
4
4
  Summary: dashscope client sdk library
5
5
  Home-page: https://dashscope.aliyun.com/
6
- Author: Alibaba
7
- Author-email: dashscope@alibaba-inc.com
6
+ Author: Alibaba Cloud
7
+ Author-email: dashscope@alibabacloud.com
8
8
  License: Apache 2.0
9
9
  Platform: Posix; MacOS X; Windows
10
10
  Classifier: Development Status :: 4 - Beta
@@ -12,15 +12,33 @@ Classifier: Intended Audience :: Developers
12
12
  Classifier: License :: OSI Approved :: Apache Software License
13
13
  Classifier: Programming Language :: Python
14
14
  Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.7
16
15
  Classifier: Programming Language :: Python :: 3.8
17
16
  Classifier: Programming Language :: Python :: 3.9
18
17
  Classifier: Programming Language :: Python :: 3.10
19
18
  Classifier: Programming Language :: Python :: 3.11
20
- Requires-Python: >=3.7.0
19
+ Requires-Python: >=3.8.0
21
20
  Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
22
  Requires-Dist: aiohttp
23
23
  Requires-Dist: requests
24
+ Requires-Dist: websocket-client
25
+ Requires-Dist: cryptography
26
+ Requires-Dist: certifi
27
+ Provides-Extra: tokenizer
28
+ Requires-Dist: tiktoken; extra == "tokenizer"
29
+ Dynamic: author
30
+ Dynamic: author-email
31
+ Dynamic: classifier
32
+ Dynamic: description
33
+ Dynamic: description-content-type
34
+ Dynamic: home-page
35
+ Dynamic: license
36
+ Dynamic: license-file
37
+ Dynamic: platform
38
+ Dynamic: provides-extra
39
+ Dynamic: requires-dist
40
+ Dynamic: requires-python
41
+ Dynamic: summary
24
42
 
25
43
  <h4 align="center">
26
44
  <p>
@@ -44,11 +62,15 @@ If you clone the code from github, you can install from source by running:
44
62
  pip install -e .
45
63
  ```
46
64
 
65
+ To use tokenizer in local mode without downloading any files, run:
66
+ ```shell
67
+ pip install dashscope[tokenizer]
68
+ ```
47
69
 
48
70
 
49
71
  ## QuickStart
50
72
 
51
- You can use `Generation` api to call model qwen-v1(通义千问).
73
+ You can use `Generation` api to call model qwen-turbo(通义千问).
52
74
 
53
75
  ```python
54
76
  from http import HTTPStatus
@@ -56,7 +78,7 @@ import dashscope
56
78
  from dashscope import Generation
57
79
 
58
80
  dashscope.api_key = 'YOUR-DASHSCOPE-API-KEY'
59
- responses = Generation.call(model=Generation.Models.qwen_v1,
81
+ responses = Generation.call(model=Generation.Models.qwen_turbo,
60
82
  prompt='今天天气好吗?')
61
83
 
62
84
  if responses.status_code == HTTPStatus.OK:
@@ -70,7 +92,7 @@ else:
70
92
 
71
93
  ## API Key Authentication
72
94
 
73
- The SDK uses API key for authentication. Please refer to [official documentation](https://dashscope.aliyun.com) regarding how to obtain your api-key.
95
+ The SDK uses API key for authentication. Please refer to [official documentation for alibabacloud china](https://www.alibabacloud.com/help/en/model-studio/) and [official documentation for alibabacloud international](https://www.alibabacloud.com/help/en/model-studio/) regarding how to obtain your api-key.
74
96
 
75
97
  ### Using the API Key
76
98
 
@@ -118,7 +140,7 @@ from dashscope import Generation
118
140
  # export DASHSCOPE_API_KEY='YOUR-DASHSCOPE-API-KEY' in environment
119
141
  def sync_dashscope_sample():
120
142
  responses = Generation.call(
121
- model=Generation.Models.qwen_v1,
143
+ model=Generation.Models.qwen_turbo,
122
144
  prompt='Is the weather good today?')
123
145
 
124
146
  if responses.status_code == HTTPStatus.OK:
@@ -142,7 +164,7 @@ from dashscope import Generation
142
164
  def sample_sync_call_stream():
143
165
  prompt_text = 'Give me a recipe using carrots, potatoes, and eggplants'
144
166
  response_generator = Generation.call(
145
- model=Generation.Models.qwen_v1,
167
+ model=Generation.Models.qwen_turbo,
146
168
  prompt=prompt_text,
147
169
  stream=True,
148
170
  max_length=512,
@@ -157,50 +179,33 @@ if __name__ == '__main__':
157
179
  sample_sync_call_stream()
158
180
 
159
181
  ```
160
- #### Streaming with History
182
+ #### Stream with Messages
161
183
  ```python
162
184
  from http import HTTPStatus
185
+ from dashscope import Generation
186
+ from dashscope.api_entities.dashscope_response import Role
163
187
 
164
- from dashscope import Conversation, History, HistoryItem
165
- def conversation_stream_example():
166
- history = History()
167
- item = HistoryItem('user', text='Is the weather good today?')
168
- history.append(item)
169
- item = HistoryItem('bot', text='The weather is nice today, do you want to go out and play?')
170
- history.append(item)
171
-
172
- item = HistoryItem('user', text='Do you have any places to recommend?')
173
- history.append(item)
174
- item = HistoryItem('bot', text='I suggest you go to the park. Spring is here, and the flowers are blooming. It is beautiful.')
175
- history.append(item)
176
- chat = Conversation(history)
177
- response = chat.call(Conversation.Models.qwen_v1,
178
- prompt='Recommend a nearby park',
179
- stream=True)
180
- for part in response:
181
- if part.status_code == HTTPStatus.OK:
182
- print(part.output)
183
- else:
184
- print('Failed request_id: %s, status_code: %s code: %s, message:%s' %
185
- (part.id, part.status_code, part.code, part.message))
186
- response = chat.call(
187
- Conversation.Models.qwen_v1,
188
- prompt='I have been to that park many times, how about a more distant one?',
189
- auto_history=True,
188
+
189
+ def stream_with_messages():
190
+ messages = [{'role': Role.SYSTEM, 'content': 'You are a helpful assistant.'},
191
+ {'role': Role.USER, 'content': '如何做西红柿炖牛腩?'}]
192
+ responses = Generation.call(
193
+ Generation.Models.qwen_turbo,
194
+ messages=messages,
195
+ result_format='message', # set the result to be "message" format.
190
196
  stream=True,
191
197
  )
192
- for part in response:
193
- if part.status_code == HTTPStatus.OK:
194
- print(part.output.text)
195
- print(part.usage)
196
- else:
197
- print('Failed request_id: %s, status_code: %s, code: %s, message:%s' %
198
- (part.id, part.status_code, part.code, part.message))
199
-
198
+ for response in responses:
199
+ if response.status_code == HTTPStatus.OK:
200
+ print(response)
201
+ else:
202
+ print('Request id: %s, Status code: %s, error code: %s, error message: %s' % (
203
+ response.request_id, response.status_code,
204
+ response.code, response.message
205
+ ))
200
206
 
201
207
  if __name__ == '__main__':
202
- conversation_stream_example()
203
-
208
+ stream_with_messages()
204
209
 
205
210
  ```
206
211
  ## Logging
@@ -232,5 +237,3 @@ Coming soon.
232
237
 
233
238
  ## License
234
239
  This project is licensed under the Apache License (Version 2.0).
235
-
236
-
@@ -0,0 +1,112 @@
1
+ dashscope/__init__.py,sha256=96J137Im9Ii9uxfVOOYkZDJNZXF1sEbcH4-QXFr4xEw,3172
2
+ dashscope/cli.py,sha256=TnVznRfApUvVnLpcHDR3nkDE2S8MTZ5v1Zz5V6I68Xw,26504
3
+ dashscope/files.py,sha256=vRDQygm3lOqBZR73o7KNHs1iTBVuvLncuwJNxIYjzAU,3981
4
+ dashscope/model.py,sha256=B5v_BtYLPqj6raClejBgdKg6WTGwhH_f-20pvsQqmsk,1491
5
+ dashscope/models.py,sha256=dE4mzXkl85G343qVylSGpURPRdA5pZSqXlx6PcxqC_Q,1275
6
+ dashscope/version.py,sha256=pMSfOWOD6FDFxEPwRdrBUVLcKr0ZXw2XBXxXPLAwg2U,74
7
+ dashscope/aigc/__init__.py,sha256=kYvYEoRK-NUHyMWpBDNQBz4fVA__uOhHRK2kDTBaWgk,617
8
+ dashscope/aigc/chat_completion.py,sha256=ONlyyssIbfaKKcFo7cEKhHx5OCF2XX810HFzIExW1ho,14813
9
+ dashscope/aigc/code_generation.py,sha256=p_mxDKJLQMW0IjFD46JRlZuEZCRESSVKEfLlAevBtqw,10936
10
+ dashscope/aigc/conversation.py,sha256=95xEEY4ThZJysj5zy3aMw7ql9KLJVfD_1iHv9QZ17Ew,14282
11
+ dashscope/aigc/generation.py,sha256=jyQzNEmcGOK4o9OjxVAULeGhN-tNcn3npQGbQI87okk,21563
12
+ dashscope/aigc/image_synthesis.py,sha256=Qwg3YMEsWrb3uZVX0fU5zepjM0J3fFFSJB1OfGP01NQ,29086
13
+ dashscope/aigc/multimodal_conversation.py,sha256=p0G6n2zK0Lb6VxfbqV-vwTbuK1wkAGoTq-0gfuV6_Ao,16345
14
+ dashscope/aigc/video_synthesis.py,sha256=g2QLSgeRr7dNzAy-DtwMsZ3YlVS8So95tG6KCXyoz7g,28252
15
+ dashscope/api_entities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
+ dashscope/api_entities/aiohttp_request.py,sha256=6xHh31lURgMtBRcUui0Sl-Pxh_uISkEV2bUSoHjdWlc,10452
17
+ dashscope/api_entities/api_request_data.py,sha256=04rpYPNK1HkT3iTPJmZpquH621xcBbe8R8EGrDJSLt0,5514
18
+ dashscope/api_entities/api_request_factory.py,sha256=D8ti5JW-odrhGUZUBe4c9XOqOkIo-ScUU2-bE8X2Uaw,5936
19
+ dashscope/api_entities/base_request.py,sha256=FKBJNGXnBNKV5j-B_h1yXomsM843I0ccJRZNH2GbejY,1357
20
+ dashscope/api_entities/chat_completion_types.py,sha256=1WMWPszhM3HaJBVz-ZXx-El4D8-RfVUL3ym65xsDRLk,11435
21
+ dashscope/api_entities/dashscope_response.py,sha256=31guU41ePkLyFsVVN-1WODXdOHiURzRyxxhrUmX9dGM,22835
22
+ dashscope/api_entities/encryption.py,sha256=rUCZx3wwVvS5oyKXEeWgyWPxM8Y5d4AaVdgxLhizBqA,5517
23
+ dashscope/api_entities/http_request.py,sha256=dlSzY8R2OT2uThNznq1S0voNzGYITY6XIYlP149fhXI,16656
24
+ dashscope/api_entities/websocket_request.py,sha256=-Q0pn-DNaXl9dBo2kQSDYX4gD4AF0Rs3bNw2_m980eY,16197
25
+ dashscope/app/__init__.py,sha256=xvSvU8O7m5u7vgIvJXTJektJZxmjT2Rpt_YwePH88XE,113
26
+ dashscope/app/application.py,sha256=79wnnvAAjWBJ8TtMUN6-B4FHBV7twkAOzhXg7yDJQxE,9620
27
+ dashscope/app/application_response.py,sha256=XO6iOZlt7OXulvFS71zwAq_HXYkn3HLJdAimTWPP0B4,8568
28
+ dashscope/assistants/__init__.py,sha256=hjCTuv13yFaXyUqlexAU-RaO0Ahq3P7VK9_LkSbkGVU,434
29
+ dashscope/assistants/assistant_types.py,sha256=qVDSy0xcsMq_sAD7t_ppoGLBN2QDiHqarAAlW_CDDtY,4478
30
+ dashscope/assistants/assistants.py,sha256=X6wUEFkpMwQBkjcBaraux0-gu6nwEWD0BUGfygLAE0A,12531
31
+ dashscope/assistants/files.py,sha256=CaQkZK7TFeMaAxtqMi-1rBVJrlKXdehZG9plNZ6zslo,7060
32
+ dashscope/audio/__init__.py,sha256=7e3ejVsDJxEbMHN-9E0nEDfU-CnnQ4JgtgUxqNs0IG4,192
33
+ dashscope/audio/asr/__init__.py,sha256=JoCenJAUVOQXPmAn1toKeFYCfc8BqNn0NKpqjuJvNJc,1055
34
+ dashscope/audio/asr/asr_phrase_manager.py,sha256=vHOLExaKCtjedkihIu7gyfQyarR9rN5JZn79LvlCpco,7693
35
+ dashscope/audio/asr/recognition.py,sha256=UtGxKZNqH353esaO7IZ4c3-yfBVfLJt0zXiKeMQwrAc,21243
36
+ dashscope/audio/asr/transcription.py,sha256=lYzPjh7jJQwjMoxx8-AY0YCMBKNKO0bi7xd5tZGSHPc,9094
37
+ dashscope/audio/asr/translation_recognizer.py,sha256=JgBmhkIl_kqH8uVwop6Fba5KlXccftKFrhaygN9PKjU,39680
38
+ dashscope/audio/asr/vocabulary.py,sha256=N0pMS2x1lDxqJ14FgTGKctfuVkR2_hlEsCNWFcgYpTY,6717
39
+ dashscope/audio/qwen_asr/__init__.py,sha256=_Q5S6yk8kgKsTrrQjnc5J_SDn6tbGL9x9lbwVr89--o,143
40
+ dashscope/audio/qwen_asr/qwen_transcription.py,sha256=zphysnudKTfTBHUdYtzTTP0TVHKbV1q4PwiM8n_Ig8Y,6895
41
+ dashscope/audio/qwen_omni/__init__.py,sha256=MEFxmyxr5H6bW22l_R9073Pl6Ka6knvhrATGT-4UBjI,298
42
+ dashscope/audio/qwen_omni/omni_realtime.py,sha256=U5AyDMkCTC03hPpv02kh0jGtemoOQlCwERMB4g6m55c,19203
43
+ dashscope/audio/qwen_tts/__init__.py,sha256=JS3axY1grqO0aTIJufZ3KS1JsU6yf6y4K2CQlNvUK9I,132
44
+ dashscope/audio/qwen_tts/speech_synthesizer.py,sha256=7LHR-PXhn-VE1cCOp_82Jq0zE9rMc3xy3dszUeyLLNs,2927
45
+ dashscope/audio/qwen_tts_realtime/__init__.py,sha256=vVkmeJr_mEAn_O0Rh5AU3ICg6qIZqppUryJ5lY8VYPo,254
46
+ dashscope/audio/qwen_tts_realtime/qwen_tts_realtime.py,sha256=ls2ClKpE8p9WeKxNLrSqOleuooWadN5L-nXsOyT08Hs,12263
47
+ dashscope/audio/tts/__init__.py,sha256=xYpMFseUZGgqgj_70zcX2VsLv-L7qxJ3d-bbdj_hO0I,245
48
+ dashscope/audio/tts/speech_synthesizer.py,sha256=vD1xQV-rew8qAsIaAGH5amsNtB0SqdtNhVHhJHGQ-xk,7622
49
+ dashscope/audio/tts_v2/__init__.py,sha256=OMGamiOvp_wvPVSOFKhsWOiIzYPCJKZtVnfEkxpVDpA,465
50
+ dashscope/audio/tts_v2/enrollment.py,sha256=ekeZJz_swhI0OwRANuUwsZjdP0rRoUergSsCUQmsh8E,6577
51
+ dashscope/audio/tts_v2/speech_synthesizer.py,sha256=Gcyp73nAiN0EwQ05NtA-SBFJnofL856YUOP3iuxPm5M,33924
52
+ dashscope/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
53
+ dashscope/client/base_api.py,sha256=znAJ65DeHiFw1H7FWK0YrkLz1CoNcyqUxF8EJ3gujeY,52523
54
+ dashscope/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
55
+ dashscope/common/api_key.py,sha256=yqFCAteq8CNQGnlLv6fxNFWsLqsQDbSzOpgAlUmDkaE,2037
56
+ dashscope/common/base_type.py,sha256=2OQDqFlEH43wn54i-691cbarV_eKRLvRsPGfyb_GS0g,4670
57
+ dashscope/common/constants.py,sha256=ZlpJNPF8WyqBZjLGJdXWrnyxl7Ntn2ug_XexYNtbMxc,2492
58
+ dashscope/common/env.py,sha256=9yWWdKqfYuHlTQSvbTBaQhGbASh5Lq6SbM9pPx8hB40,920
59
+ dashscope/common/error.py,sha256=sXQqBGWCUBPyKa5rAI6DWc0sEidH01sR8zlIBfrTTDU,2690
60
+ dashscope/common/logging.py,sha256=lX86X9ND1MC5mA_qKAktwaVXd_BufLgmSGPggUiEJZo,1035
61
+ dashscope/common/message_manager.py,sha256=mZ7fS5LV09huwvz-2nxrr2RFQ9fQAYhEpeUmFb7WfW4,1148
62
+ dashscope/common/utils.py,sha256=i0pnYxz5zErw1wM-eFQx2XLfOmBjFscqG4-aEJYnlRc,15439
63
+ dashscope/customize/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
64
+ dashscope/customize/customize_types.py,sha256=02qxJ-FodKS9Sgl7blx7IAx_eOdpf53L1mZ909PSMsM,4854
65
+ dashscope/customize/deployments.py,sha256=2BxjgukuXe9bkl1VOvvKky0NxkcXVL3xk07UusjwZII,5240
66
+ dashscope/customize/finetunes.py,sha256=AL_kGTJXMvM2ej-EKsLLd1dUphPQdVTefFVCSVH-C-w,8362
67
+ dashscope/embeddings/__init__.py,sha256=XQ7vKr8oZM2CmdOduE53BWy6_Qpn9xUPkma64yw8Gws,291
68
+ dashscope/embeddings/batch_text_embedding.py,sha256=lVhvTS8McYfXuqt_8CmmhA6bPqD0nrGv965kjYG_j0E,8842
69
+ dashscope/embeddings/batch_text_embedding_response.py,sha256=ZfkJMUq8GRsFA6XUTsiAsIySqGJH-VPi2P9Ba1KTU-s,2056
70
+ dashscope/embeddings/multimodal_embedding.py,sha256=Sb8jQPN7XYv9vqOAltq99YNEM_VLY4cRa1E5oocspRM,6964
71
+ dashscope/embeddings/text_embedding.py,sha256=2MPEyMB99xueDbvFg9kKAe8bgHMDEaFLaFa6GzDWDHg,2108
72
+ dashscope/io/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
73
+ dashscope/io/input_output.py,sha256=0aXrRJFo1ZqYm_AJWR_w88O4-Btn9np2zUhrrUdBdfw,3992
74
+ dashscope/multimodal/__init__.py,sha256=fyqeolbDLWVn5wSpPZ3nAOnUBRF9k6mlsy6dCmgjPvI,533
75
+ dashscope/multimodal/dialog_state.py,sha256=CtOdfGWhq0ePG3bc8-7inhespETtPD4QDli1513hd1A,1522
76
+ dashscope/multimodal/multimodal_constants.py,sha256=z_QVq01E43FAqKQnDu9vdf89d1zuYlWyANewWTEXVJM,1282
77
+ dashscope/multimodal/multimodal_dialog.py,sha256=elHxPlvG0V6F_lFhyRDywI55qFhGexZJzf2EbtziiVk,24331
78
+ dashscope/multimodal/multimodal_request_params.py,sha256=XcPhr6lhz7DdGKPmQxVIzh2Nn4t25VhY0LABF1UmVXk,9385
79
+ dashscope/multimodal/tingwu/__init__.py,sha256=Gi9GEM0bdeJlZpvyksSeHOc2--_tG5aF6QAx6TAS2fE,225
80
+ dashscope/multimodal/tingwu/tingwu.py,sha256=01d-QOeuB1QmRhiZqbXJ8pHoGqT0C-xZTjIs_ZBXOyw,2613
81
+ dashscope/multimodal/tingwu/tingwu_realtime.py,sha256=oBeqrZit3uBZHuyI7m9VILz2qaqJRMO0-Nm2eJ5Q63g,20215
82
+ dashscope/nlp/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
83
+ dashscope/nlp/understanding.py,sha256=00ado-ibYEzBRT0DgKGd3bohQDNW73xnFhJ_1aa87lw,2880
84
+ dashscope/protocol/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
85
+ dashscope/protocol/websocket.py,sha256=k4B8GOBeyvAxqVQ47JhWfXfNErIhiVlQ-VCiKLLG0Ho,613
86
+ dashscope/rerank/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
87
+ dashscope/rerank/text_rerank.py,sha256=NKN3vnWprguhHy2_g0D7znZ7jEGrLX4zMaLE3jBrl94,2449
88
+ dashscope/resources/qwen.tiktoken,sha256=srG437XMXwJLr8NzEhxquj9m-aWgJp4kNHCh3hajMYY,2561218
89
+ dashscope/threads/__init__.py,sha256=3IKX9vZWhT87XrVx1pA_g3MWHEekXoJJSZeE_CTWL08,672
90
+ dashscope/threads/thread_types.py,sha256=brek-eTM9147TAlDxpLKlFcp-JBcSNo6Slg76t0O_dk,18604
91
+ dashscope/threads/threads.py,sha256=J9QGY0vy6MldC4ujQMyiYc9jN4aH9NGj0SkcWZHwkj0,7716
92
+ dashscope/threads/messages/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
93
+ dashscope/threads/messages/files.py,sha256=WxKVQednISIh2MY8N1B6Y4HjGllFhcLKCsc4QXKZ6AQ,3871
94
+ dashscope/threads/messages/messages.py,sha256=peKqehK8JO0ZwRXACaojg6-61TkBBbqd190xtKIbOZo,8470
95
+ dashscope/threads/runs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
96
+ dashscope/threads/runs/runs.py,sha256=PsUL5IFw-kF8WXEl_CnL1vMGIuP7S7MWzkLhHJCCKDA,19442
97
+ dashscope/threads/runs/steps.py,sha256=579EsCOwsamuJMSNrrrX86h9JfMdXNlErVJ8XakSqSc,3689
98
+ dashscope/tokenizers/__init__.py,sha256=TvVAsDam5S0R4rorxdfyUGIEQQX1q8nQ--RxsWWos3A,251
99
+ dashscope/tokenizers/qwen_tokenizer.py,sha256=tvX7x34Rg_NFFc1XjneXNFfXVkePdqkgHHShce2RJGo,4162
100
+ dashscope/tokenizers/tokenization.py,sha256=ubQBJ_yw_MoHuHxZcK9NarZSSbyExloeSOLIWYhRzH0,4824
101
+ dashscope/tokenizers/tokenizer.py,sha256=3FQVDvMNkCW9ccYeJdjrd_PIMMD3Xv7aNZkaYOE4XX4,1205
102
+ dashscope/tokenizers/tokenizer_base.py,sha256=5EJIFuizMWESEmLmbd38yJnfeHmPnzZPwsO4aOGjpl4,707
103
+ dashscope/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
104
+ dashscope/utils/message_utils.py,sha256=7Qf-jbp8zerlYsNS92nR2lBgQ4o6JlAYVtZpRxOiMQk,44371
105
+ dashscope/utils/oss_utils.py,sha256=6VG-1YeuiYsQqgRFSvCA6B4kIp2E69GzxZ1Bd0BAAns,9942
106
+ dashscope/utils/param_utils.py,sha256=QSmg49cJ8oR24tq2ghLhdLRQPE3KvA3qXhSP_SCAXig,826
107
+ dashscope-1.25.6.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
108
+ dashscope-1.25.6.dist-info/METADATA,sha256=bZwQcVLP4bKA5x2izTMVko2QpAOhdptSQa1m5T9h8G0,7146
109
+ dashscope-1.25.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
110
+ dashscope-1.25.6.dist-info/entry_points.txt,sha256=e9C3sOf9zDYL0O5ROEGX6FT8w-QK_kaGRWmPZDHAFys,49
111
+ dashscope-1.25.6.dist-info/top_level.txt,sha256=woqavFJK9zas5xTqynmALqOtlafghjsk63Xk86powTU,10
112
+ dashscope-1.25.6.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.37.1)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,3 +1,2 @@
1
1
  [console_scripts]
2
2
  dashscope = dashscope.cli:main
3
-
@@ -1,5 +1,3 @@
1
- Copyright 2023-2024 Alibaba DashScope. All rights reserved.
2
-
3
1
  Apache License
4
2
  Version 2.0, January 2004
5
3
  http://www.apache.org/licenses/
@@ -188,7 +186,7 @@ Copyright 2023-2024 Alibaba DashScope. All rights reserved.
188
186
  same "printed page" as the copyright notice for easier
189
187
  identification within third-party archives.
190
188
 
191
- Copyright 2020-2023 Alibaba DashScope.
189
+ Copyright [yyyy] [name of copyright owner]
192
190
 
193
191
  Licensed under the Apache License, Version 2.0 (the "License");
194
192
  you may not use this file except in compliance with the License.
@@ -200,4 +198,4 @@ Copyright 2023-2024 Alibaba DashScope. All rights reserved.
200
198
  distributed under the License is distributed on an "AS IS" BASIS,
201
199
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
200
  See the License for the specific language governing permissions and
203
- limitations under the License.
201
+ limitations under the License.