dashscope 1.0.2__tar.gz → 1.26.0__tar.gz

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 (225) hide show
  1. {dashscope-1.0.2 → dashscope-1.26.0}/LICENSE +2 -4
  2. dashscope-1.26.0/MANIFEST.in +4 -0
  3. dashscope-1.26.0/PKG-INFO +564 -0
  4. dashscope-1.26.0/README.md +520 -0
  5. dashscope-1.26.0/dashscope/__init__.py +142 -0
  6. dashscope-1.26.0/dashscope/aigc/__init__.py +24 -0
  7. dashscope-1.26.0/dashscope/aigc/chat_completion.py +301 -0
  8. dashscope-1.26.0/dashscope/aigc/code_generation.py +177 -0
  9. dashscope-1.26.0/dashscope/aigc/conversation.py +410 -0
  10. dashscope-1.26.0/dashscope/aigc/generation.py +498 -0
  11. dashscope-1.26.0/dashscope/aigc/image_generation.py +669 -0
  12. dashscope-1.26.0/dashscope/aigc/image_synthesis.py +836 -0
  13. dashscope-1.26.0/dashscope/aigc/multimodal_conversation.py +515 -0
  14. dashscope-1.26.0/dashscope/aigc/video_synthesis.py +991 -0
  15. dashscope-1.26.0/dashscope/api_entities/aio_session.py +59 -0
  16. dashscope-1.26.0/dashscope/api_entities/aiohttp_request.py +319 -0
  17. {dashscope-1.0.2 → dashscope-1.26.0}/dashscope/api_entities/api_request_data.py +48 -30
  18. dashscope-1.26.0/dashscope/api_entities/api_request_factory.py +189 -0
  19. dashscope-1.26.0/dashscope/api_entities/base_request.py +36 -0
  20. dashscope-1.26.0/dashscope/api_entities/chat_completion_types.py +395 -0
  21. dashscope-1.26.0/dashscope/api_entities/dashscope_response.py +943 -0
  22. dashscope-1.26.0/dashscope/api_entities/encryption.py +194 -0
  23. dashscope-1.26.0/dashscope/api_entities/http_request.py +515 -0
  24. {dashscope-1.0.2 → dashscope-1.26.0}/dashscope/api_entities/websocket_request.py +203 -127
  25. dashscope-1.26.0/dashscope/app/__init__.py +6 -0
  26. dashscope-1.26.0/dashscope/app/application.py +293 -0
  27. dashscope-1.26.0/dashscope/app/application_response.py +272 -0
  28. dashscope-1.26.0/dashscope/assistants/__init__.py +19 -0
  29. dashscope-1.26.0/dashscope/assistants/assistant_types.py +193 -0
  30. dashscope-1.26.0/dashscope/assistants/assistants.py +404 -0
  31. dashscope-1.26.0/dashscope/assistants/files.py +236 -0
  32. dashscope-1.26.0/dashscope/audio/__init__.py +13 -0
  33. dashscope-1.26.0/dashscope/audio/asr/__init__.py +33 -0
  34. dashscope-1.26.0/dashscope/audio/asr/asr_phrase_manager.py +224 -0
  35. dashscope-1.26.0/dashscope/audio/asr/recognition.py +605 -0
  36. dashscope-1.26.0/dashscope/audio/asr/transcription.py +261 -0
  37. dashscope-1.26.0/dashscope/audio/asr/translation_recognizer.py +1092 -0
  38. dashscope-1.26.0/dashscope/audio/asr/vocabulary.py +236 -0
  39. dashscope-1.26.0/dashscope/audio/http_tts/__init__.py +12 -0
  40. dashscope-1.26.0/dashscope/audio/http_tts/http_speech_synthesizer.py +293 -0
  41. dashscope-1.26.0/dashscope/audio/qwen_asr/__init__.py +8 -0
  42. dashscope-1.26.0/dashscope/audio/qwen_asr/qwen_transcription.py +216 -0
  43. dashscope-1.26.0/dashscope/audio/qwen_omni/__init__.py +16 -0
  44. dashscope-1.26.0/dashscope/audio/qwen_omni/omni_realtime.py +628 -0
  45. dashscope-1.26.0/dashscope/audio/qwen_tts/__init__.py +6 -0
  46. dashscope-1.26.0/dashscope/audio/qwen_tts/speech_synthesizer.py +85 -0
  47. dashscope-1.26.0/dashscope/audio/qwen_tts_realtime/__init__.py +14 -0
  48. dashscope-1.26.0/dashscope/audio/qwen_tts_realtime/qwen_tts_realtime.py +416 -0
  49. dashscope-1.26.0/dashscope/audio/tts/__init__.py +10 -0
  50. dashscope-1.26.0/dashscope/audio/tts/speech_synthesizer.py +229 -0
  51. dashscope-1.26.0/dashscope/audio/tts_v2/__init__.py +19 -0
  52. dashscope-1.26.0/dashscope/audio/tts_v2/enrollment.py +246 -0
  53. dashscope-1.26.0/dashscope/audio/tts_v2/speech_synthesizer.py +1067 -0
  54. dashscope-1.26.0/dashscope/cli/__init__.py +342 -0
  55. dashscope-1.26.0/dashscope/cli/__main__.py +17 -0
  56. dashscope-1.26.0/dashscope/cli/agentic_rl.py +720 -0
  57. dashscope-1.26.0/dashscope/cli/application.py +87 -0
  58. dashscope-1.26.0/dashscope/cli/code_generation.py +81 -0
  59. dashscope-1.26.0/dashscope/cli/common.py +100 -0
  60. dashscope-1.26.0/dashscope/cli/deployments.py +209 -0
  61. dashscope-1.26.0/dashscope/cli/embeddings.py +79 -0
  62. dashscope-1.26.0/dashscope/cli/files.py +136 -0
  63. dashscope-1.26.0/dashscope/cli/fine_tunes.py +345 -0
  64. dashscope-1.26.0/dashscope/cli/generation.py +215 -0
  65. dashscope-1.26.0/dashscope/cli/image_generation.py +88 -0
  66. dashscope-1.26.0/dashscope/cli/image_synthesis.py +67 -0
  67. dashscope-1.26.0/dashscope/cli/models.py +54 -0
  68. dashscope-1.26.0/dashscope/cli/multimodal_conversation.py +98 -0
  69. dashscope-1.26.0/dashscope/cli/multimodal_embedding.py +126 -0
  70. dashscope-1.26.0/dashscope/cli/oss.py +83 -0
  71. dashscope-1.26.0/dashscope/cli/rerank.py +71 -0
  72. dashscope-1.26.0/dashscope/cli/speech_synthesis.py +84 -0
  73. dashscope-1.26.0/dashscope/cli/tokenization.py +54 -0
  74. dashscope-1.26.0/dashscope/cli/transcription.py +100 -0
  75. dashscope-1.26.0/dashscope/cli/understanding.py +60 -0
  76. dashscope-1.26.0/dashscope/cli/video_synthesis.py +215 -0
  77. dashscope-1.26.0/dashscope/client/base_api.py +1617 -0
  78. dashscope-1.26.0/dashscope/common/api_key.py +55 -0
  79. dashscope-1.26.0/dashscope/common/base_type.py +139 -0
  80. dashscope-1.26.0/dashscope/common/constants.py +98 -0
  81. dashscope-1.26.0/dashscope/common/env.py +31 -0
  82. dashscope-1.26.0/dashscope/common/error.py +146 -0
  83. {dashscope-1.0.2 → dashscope-1.26.0}/dashscope/common/logging.py +8 -5
  84. dashscope-1.26.0/dashscope/common/message_manager.py +38 -0
  85. dashscope-1.26.0/dashscope/common/utils.py +529 -0
  86. dashscope-1.26.0/dashscope/embeddings/__init__.py +12 -0
  87. dashscope-1.26.0/dashscope/embeddings/batch_text_embedding.py +235 -0
  88. dashscope-1.26.0/dashscope/embeddings/batch_text_embedding_response.py +74 -0
  89. dashscope-1.26.0/dashscope/embeddings/multimodal_embedding.py +302 -0
  90. dashscope-1.26.0/dashscope/embeddings/text_embedding.py +82 -0
  91. dashscope-1.26.0/dashscope/files.py +136 -0
  92. dashscope-1.26.0/dashscope/finetune/agentic_rl.py +462 -0
  93. dashscope-1.26.0/dashscope/finetune/customize_types.py +193 -0
  94. dashscope-1.26.0/dashscope/finetune/deployments.py +185 -0
  95. dashscope-1.26.0/dashscope/finetune/finetunes.py +291 -0
  96. dashscope-1.26.0/dashscope/finetune/reinforcement/__init__.py +253 -0
  97. dashscope-1.26.0/dashscope/finetune/reinforcement/common/constants.py +136 -0
  98. dashscope-1.26.0/dashscope/finetune/reinforcement/common/errors.py +313 -0
  99. dashscope-1.26.0/dashscope/finetune/reinforcement/common/log.py +34 -0
  100. dashscope-1.26.0/dashscope/finetune/reinforcement/common/model.py +1602 -0
  101. dashscope-1.26.0/dashscope/finetune/reinforcement/common/model_types.py +111 -0
  102. dashscope-1.26.0/dashscope/finetune/reinforcement/common/utils.py +1049 -0
  103. dashscope-1.26.0/dashscope/finetune/reinforcement/component/__init__.py +116 -0
  104. dashscope-1.26.0/dashscope/finetune/reinforcement/component/data/__init__.py +64 -0
  105. dashscope-1.26.0/dashscope/finetune/reinforcement/component/data/base_data_model.py +221 -0
  106. dashscope-1.26.0/dashscope/finetune/reinforcement/component/data/group_reward_input.py +53 -0
  107. dashscope-1.26.0/dashscope/finetune/reinforcement/component/data/group_reward_output.py +57 -0
  108. dashscope-1.26.0/dashscope/finetune/reinforcement/component/data/reward_input.py +53 -0
  109. dashscope-1.26.0/dashscope/finetune/reinforcement/component/data/reward_output.py +60 -0
  110. dashscope-1.26.0/dashscope/finetune/reinforcement/component/data/rollout_input.py +78 -0
  111. dashscope-1.26.0/dashscope/finetune/reinforcement/component/data/rollout_output.py +45 -0
  112. dashscope-1.26.0/dashscope/finetune/reinforcement/component/demo/__init__.py +19 -0
  113. dashscope-1.26.0/dashscope/finetune/reinforcement/component/demo/group_reward_processor_demo.py +113 -0
  114. dashscope-1.26.0/dashscope/finetune/reinforcement/component/demo/reward_processor_demo.py +97 -0
  115. dashscope-1.26.0/dashscope/finetune/reinforcement/component/demo/rollout_processor_demo.py +96 -0
  116. dashscope-1.26.0/dashscope/finetune/reinforcement/component/func_decorator.py +226 -0
  117. dashscope-1.26.0/dashscope/finetune/reinforcement/component/func_manager.py +338 -0
  118. dashscope-1.26.0/dashscope/finetune/reinforcement/component/observability/__init__.py +122 -0
  119. dashscope-1.26.0/dashscope/finetune/reinforcement/component/observability/genai/__init__.py +146 -0
  120. dashscope-1.26.0/dashscope/finetune/reinforcement/component/observability/genai/_core.py +498 -0
  121. dashscope-1.26.0/dashscope/finetune/reinforcement/component/observability/genai/llm_dashscope.py +190 -0
  122. dashscope-1.26.0/dashscope/finetune/reinforcement/component/observability/genai/llm_openai.py +620 -0
  123. dashscope-1.26.0/dashscope/finetune/reinforcement/component/observability/genai/llm_span.py +237 -0
  124. dashscope-1.26.0/dashscope/finetune/reinforcement/component/observability/genai/messages.py +587 -0
  125. dashscope-1.26.0/dashscope/finetune/reinforcement/component/observability/genai/tools.py +1026 -0
  126. dashscope-1.26.0/dashscope/finetune/reinforcement/component/observability/processor_span.py +326 -0
  127. dashscope-1.26.0/dashscope/finetune/reinforcement/component/observability/tracing.py +823 -0
  128. dashscope-1.26.0/dashscope/finetune/reinforcement/component/parser/__init__.py +20 -0
  129. dashscope-1.26.0/dashscope/finetune/reinforcement/component/parser/base_parser.py +35 -0
  130. dashscope-1.26.0/dashscope/finetune/reinforcement/component/parser/group_reward_parser.py +41 -0
  131. dashscope-1.26.0/dashscope/finetune/reinforcement/component/parser/reward_parser.py +41 -0
  132. dashscope-1.26.0/dashscope/finetune/reinforcement/component/parser/rollout_parser.py +41 -0
  133. dashscope-1.26.0/dashscope/finetune/reinforcement/component/processor/__init__.py +20 -0
  134. dashscope-1.26.0/dashscope/finetune/reinforcement/component/processor/abstract_group_reward_processor.py +83 -0
  135. dashscope-1.26.0/dashscope/finetune/reinforcement/component/processor/abstract_processor.py +54 -0
  136. dashscope-1.26.0/dashscope/finetune/reinforcement/component/processor/abstract_reward_processor.py +201 -0
  137. dashscope-1.26.0/dashscope/finetune/reinforcement/component/processor/abstract_rollout_processor.py +78 -0
  138. dashscope-1.26.0/dashscope/finetune/reinforcement/component/server/__init__.py +0 -0
  139. dashscope-1.26.0/dashscope/finetune/reinforcement/component/server/server.py +631 -0
  140. dashscope-1.26.0/dashscope/io/__init__.py +0 -0
  141. dashscope-1.26.0/dashscope/io/input_output.py +132 -0
  142. dashscope-1.26.0/dashscope/model.py +62 -0
  143. dashscope-1.26.0/dashscope/models.py +77 -0
  144. dashscope-1.26.0/dashscope/multimodal/__init__.py +95 -0
  145. dashscope-1.26.0/dashscope/multimodal/dialog_state.py +59 -0
  146. dashscope-1.26.0/dashscope/multimodal/multimodal_constants.py +36 -0
  147. dashscope-1.26.0/dashscope/multimodal/multimodal_dialog.py +798 -0
  148. dashscope-1.26.0/dashscope/multimodal/multimodal_request_params.py +336 -0
  149. dashscope-1.26.0/dashscope/multimodal/tingwu/__init__.py +11 -0
  150. dashscope-1.26.0/dashscope/multimodal/tingwu/tingwu.py +84 -0
  151. dashscope-1.26.0/dashscope/multimodal/tingwu/tingwu_realtime.py +637 -0
  152. dashscope-1.26.0/dashscope/nlp/__init__.py +0 -0
  153. dashscope-1.26.0/dashscope/nlp/understanding.py +89 -0
  154. dashscope-1.26.0/dashscope/protocol/__init__.py +0 -0
  155. dashscope-1.26.0/dashscope/protocol/websocket.py +31 -0
  156. dashscope-1.26.0/dashscope/rerank/__init__.py +6 -0
  157. dashscope-1.26.0/dashscope/rerank/text_rerank.py +177 -0
  158. dashscope-1.26.0/dashscope/resources/qwen.tiktoken +151643 -0
  159. dashscope-1.26.0/dashscope/threads/__init__.py +29 -0
  160. dashscope-1.26.0/dashscope/threads/messages/__init__.py +0 -0
  161. dashscope-1.26.0/dashscope/threads/messages/files.py +127 -0
  162. dashscope-1.26.0/dashscope/threads/messages/messages.py +260 -0
  163. dashscope-1.26.0/dashscope/threads/runs/__init__.py +0 -0
  164. dashscope-1.26.0/dashscope/threads/runs/runs.py +582 -0
  165. dashscope-1.26.0/dashscope/threads/runs/steps.py +126 -0
  166. dashscope-1.26.0/dashscope/threads/thread_types.py +708 -0
  167. dashscope-1.26.0/dashscope/threads/threads.py +258 -0
  168. dashscope-1.26.0/dashscope/tokenizers/__init__.py +13 -0
  169. dashscope-1.26.0/dashscope/tokenizers/qwen_tokenizer.py +167 -0
  170. dashscope-1.26.0/dashscope/tokenizers/tokenization.py +147 -0
  171. dashscope-1.26.0/dashscope/tokenizers/tokenizer.py +49 -0
  172. dashscope-1.26.0/dashscope/tokenizers/tokenizer_base.py +31 -0
  173. dashscope-1.26.0/dashscope/utils/__init__.py +0 -0
  174. dashscope-1.26.0/dashscope/utils/message_utils.py +1235 -0
  175. dashscope-1.26.0/dashscope/utils/oss_utils.py +305 -0
  176. dashscope-1.26.0/dashscope/utils/param_utils.py +31 -0
  177. dashscope-1.26.0/dashscope/version.py +4 -0
  178. dashscope-1.26.0/dashscope.egg-info/PKG-INFO +564 -0
  179. dashscope-1.26.0/dashscope.egg-info/SOURCES.txt +191 -0
  180. dashscope-1.26.0/dashscope.egg-info/requires.txt +10 -0
  181. dashscope-1.26.0/requirements.txt +7 -0
  182. dashscope-1.26.0/setup.cfg +11 -0
  183. dashscope-1.26.0/setup.py +73 -0
  184. dashscope-1.0.2/PKG-INFO +0 -243
  185. dashscope-1.0.2/README.md +0 -220
  186. dashscope-1.0.2/dashscope/__init__.py +0 -21
  187. dashscope-1.0.2/dashscope/aigc/__init__.py +0 -5
  188. dashscope-1.0.2/dashscope/aigc/conversation.py +0 -220
  189. dashscope-1.0.2/dashscope/aigc/generation.py +0 -91
  190. dashscope-1.0.2/dashscope/api_entities/aiohttp_request.py +0 -242
  191. dashscope-1.0.2/dashscope/api_entities/api_request_factory.py +0 -87
  192. dashscope-1.0.2/dashscope/api_entities/base_request.py +0 -25
  193. dashscope-1.0.2/dashscope/api_entities/dashscope_response.py +0 -187
  194. dashscope-1.0.2/dashscope/api_entities/http_request.py +0 -216
  195. dashscope-1.0.2/dashscope/audio/__init__.py +0 -3
  196. dashscope-1.0.2/dashscope/audio/asr/__init__.py +0 -5
  197. dashscope-1.0.2/dashscope/audio/asr/transcription.py +0 -138
  198. dashscope-1.0.2/dashscope/cli.py +0 -335
  199. dashscope-1.0.2/dashscope/client/base_api.py +0 -541
  200. dashscope-1.0.2/dashscope/common/api_key.py +0 -43
  201. dashscope-1.0.2/dashscope/common/constants.py +0 -86
  202. dashscope-1.0.2/dashscope/common/env.py +0 -21
  203. dashscope-1.0.2/dashscope/common/error.py +0 -100
  204. dashscope-1.0.2/dashscope/common/utils.py +0 -107
  205. dashscope-1.0.2/dashscope/deployment.py +0 -98
  206. dashscope-1.0.2/dashscope/file.py +0 -103
  207. dashscope-1.0.2/dashscope/finetune.py +0 -136
  208. dashscope-1.0.2/dashscope/io/input_output.py +0 -82
  209. dashscope-1.0.2/dashscope/model.py +0 -52
  210. dashscope-1.0.2/dashscope/protocol/websocket.py +0 -27
  211. dashscope-1.0.2/dashscope/version.py +0 -1
  212. dashscope-1.0.2/dashscope.egg-info/PKG-INFO +0 -243
  213. dashscope-1.0.2/dashscope.egg-info/SOURCES.txt +0 -45
  214. dashscope-1.0.2/dashscope.egg-info/requires.txt +0 -2
  215. dashscope-1.0.2/setup.cfg +0 -6
  216. dashscope-1.0.2/setup.py +0 -76
  217. {dashscope-1.0.2 → dashscope-1.26.0}/dashscope/api_entities/__init__.py +0 -0
  218. {dashscope-1.0.2 → dashscope-1.26.0}/dashscope/client/__init__.py +0 -0
  219. {dashscope-1.0.2 → dashscope-1.26.0}/dashscope/common/__init__.py +0 -0
  220. {dashscope-1.0.2/dashscope/io → dashscope-1.26.0/dashscope/finetune}/__init__.py +0 -0
  221. {dashscope-1.0.2/dashscope/protocol → dashscope-1.26.0/dashscope/finetune/reinforcement/common}/__init__.py +0 -0
  222. {dashscope-1.0.2 → dashscope-1.26.0}/dashscope.egg-info/dependency_links.txt +0 -0
  223. {dashscope-1.0.2 → dashscope-1.26.0}/dashscope.egg-info/entry_points.txt +0 -0
  224. {dashscope-1.0.2 → dashscope-1.26.0}/dashscope.egg-info/not-zip-safe +0 -0
  225. {dashscope-1.0.2 → dashscope-1.26.0}/dashscope.egg-info/top_level.txt +0 -0
@@ -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.
@@ -0,0 +1,4 @@
1
+ include requirements.txt
2
+ include dashscope/resources/qwen.tiktoken
3
+ exclude .acli/*
4
+ recursive-exclude .acli *
@@ -0,0 +1,564 @@
1
+ Metadata-Version: 2.4
2
+ Name: dashscope
3
+ Version: 1.26.0
4
+ Summary: dashscope client sdk library
5
+ Home-page: https://dashscope.aliyun.com/
6
+ Author: Alibaba Cloud
7
+ Author-email: dashscope@alibabacloud.com
8
+ License: Apache 2.0
9
+ Platform: Posix; MacOS X; Windows
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Requires-Python: >=3.8.0
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: aiohttp
23
+ Requires-Dist: requests
24
+ Requires-Dist: websocket-client
25
+ Requires-Dist: cryptography
26
+ Requires-Dist: certifi
27
+ Requires-Dist: typer>=0.9.0
28
+ Requires-Dist: rich>=13.0.0
29
+ Provides-Extra: tokenizer
30
+ Requires-Dist: tiktoken; extra == "tokenizer"
31
+ Dynamic: author
32
+ Dynamic: author-email
33
+ Dynamic: classifier
34
+ Dynamic: description
35
+ Dynamic: description-content-type
36
+ Dynamic: home-page
37
+ Dynamic: license
38
+ Dynamic: license-file
39
+ Dynamic: platform
40
+ Dynamic: provides-extra
41
+ Dynamic: requires-dist
42
+ Dynamic: requires-python
43
+ Dynamic: summary
44
+
45
+ # DashScope Python SDK
46
+
47
+ The DashScope Python SDK provides a comprehensive interface to [Alibaba Cloud Model Studio (Bailian)](https://www.alibabacloud.com/help/en/model-studio/) APIs, covering text generation, multi-modal understanding, embeddings, reranking, image/video generation, speech synthesis & recognition, and more.
48
+
49
+ ## Installation
50
+ To install the DashScope Python SDK, simply run:
51
+ ```shell
52
+ pip install dashscope
53
+ ```
54
+
55
+ If you clone the code from github, you can install from source by running:
56
+ ```shell
57
+ pip install -e .
58
+ ```
59
+
60
+ To use tokenizer in local mode without downloading any files, run:
61
+ ```shell
62
+ pip install dashscope[tokenizer]
63
+ ```
64
+
65
+
66
+ ## Quick Start
67
+
68
+ ```python
69
+ from http import HTTPStatus
70
+ from dashscope import Generation
71
+
72
+ responses = Generation.call(
73
+ model="qwen-plus",
74
+ messages=[
75
+ {"role": "system", "content": "You are a helpful assistant."},
76
+ {"role": "user", "content": "Who are you?"},
77
+ ],
78
+ result_format="message",
79
+ )
80
+
81
+ if responses.status_code == HTTPStatus.OK:
82
+ print(responses.output.choices[0].message.content)
83
+ else:
84
+ print(f"Error: {responses.code} - {responses.message}")
85
+ ```
86
+
87
+ ## API Key Authentication
88
+
89
+ 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.
90
+
91
+ ### Using the API Key
92
+
93
+ 1. Set the API key via code
94
+ ```python
95
+ import dashscope
96
+
97
+ dashscope.api_key = 'YOUR-DASHSCOPE-API-KEY'
98
+ # Or specify the API key file path via code
99
+ # dashscope.api_key_file_path='~/.dashscope/api_key'
100
+
101
+ ```
102
+
103
+ 2. Set the API key via environment variables
104
+
105
+ a. Set the API key directly using the environment variable below
106
+
107
+ ```shell
108
+ export DASHSCOPE_API_KEY='YOUR-DASHSCOPE-API-KEY'
109
+ ```
110
+
111
+ b. Specify the API key file path via an environment variable
112
+
113
+ ```shell
114
+ export DASHSCOPE_API_KEY_FILE_PATH='~/.dashscope/api_key'
115
+ ```
116
+
117
+ 3. Save the API key to a file
118
+ ```python
119
+ from dashscope import save_api_key
120
+
121
+ save_api_key(api_key='YOUR-DASHSCOPE-API-KEY',
122
+ api_key_file_path='api_key_file_location or (None, will save to default location "~/.dashscope/api_key"')
123
+
124
+ ```
125
+
126
+ ## Supported Models
127
+
128
+ | Category | Recommended Models | SDK Class |
129
+ |----------|-------------------|-----------|
130
+ | Text Generation | qwen3.7-max, qwen3.7-plus, qwen3.6-flash | `Generation` |
131
+ | Multi-Modal Understanding | qwen3.5-omni-plus, qwen3.7-plus (vision) | `MultiModalConversation` |
132
+ | Text Embedding | text-embedding-v4, text-embedding-v3 | `TextEmbedding` |
133
+ | Multi-Modal Embedding | tongyi-embedding-vision-plus, qwen3-vl-embedding | `MultiModalEmbedding` |
134
+ | Text ReRank | qwen3-rerank, gte-rerank-v2 | `TextReRank` |
135
+ | Image Generation | wan2.7-image-pro, qwen-image-2.0-pro | `ImageSynthesis` |
136
+ | Video Generation | wan2.7-t2v, wan2.7-i2v, happyhorse-1.0-t2v/i2v | `VideoSynthesis` |
137
+ | Speech Synthesis (TTS) | cosyvoice-v3.5-plus, cosyvoice-v1 | `SpeechSynthesizer`, `HttpSpeechSynthesizer` |
138
+ | Speech Recognition (ASR) | fun-asr-realtime, fun-asr, paraformer-v1 | `Transcription` |
139
+ | Omni (Real-time) | qwen3.5-omni-plus-realtime | `MultiModalConversation` |
140
+
141
+ For the latest model list, visit [Bailian Model Plaza](https://bailian.console.aliyun.com/).
142
+
143
+ ## SDK Features
144
+
145
+ ### Text Generation
146
+
147
+ Synchronous call with messages:
148
+
149
+ ```python
150
+ from http import HTTPStatus
151
+ from dashscope import Generation
152
+
153
+ response = Generation.call(
154
+ model="qwen-plus",
155
+ messages=[{"role": "user", "content": "Tell me a joke"}],
156
+ result_format="message",
157
+ )
158
+ ```
159
+
160
+ Streaming:
161
+
162
+ ```python
163
+ responses = Generation.call(
164
+ model="qwen-plus",
165
+ messages=[{"role": "user", "content": "Write a short poem"}],
166
+ result_format="message",
167
+ stream=True,
168
+ )
169
+ for response in responses:
170
+ if response.status_code == HTTPStatus.OK:
171
+ print(response.output.choices[0].message.content, end="")
172
+ ```
173
+
174
+ Async (non-blocking):
175
+
176
+ ```python
177
+ from dashscope import AioGeneration
178
+
179
+ response = await AioGeneration.call(
180
+ model="qwen-plus",
181
+ messages=[{"role": "user", "content": "Hello"}],
182
+ result_format="message",
183
+ )
184
+ ```
185
+
186
+ Key parameters: `stream`, `temperature`, `top_p`, `top_k`, `max_tokens`, `seed`, `stop`, `repetition_penalty`, `tools`, `tool_choice`, `enable_thinking`.
187
+
188
+ ### Multi-Modal Conversation
189
+
190
+ Vision (image + text), video, and audio understanding:
191
+
192
+ ```python
193
+ from dashscope import MultiModalConversation
194
+
195
+ response = MultiModalConversation.call(
196
+ model="qwen-vl-max",
197
+ messages=[{
198
+ "role": "user",
199
+ "content": [
200
+ {"image": "https://example.com/image.jpg"},
201
+ {"text": "What is in this image?"},
202
+ ],
203
+ }],
204
+ )
205
+ ```
206
+
207
+ ### Text Embedding
208
+
209
+ ```python
210
+ from dashscope import TextEmbedding
211
+
212
+ response = TextEmbedding.call(
213
+ model="text-embedding-v3",
214
+ input="Hello world",
215
+ dimension=1024,
216
+ text_type="document",
217
+ )
218
+ ```
219
+
220
+ Parameters: `text_type` ("query" / "document"), `dimension`, `output_type` ("dense" / "sparse" / "dense&sparse"), `instruct`.
221
+
222
+ ### Multi-Modal Embedding
223
+
224
+ ```python
225
+ from dashscope import (
226
+ MultiModalEmbedding,
227
+ MultiModalEmbeddingItemImage,
228
+ MultiModalEmbeddingItemText,
229
+ )
230
+
231
+ response = MultiModalEmbedding.call(
232
+ model="multimodal-embedding-v1",
233
+ input=[
234
+ MultiModalEmbeddingItemImage("https://example.com/image.jpg", factor=1),
235
+ MultiModalEmbeddingItemText("a cat", factor=1),
236
+ ],
237
+ )
238
+ ```
239
+
240
+ ### Batch Text Embedding
241
+
242
+ ```python
243
+ from dashscope import BatchTextEmbedding
244
+
245
+ # Sync: submit and wait for result
246
+ result = BatchTextEmbedding.call(
247
+ model="text-embedding-async-v2",
248
+ url="https://your-file-url/texts.txt",
249
+ )
250
+
251
+ # Or async: submit task, then poll
252
+ task = BatchTextEmbedding.async_call(
253
+ model="text-embedding-async-v2",
254
+ url="https://your-file-url/texts.txt",
255
+ )
256
+ result = BatchTextEmbedding.wait(task)
257
+ ```
258
+
259
+ ### Text ReRank
260
+
261
+ ```python
262
+ from dashscope import TextReRank
263
+
264
+ response = TextReRank.call(
265
+ model="gte-rerank-v2",
266
+ query="What is deep learning?",
267
+ documents=[
268
+ "Deep learning is a subset of machine learning.",
269
+ "The weather is nice today.",
270
+ "Neural networks are the foundation of deep learning.",
271
+ ],
272
+ top_n=2,
273
+ return_documents=True,
274
+ )
275
+ ```
276
+
277
+ ### Image Generation
278
+
279
+ ```python
280
+ from dashscope import ImageSynthesis
281
+
282
+ # Async task pattern
283
+ response = ImageSynthesis.async_call(
284
+ model="wanx-v1",
285
+ prompt="A serene mountain landscape at sunset",
286
+ )
287
+
288
+ # Wait for result
289
+ result = ImageSynthesis.wait(response)
290
+
291
+ # Sync call (for wan2.2-t2i-flash/plus)
292
+ result = ImageSynthesis.sync_call(
293
+ model="wan2.2-t2i-flash",
294
+ prompt="A serene mountain landscape at sunset",
295
+ )
296
+ ```
297
+
298
+ ### Video Generation
299
+
300
+ ```python
301
+ from dashscope import VideoSynthesis
302
+
303
+ # Text-to-video
304
+ response = VideoSynthesis.async_call(
305
+ model="wan2.7-t2v",
306
+ prompt="A cat playing with a ball of yarn",
307
+ )
308
+
309
+ result = VideoSynthesis.wait(response)
310
+ ```
311
+
312
+ ### Speech Synthesis (TTS)
313
+
314
+ WebSocket streaming (real-time):
315
+
316
+ ```python
317
+ from dashscope.audio.tts_v2 import SpeechSynthesizer
318
+
319
+ synthesizer = SpeechSynthesizer(model="cosyvoice-v1", voice="longxiaochun")
320
+ audio = synthesizer.call("Hello, welcome to DashScope!")
321
+ ```
322
+
323
+ HTTP (one-shot):
324
+
325
+ ```python
326
+ from dashscope import HttpSpeechSynthesizer
327
+
328
+ result = HttpSpeechSynthesizer.call(
329
+ model="cosyvoice-v3-flash",
330
+ text="Hello, welcome to DashScope!",
331
+ voice="longxiaochun",
332
+ )
333
+ ```
334
+
335
+ ### Speech Recognition (ASR)
336
+
337
+ File transcription:
338
+
339
+ ```python
340
+ from dashscope.audio.asr import Transcription
341
+
342
+ # Submit transcription task
343
+ response = Transcription.async_call(
344
+ model="paraformer-v1",
345
+ file_urls=["https://example.com/audio.wav"],
346
+ )
347
+
348
+ # Wait for result
349
+ result = Transcription.wait(response)
350
+ ```
351
+
352
+ ### Tokenization
353
+
354
+ ```python
355
+ from dashscope import Tokenization
356
+
357
+ response = Tokenization.call(model="qwen-turbo", prompt="Hello world")
358
+ print(response.usage)
359
+ ```
360
+
361
+ Local tokenizer (requires `pip install dashscope[tokenizer]`):
362
+
363
+ ```python
364
+ from dashscope import get_tokenizer
365
+
366
+ tokenizer = get_tokenizer("qwen-turbo")
367
+ tokens = tokenizer.encode("Hello world")
368
+ ```
369
+
370
+ ### Application
371
+
372
+ Call a Bailian application:
373
+
374
+ ```python
375
+ from dashscope import Application
376
+
377
+ response = Application.call(app_id="YOUR_APP_ID", prompt="Hello")
378
+ ```
379
+
380
+ ### Fine-tuning
381
+
382
+ ```python
383
+ from dashscope import FineTunes
384
+
385
+ # Create a fine-tuning job
386
+ response = FineTunes.call(
387
+ model="qwen-turbo",
388
+ training_file_ids=["file-xxx"],
389
+ hyper_parameters={"n_epochs": 3},
390
+ )
391
+
392
+ # Check status
393
+ status = FineTunes.get("ft-xxx")
394
+ ```
395
+
396
+ ### Deployments
397
+
398
+ ```python
399
+ from dashscope import Deployments
400
+
401
+ # Deploy a fine-tuned model
402
+ response = Deployments.call(model="your-finetuned-model", capacity=1)
403
+
404
+ # List / get / scale / delete
405
+ deployments = Deployments.list()
406
+ info = Deployments.get("deployed-model-name")
407
+ Deployments.scale("deployed-model-name", capacity=2)
408
+ Deployments.delete("deployed-model-name")
409
+ ```
410
+
411
+ ### Assistants & Threads (Beta)
412
+
413
+ ```python
414
+ from dashscope import Assistants, Threads, Messages, Runs
415
+
416
+ # Create an assistant
417
+ assistant = Assistants.create(
418
+ model="qwen-max",
419
+ name="Math Tutor",
420
+ instructions="You are a math tutor.",
421
+ )
422
+
423
+ # Create a thread and send a message
424
+ thread = Threads.create()
425
+ Messages.create(thread.id, content="What is 2+2?")
426
+
427
+ # Run the assistant and wait for completion
428
+ run = Runs.create(thread.id, assistant_id=assistant.id)
429
+ result = Runs.wait(run.id, thread_id=thread.id)
430
+ ```
431
+
432
+ ### OpenAI-Compatible Interface
433
+
434
+ ```python
435
+ from dashscope.aigc.chat_completion import Completions
436
+
437
+ response = Completions.create(
438
+ model="qwen-plus",
439
+ messages=[{"role": "user", "content": "Hello"}],
440
+ max_tokens=100,
441
+ )
442
+ ```
443
+
444
+ ## CLI Reference
445
+
446
+ The DashScope CLI is installed automatically with the SDK. All commands support `-k / --api-key` for authentication (or use the `DASHSCOPE_API_KEY` environment variable).
447
+
448
+ ### Text Generation
449
+
450
+ ```shell
451
+ dashscope generation create -m qwen-plus -p "Hello, who are you?"
452
+ dashscope generation create -m qwen-plus -p "Tell me a story" --stream
453
+ ```
454
+
455
+ ### File Management
456
+
457
+ ```shell
458
+ dashscope files upload --file training_data.jsonl --purpose fine-tune
459
+ dashscope files list
460
+ dashscope files get file-xxx
461
+ dashscope files delete file-xxx
462
+ ```
463
+
464
+ ### Fine-tuning
465
+
466
+ ```shell
467
+ # Create a fine-tuning job
468
+ dashscope ft create -m qwen-turbo -t file-xxx
469
+
470
+ # List jobs
471
+ dashscope ft list
472
+
473
+ # Get job status
474
+ dashscope ft get ft-xxx
475
+
476
+ # Stream training events
477
+ dashscope ft stream ft-xxx
478
+
479
+ # Cancel / delete a job
480
+ dashscope ft cancel ft-xxx
481
+ dashscope ft delete ft-xxx
482
+ ```
483
+
484
+ ### Deployments
485
+
486
+ ```shell
487
+ dashscope deployments create -m your-finetuned-model --capacity 1
488
+ dashscope deployments list
489
+ dashscope deployments get dm-xxx
490
+ dashscope deployments scale dm-xxx --capacity 2
491
+ dashscope deployments delete dm-xxx
492
+ ```
493
+
494
+ ### OSS Upload
495
+
496
+ ```shell
497
+ dashscope oss upload -m qwen-plus --file data.jsonl
498
+ ```
499
+
500
+ ### Agentic RL (Reinforcement Learning)
501
+
502
+ ```shell
503
+ # Register reward/rollout functions
504
+ dashscope rl register_functions \
505
+ --rollout-classpaths rollout.py:MyRollout \
506
+ --reward-classpaths reward.py:MyReward
507
+
508
+ # Test registered functions
509
+ dashscope rl test_functions instance-xxx --type reward --input '{"key": "value"}'
510
+
511
+ # Upload training data
512
+ dashscope rl upload_data --training-files train.jsonl
513
+
514
+ # Run RL training workflow
515
+ dashscope rl run -c config.yaml
516
+
517
+ # Monitor jobs
518
+ dashscope rl list
519
+ dashscope rl get job-xxx
520
+ dashscope rl logs job-xxx
521
+ dashscope rl cancel job-xxx
522
+ ```
523
+
524
+ ### Legacy Command Support
525
+
526
+ The CLI supports legacy argparse-style commands for backward compatibility:
527
+
528
+ ```shell
529
+ # Legacy format (still works)
530
+ dashscope fine_tunes.call --training_file_ids file-xxx
531
+
532
+ # New format (recommended)
533
+ dashscope ft create --training-file-ids file-xxx
534
+ ```
535
+
536
+ ## Logging
537
+ To output Dashscope logs, you need to configure the logger.
538
+ ```shell
539
+ export DASHSCOPE_LOGGING_LEVEL='info'
540
+
541
+ ```
542
+
543
+ ## Output
544
+ The output contains the following fields:
545
+ ```
546
+ request_id (str): The request id.
547
+ status_code (int): HTTP status code, 200 indicates that the
548
+ request was successful, others indicate an error.
549
+ code (str): Error code if error occurs, otherwise empty str.
550
+ message (str): Set to error message on error.
551
+ output (Any): The request output.
552
+ usage (Any): The request usage information.
553
+ ```
554
+
555
+ ## Error Handling
556
+ Currently, errors are thrown as exceptions.
557
+
558
+
559
+ ## Contributing
560
+ Coming soon.
561
+
562
+
563
+ ## License
564
+ This project is licensed under the Apache License (Version 2.0).