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

Files changed (84) hide show
  1. dashscope/__init__.py +3 -1
  2. dashscope/aigc/__init__.py +2 -0
  3. dashscope/aigc/chat_completion.py +15 -4
  4. dashscope/aigc/code_generation.py +2 -0
  5. dashscope/aigc/conversation.py +2 -0
  6. dashscope/aigc/generation.py +2 -0
  7. dashscope/aigc/image_synthesis.py +2 -0
  8. dashscope/aigc/multimodal_conversation.py +8 -4
  9. dashscope/aigc/video_synthesis.py +2 -0
  10. dashscope/api_entities/aiohttp_request.py +3 -0
  11. dashscope/api_entities/api_request_data.py +3 -0
  12. dashscope/api_entities/api_request_factory.py +2 -0
  13. dashscope/api_entities/base_request.py +2 -0
  14. dashscope/api_entities/chat_completion_types.py +58 -63
  15. dashscope/api_entities/dashscope_response.py +74 -2
  16. dashscope/api_entities/http_request.py +3 -0
  17. dashscope/api_entities/websocket_request.py +3 -2
  18. dashscope/app/__init__.py +2 -0
  19. dashscope/app/application.py +17 -15
  20. dashscope/app/application_response.py +1 -1
  21. dashscope/assistants/__init__.py +2 -0
  22. dashscope/assistants/assistant_types.py +2 -0
  23. dashscope/assistants/assistants.py +2 -0
  24. dashscope/assistants/files.py +2 -0
  25. dashscope/audio/__init__.py +4 -2
  26. dashscope/audio/asr/__init__.py +2 -0
  27. dashscope/audio/asr/asr_phrase_manager.py +2 -0
  28. dashscope/audio/asr/recognition.py +2 -0
  29. dashscope/audio/asr/transcription.py +3 -0
  30. dashscope/audio/asr/translation_recognizer.py +2 -0
  31. dashscope/audio/asr/vocabulary.py +3 -0
  32. dashscope/audio/qwen_tts/__init__.py +5 -0
  33. dashscope/audio/qwen_tts/speech_synthesizer.py +77 -0
  34. dashscope/audio/tts/__init__.py +2 -0
  35. dashscope/audio/tts/speech_synthesizer.py +2 -0
  36. dashscope/audio/tts_v2/__init__.py +2 -0
  37. dashscope/audio/tts_v2/enrollment.py +3 -0
  38. dashscope/audio/tts_v2/speech_synthesizer.py +4 -1
  39. dashscope/client/base_api.py +4 -1
  40. dashscope/common/api_key.py +2 -0
  41. dashscope/common/base_type.py +2 -0
  42. dashscope/common/constants.py +2 -0
  43. dashscope/common/env.py +2 -0
  44. dashscope/common/error.py +3 -0
  45. dashscope/common/logging.py +2 -0
  46. dashscope/common/message_manager.py +2 -0
  47. dashscope/common/utils.py +3 -0
  48. dashscope/customize/customize_types.py +2 -0
  49. dashscope/customize/deployments.py +2 -0
  50. dashscope/customize/finetunes.py +2 -0
  51. dashscope/embeddings/__init__.py +2 -0
  52. dashscope/embeddings/batch_text_embedding.py +2 -0
  53. dashscope/embeddings/batch_text_embedding_response.py +3 -0
  54. dashscope/embeddings/multimodal_embedding.py +6 -3
  55. dashscope/embeddings/text_embedding.py +2 -0
  56. dashscope/files.py +2 -0
  57. dashscope/io/input_output.py +2 -0
  58. dashscope/model.py +2 -0
  59. dashscope/models.py +2 -0
  60. dashscope/nlp/understanding.py +2 -0
  61. dashscope/protocol/websocket.py +3 -0
  62. dashscope/rerank/text_rerank.py +2 -0
  63. dashscope/threads/__init__.py +2 -0
  64. dashscope/threads/messages/files.py +2 -0
  65. dashscope/threads/messages/messages.py +2 -0
  66. dashscope/threads/runs/runs.py +2 -0
  67. dashscope/threads/runs/steps.py +2 -0
  68. dashscope/threads/thread_types.py +2 -0
  69. dashscope/threads/threads.py +2 -0
  70. dashscope/tokenizers/__init__.py +2 -0
  71. dashscope/tokenizers/qwen_tokenizer.py +2 -0
  72. dashscope/tokenizers/tokenization.py +2 -0
  73. dashscope/tokenizers/tokenizer.py +2 -0
  74. dashscope/tokenizers/tokenizer_base.py +2 -0
  75. dashscope/utils/oss_utils.py +3 -0
  76. dashscope/version.py +3 -1
  77. {dashscope-1.22.1.dist-info → dashscope-1.23.0.dist-info}/LICENSE +2 -4
  78. {dashscope-1.22.1.dist-info → dashscope-1.23.0.dist-info}/METADATA +4 -3
  79. dashscope-1.23.0.dist-info/RECORD +95 -0
  80. {dashscope-1.22.1.dist-info → dashscope-1.23.0.dist-info}/entry_points.txt +1 -0
  81. dashscope/utils/temporary_storage.py +0 -160
  82. dashscope-1.22.1.dist-info/RECORD +0 -94
  83. {dashscope-1.22.1.dist-info → dashscope-1.23.0.dist-info}/WHEEL +0 -0
  84. {dashscope-1.22.1.dist-info → dashscope-1.23.0.dist-info}/top_level.txt +0 -0
dashscope/__init__.py CHANGED
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  import logging
2
4
  from logging import NullHandler
3
5
 
@@ -5,8 +7,8 @@ from dashscope.aigc.code_generation import CodeGeneration
5
7
  from dashscope.aigc.conversation import Conversation, History, HistoryItem
6
8
  from dashscope.aigc.generation import AioGeneration, Generation
7
9
  from dashscope.aigc.image_synthesis import ImageSynthesis
8
- from dashscope.aigc.video_synthesis import VideoSynthesis
9
10
  from dashscope.aigc.multimodal_conversation import MultiModalConversation
11
+ from dashscope.aigc.video_synthesis import VideoSynthesis
10
12
  from dashscope.app.application import Application
11
13
  from dashscope.assistants import Assistant, AssistantList, Assistants
12
14
  from dashscope.assistants.assistant_types import AssistantFile, DeleteResponse
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  from .conversation import Conversation, History, HistoryItem
2
4
  from .generation import Generation
3
5
  from .image_synthesis import ImageSynthesis
@@ -1,14 +1,17 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  import json
2
4
  from typing import Any, Dict, Generator, List, Union
3
5
 
4
6
  import dashscope
7
+ from dashscope.aigc.generation import Generation
8
+ from dashscope.api_entities.chat_completion_types import (ChatCompletion,
9
+ ChatCompletionChunk)
5
10
  from dashscope.api_entities.dashscope_response import (GenerationResponse,
6
11
  Message)
7
12
  from dashscope.client.base_api import BaseAioApi, CreateMixin
8
- from dashscope.common import constants
9
13
  from dashscope.common.error import InputRequired, ModelRequired
10
14
  from dashscope.common.utils import _get_task_group_and_task
11
- from dashscope.api_entities.chat_completion_types import ChatCompletion, ChatCompletionChunk
12
15
 
13
16
 
14
17
  class Completions(CreateMixin):
@@ -16,6 +19,7 @@ class Completions(CreateMixin):
16
19
 
17
20
  """
18
21
  SUB_PATH = ''
22
+
19
23
  @classmethod
20
24
  def create(
21
25
  cls,
@@ -115,9 +119,16 @@ class Completions(CreateMixin):
115
119
  data['repetition_penalty'] = repetition_penalty
116
120
  if extra_body is not None and extra_body:
117
121
  data = {**data, **extra_body}
118
-
122
+
119
123
  if extra_headers is not None and extra_headers:
120
- kwargs = {'headers': extra_headers} if kwargs else {**kwargs, **{'headers': extra_headers}}
124
+ kwargs = {
125
+ 'headers': extra_headers
126
+ } if kwargs else {
127
+ **kwargs,
128
+ **{
129
+ 'headers': extra_headers
130
+ }
131
+ }
121
132
 
122
133
  response = super().call(data=data,
123
134
  path='chat/completions',
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  from typing import Generator, List, Union
2
4
 
3
5
  from dashscope.api_entities.dashscope_response import (DashScopeAPIResponse,
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  import json
2
4
  from copy import deepcopy
3
5
  from http import HTTPStatus
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  import copy
2
4
  import json
3
5
  from typing import Any, Dict, Generator, List, Union
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  from typing import Any, Dict, List, Union
2
4
 
3
5
  from dashscope.api_entities.dashscope_response import (DashScopeAPIResponse,
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  import copy
2
4
  from typing import Generator, List, Union
3
5
 
@@ -121,8 +123,10 @@ class MultiModalConversation(BaseApi):
121
123
  for message in messages:
122
124
  content = message['content']
123
125
  for elem in content:
124
- is_upload = preprocess_message_element(model, elem, api_key)
125
- if is_upload and not has_upload:
126
- has_upload = True
127
-
126
+ if not isinstance(elem,
127
+ (int, float, bool, str, bytes, bytearray)):
128
+ is_upload = preprocess_message_element(
129
+ model, elem, api_key)
130
+ if is_upload and not has_upload:
131
+ has_upload = True
128
132
  return has_upload
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  from typing import Any, Dict, Union
2
4
 
3
5
  from dashscope.api_entities.dashscope_response import (DashScopeAPIResponse,
@@ -1,7 +1,10 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  import json
2
4
  from http import HTTPStatus
3
5
 
4
6
  import aiohttp
7
+
5
8
  from dashscope.api_entities.base_request import AioBaseRequest
6
9
  from dashscope.api_entities.dashscope_response import DashScopeAPIResponse
7
10
  from dashscope.common.constants import (DEFAULT_REQUEST_TIMEOUT_SECONDS,
@@ -1,7 +1,10 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  import json
2
4
  from urllib.parse import urlencode
3
5
 
4
6
  import aiohttp
7
+
5
8
  from dashscope.common.constants import ApiProtocol
6
9
  from dashscope.io.input_output import InputResolver
7
10
 
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  from urllib.parse import urlencode
2
4
 
3
5
  import dashscope
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  import os
2
4
  import platform
3
5
  from abc import ABC, abstractmethod
@@ -1,34 +1,11 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  # adapter from openai sdk
2
4
  from dataclasses import dataclass
3
- from typing import Dict, List, Literal, Optional
5
+ from typing import List, Literal, Optional
4
6
 
5
7
  from dashscope.common.base_type import BaseObjectMixin
6
- """
7
- {
8
- "choices": [
9
- {
10
- "message": {
11
- "role": "assistant",
12
- "content": "很抱歉,由于您提供的信息不完整,我无法直接比较两篇文章的内容。但是,一般而言,大型语言模型的训练通常确实涉及两个主要阶段:\n\n1. **预训练阶段 (Pre-Training Phase)**:在这个阶段,模型在大规模无标注文本数据集(如互联网上的网页、书籍、新闻等)上进行训练。目的是让模型学习语言的通用模式和结构。常见的预训练技术包括自回归(Autoregressive)模型如GPT系列,以及transformer架构下的编码器-解码器模型如BERT系列。\n\n2. **微调阶段 (Fine-Tuning Phase)**:预训练模型在特定任务的数据集上进行进一步训练,以适应下游任务,如问答、文本分类、机器翻译等。这个阶段允许模型根据具体任务的需求调整权重,从而提高性能。\n\n如果您能提供更详细的信息或两篇文章的具体内容,我可以给出更准确的比较分析。"
13
- },
14
- "finish_reason": "stop",
15
- "index": 0,
16
- "logprobs": null
17
- }
18
- ],
19
- "object": "chat.completion",
20
- "usage": {
21
- "prompt_tokens": 66,
22
- "completion_tokens": 195,
23
- "total_tokens": 261
24
- },
25
- "created": 1716539630,
26
- "system_fingerprint": null,
27
- "model": "qwen-long",
28
- "id": "chatcmpl-a737071790e091c6be016ea27a891392",
29
- "status_code": 200
30
- }
31
- """
8
+
32
9
 
33
10
  @dataclass(init=False)
34
11
  class CompletionUsage(BaseObjectMixin):
@@ -43,6 +20,7 @@ class CompletionUsage(BaseObjectMixin):
43
20
  def __init__(self, **kwargs):
44
21
  super().__init__(**kwargs)
45
22
 
23
+
46
24
  @dataclass(init=False)
47
25
  class TopLogprob(BaseObjectMixin):
48
26
  token: str
@@ -66,6 +44,7 @@ class TopLogprob(BaseObjectMixin):
66
44
  def __init__(self, **kwargs):
67
45
  super().__init__(**kwargs)
68
46
 
47
+
69
48
  @dataclass(init=False)
70
49
  class ChatCompletionTokenLogprob(BaseObjectMixin):
71
50
  token: str
@@ -95,32 +74,35 @@ class ChatCompletionTokenLogprob(BaseObjectMixin):
95
74
  returned.
96
75
  """
97
76
  def __init__(self, **kwargs):
98
- if 'top_logprobs' in kwargs and kwargs['top_logprobs'] is not None and kwargs['top_logprobs']:
77
+ if 'top_logprobs' in kwargs and kwargs[
78
+ 'top_logprobs'] is not None and kwargs['top_logprobs']:
99
79
  top_logprobs = []
100
80
  for logprob in kwargs['top_logprobs']:
101
81
  top_logprobs.append(ChatCompletionTokenLogprob(**logprob))
102
82
  self.top_logprobs = top_logprobs
103
83
  else:
104
84
  self.top_logprobs = None
105
-
85
+
106
86
  super().__init__(**kwargs)
107
-
108
-
87
+
88
+
109
89
  @dataclass(init=False)
110
90
  class ChoiceLogprobs(BaseObjectMixin):
111
91
  content: Optional[List[ChatCompletionTokenLogprob]] = None
112
92
  """A list of message content tokens with log probability information."""
113
93
  def __init__(self, **kwargs):
114
- if 'content' in kwargs and kwargs['content'] is not None and kwargs['content']:
94
+ if 'content' in kwargs and kwargs['content'] is not None and kwargs[
95
+ 'content']:
115
96
  logprobs = []
116
97
  for logprob in kwargs['content']:
117
98
  logprobs.append(ChatCompletionTokenLogprob(**logprob))
118
99
  self.content = logprobs
119
100
  else:
120
101
  self.content = None
121
-
102
+
122
103
  super().__init__(**kwargs)
123
104
 
105
+
124
106
  @dataclass(init=False)
125
107
  class FunctionCall(BaseObjectMixin):
126
108
  arguments: str
@@ -136,6 +118,7 @@ class FunctionCall(BaseObjectMixin):
136
118
  def __init__(self, **kwargs):
137
119
  super().__init__(**kwargs)
138
120
 
121
+
139
122
  @dataclass(init=False)
140
123
  class Function(BaseObjectMixin):
141
124
  arguments: str
@@ -151,6 +134,7 @@ class Function(BaseObjectMixin):
151
134
  def __init__(self, **kwargs):
152
135
  super().__init__(**kwargs)
153
136
 
137
+
154
138
  @dataclass(init=False)
155
139
  class ChatCompletionMessageToolCall(BaseObjectMixin):
156
140
  id: str
@@ -159,22 +143,24 @@ class ChatCompletionMessageToolCall(BaseObjectMixin):
159
143
  function: Function
160
144
  """The function that the model called."""
161
145
 
162
- type: Literal["function"]
146
+ type: Literal['function']
163
147
  """The type of the tool. Currently, only `function` is supported."""
164
148
  def __init__(self, **kwargs):
165
- if 'function' in kwargs and kwargs['function'] is not None and kwargs['function']:
149
+ if 'function' in kwargs and kwargs['function'] is not None and kwargs[
150
+ 'function']:
166
151
  self.function = Function(**kwargs.pop('function', {}))
167
152
  else:
168
- function = None
169
-
153
+ self.function = None
154
+
170
155
  super().__init__(**kwargs)
171
-
156
+
157
+
172
158
  @dataclass(init=False)
173
159
  class ChatCompletionMessage(BaseObjectMixin):
174
160
  content: Optional[str] = None
175
161
  """The contents of the message."""
176
162
 
177
- role: Literal["assistant"]
163
+ role: Literal['assistant']
178
164
  """The role of the author of this message."""
179
165
 
180
166
  function_call: Optional[FunctionCall] = None
@@ -185,23 +171,27 @@ class ChatCompletionMessage(BaseObjectMixin):
185
171
  """
186
172
 
187
173
  tool_calls: Optional[List[ChatCompletionMessageToolCall]] = None
188
-
189
174
  """The tool calls generated by the model, such as function calls."""
190
175
  def __init__(self, **kwargs):
191
- if 'function_call' in kwargs and kwargs['function_call'] is not None and kwargs['function_call']:
192
- self.function_call = FunctionCall(**kwargs.pop('function_call', {}))
193
-
194
- if 'tool_calls' in kwargs and kwargs['tool_calls'] is not None and kwargs['tool_calls']:
176
+ if 'function_call' in kwargs and kwargs[
177
+ 'function_call'] is not None and kwargs['function_call']:
178
+ self.function_call = FunctionCall(
179
+ **kwargs.pop('function_call', {}))
180
+
181
+ if 'tool_calls' in kwargs and kwargs[
182
+ 'tool_calls'] is not None and kwargs['tool_calls']:
195
183
  tool_calls = []
196
184
  for tool_call in kwargs['tool_calls']:
197
185
  tool_calls.append(ChatCompletionMessageToolCall(**tool_call))
198
186
  self.tool_calls = tool_calls
199
-
187
+
200
188
  super().__init__(**kwargs)
201
-
189
+
190
+
202
191
  @dataclass(init=False)
203
192
  class Choice(BaseObjectMixin):
204
- finish_reason: Literal["stop", "length", "tool_calls", "content_filter", "function_call"]
193
+ finish_reason: Literal['stop', 'length', 'tool_calls', 'content_filter',
194
+ 'function_call']
205
195
  """The reason the model stopped generating tokens.
206
196
 
207
197
  This will be `stop` if the model hit a natural stop point or a provided stop
@@ -219,18 +209,20 @@ class Choice(BaseObjectMixin):
219
209
 
220
210
  message: ChatCompletionMessage
221
211
  """A chat completion message generated by the model."""
222
-
223
212
  def __init__(self, **kwargs):
224
- if 'message' in kwargs and kwargs['message'] is not None and kwargs['message']:
213
+ if 'message' in kwargs and kwargs['message'] is not None and kwargs[
214
+ 'message']:
225
215
  self.message = ChatCompletionMessage(**kwargs.pop('message', {}))
226
216
  else:
227
217
  self.message = None
228
-
229
- if 'logprobs' in kwargs and kwargs['logprobs'] is not None and kwargs['logprobs']:
218
+
219
+ if 'logprobs' in kwargs and kwargs['logprobs'] is not None and kwargs[
220
+ 'logprobs']:
230
221
  self.logprobs = ChoiceLogprobs(**kwargs.pop('logprobs', {}))
231
222
 
232
223
  super().__init__(**kwargs)
233
-
224
+
225
+
234
226
  @dataclass(init=False)
235
227
  class ChatCompletion(BaseObjectMixin):
236
228
  status_code: int
@@ -257,7 +249,7 @@ class ChatCompletion(BaseObjectMixin):
257
249
  model: str
258
250
  """The model used for the chat completion."""
259
251
 
260
- object: Literal["chat.completion"]
252
+ object: Literal['chat.completion']
261
253
  """The object type, which is always `chat.completion`."""
262
254
 
263
255
  system_fingerprint: Optional[str] = None
@@ -269,14 +261,15 @@ class ChatCompletion(BaseObjectMixin):
269
261
 
270
262
  usage: Optional[CompletionUsage] = None
271
263
  """Usage statistics for the completion request."""
272
-
273
264
  def __init__(self, **kwargs):
274
- if 'usage' in kwargs and kwargs['usage'] is not None and kwargs['usage']:
265
+ if 'usage' in kwargs and kwargs['usage'] is not None and kwargs[
266
+ 'usage']:
275
267
  self.usage = CompletionUsage(**kwargs.pop('usage', {}))
276
268
  else:
277
269
  self.usage = None
278
-
279
- if 'choices' in kwargs and kwargs['choices'] is not None and kwargs['choices']:
270
+
271
+ if 'choices' in kwargs and kwargs['choices'] is not None and kwargs[
272
+ 'choices']:
280
273
  choices = []
281
274
  for choice in kwargs.pop('choices', []):
282
275
  choices.append(Choice(**choice))
@@ -284,7 +277,8 @@ class ChatCompletion(BaseObjectMixin):
284
277
  else:
285
278
  self.choices = None
286
279
  super().__init__(**kwargs)
287
-
280
+
281
+
288
282
  @dataclass(init=False)
289
283
  class ChatCompletionChunk(BaseObjectMixin):
290
284
  status_code: int
@@ -315,7 +309,7 @@ class ChatCompletionChunk(BaseObjectMixin):
315
309
  model: str
316
310
  """The model to generate the completion."""
317
311
 
318
- object: Literal["chat.completion.chunk"]
312
+ object: Literal['chat.completion.chunk']
319
313
  """The object type, which is always `chat.completion.chunk`."""
320
314
 
321
315
  system_fingerprint: Optional[str] = None
@@ -333,12 +327,14 @@ class ChatCompletionChunk(BaseObjectMixin):
333
327
  statistics for the entire request.
334
328
  """
335
329
  def __init__(self, **kwargs):
336
- if 'usage' in kwargs and kwargs['usage'] is not None and kwargs['usage']:
330
+ if 'usage' in kwargs and kwargs['usage'] is not None and kwargs[
331
+ 'usage']:
337
332
  self.usage = CompletionUsage(**kwargs.pop('usage', {}))
338
333
  else:
339
334
  self.usage = None
340
-
341
- if 'choices' in kwargs and kwargs['choices'] is not None and kwargs['choices']:
335
+
336
+ if 'choices' in kwargs and kwargs['choices'] is not None and kwargs[
337
+ 'choices']:
342
338
  choices = []
343
339
  for choice in kwargs.pop('choices', []):
344
340
  choices.append(Choice(**choice))
@@ -346,4 +342,3 @@ class ChatCompletionChunk(BaseObjectMixin):
346
342
  else:
347
343
  self.choices = None
348
344
  super().__init__(**kwargs)
349
-
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  import json
2
4
  from dataclasses import dataclass
3
5
  from http import HTTPStatus
@@ -487,9 +489,18 @@ class ImageSynthesisUsage(DictMixin):
487
489
  @dataclass(init=False)
488
490
  class VideoSynthesisUsage(DictMixin):
489
491
  video_count: int
492
+ video_duration: int
493
+ video_ratio: str
490
494
 
491
- def __init__(self, video_count: int = 1, **kwargs):
492
- super().__init__(video_count=video_count, **kwargs)
495
+ def __init__(self,
496
+ video_count: int = 1,
497
+ video_duration: int = 0,
498
+ video_ratio: str = '',
499
+ **kwargs):
500
+ super().__init__(video_count=video_count,
501
+ video_duration=video_duration,
502
+ video_ratio=video_ratio,
503
+ **kwargs)
493
504
 
494
505
 
495
506
  @dataclass(init=False)
@@ -611,3 +622,64 @@ class ReRankResponse(DashScopeAPIResponse):
611
622
  request_id=api_response.request_id,
612
623
  code=api_response.code,
613
624
  message=api_response.message)
625
+
626
+
627
+ @dataclass(init=False)
628
+ class TextToSpeechAudio(DictMixin):
629
+ expires_at: int
630
+ id: str
631
+ data: str
632
+ url: str
633
+
634
+ def __init__(self,
635
+ expires_at: int,
636
+ id: str,
637
+ data: str = None,
638
+ url: str = None,
639
+ **kwargs):
640
+ super().__init__(expires_at=expires_at,
641
+ id=id,
642
+ data=data,
643
+ url=url,
644
+ **kwargs)
645
+
646
+
647
+ @dataclass(init=False)
648
+ class TextToSpeechOutput(DictMixin):
649
+ finish_reason: str
650
+ audio: TextToSpeechAudio
651
+
652
+ def __init__(self,
653
+ finish_reason: str = None,
654
+ audio: TextToSpeechAudio = None,
655
+ **kwargs):
656
+ super().__init__(finish_reason=finish_reason,
657
+ audio=audio,
658
+ **kwargs)
659
+
660
+
661
+ @dataclass(init=False)
662
+ class TextToSpeechResponse(DashScopeAPIResponse):
663
+ output: TextToSpeechOutput
664
+ usage: MultiModalConversationUsage
665
+
666
+ @staticmethod
667
+ def from_api_response(api_response: DashScopeAPIResponse):
668
+ if api_response.status_code == HTTPStatus.OK:
669
+ usage = {}
670
+ if api_response.usage:
671
+ usage = api_response.usage
672
+
673
+ return MultiModalConversationResponse(
674
+ status_code=api_response.status_code,
675
+ request_id=api_response.request_id,
676
+ code=api_response.code,
677
+ message=api_response.message,
678
+ output=TextToSpeechOutput(**api_response.output),
679
+ usage=MultiModalConversationUsage(**usage))
680
+ else:
681
+ return TextToSpeechResponse(
682
+ status_code=api_response.status_code,
683
+ request_id=api_response.request_id,
684
+ code=api_response.code,
685
+ message=api_response.message)
@@ -1,8 +1,11 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  import json
2
4
  from http import HTTPStatus
3
5
 
4
6
  import aiohttp
5
7
  import requests
8
+
6
9
  from dashscope.api_entities.base_request import AioBaseRequest
7
10
  from dashscope.api_entities.dashscope_response import DashScopeAPIResponse
8
11
  from dashscope.common.constants import (DEFAULT_REQUEST_TIMEOUT_SECONDS,
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  import asyncio
2
4
  import json
3
5
  import uuid
@@ -5,6 +7,7 @@ from http import HTTPStatus
5
7
  from typing import Tuple, Union
6
8
 
7
9
  import aiohttp
10
+
8
11
  from dashscope.api_entities.base_request import AioBaseRequest
9
12
  from dashscope.api_entities.dashscope_response import DashScopeAPIResponse
10
13
  from dashscope.common.constants import (DEFAULT_REQUEST_TIMEOUT_SECONDS,
@@ -356,5 +359,3 @@ class WebSocketRequest(AioBaseRequest):
356
359
  def _build_up_message(self, headers, payload):
357
360
  message = {'header': headers, 'payload': payload}
358
361
  return json.dumps(message)
359
-
360
- [{"type": "Path", "pathConfig": {"values": ["/api/v1/configs/*","/api/v1/auths/activate","/api/v1/evaluations/*","/oauth/*","/api/v1/auths/reset/password","~*^/api/v1/users/logout/*"]}}]
dashscope/app/__init__.py CHANGED
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  from .application import Application
2
4
 
3
5
  __all__ = [Application]
@@ -1,19 +1,20 @@
1
- #!/usr/bin/env python3
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
2
  """
3
3
  @File : application.py
4
4
  @Date : 2024-02-24
5
5
  @Desc : Application calls for both http and http sse
6
6
  """
7
7
  import copy
8
- from typing import Generator, Union, List
8
+ from typing import Generator, List, Union
9
9
 
10
10
  from dashscope.api_entities.api_request_factory import _build_api_request
11
+ from dashscope.api_entities.dashscope_response import Message, Role
11
12
  from dashscope.app.application_response import ApplicationResponse
12
13
  from dashscope.client.base_api import BaseApi
13
14
  from dashscope.common.api_key import get_default_api_key
14
- from dashscope.common.constants import HISTORY, PROMPT, DEPRECATED_MESSAGE, MESSAGES
15
+ from dashscope.common.constants import (DEPRECATED_MESSAGE, HISTORY, MESSAGES,
16
+ PROMPT)
15
17
  from dashscope.common.error import InputRequired, InvalidInput
16
- from dashscope.api_entities.dashscope_response import Message, Role
17
18
  from dashscope.common.logging import logger
18
19
 
19
20
 
@@ -23,7 +24,6 @@ class Application(BaseApi):
23
24
  """API for app completion calls.
24
25
 
25
26
  """
26
-
27
27
  class DocReferenceType:
28
28
  """ doc reference type for rag completion """
29
29
 
@@ -43,15 +43,16 @@ class Application(BaseApi):
43
43
 
44
44
  @classmethod
45
45
  def call(
46
- cls,
47
- app_id: str,
48
- prompt: str = None,
49
- history: list = None,
50
- workspace: str = None,
51
- api_key: str = None,
52
- messages: List[Message] = None,
53
- **kwargs
54
- ) -> Union[ApplicationResponse, Generator[ApplicationResponse, None, None]]:
46
+ cls,
47
+ app_id: str,
48
+ prompt: str = None,
49
+ history: list = None,
50
+ workspace: str = None,
51
+ api_key: str = None,
52
+ messages: List[Message] = None,
53
+ **kwargs
54
+ ) -> Union[ApplicationResponse, Generator[ApplicationResponse, None,
55
+ None]]:
55
56
  """Call app completion service.
56
57
 
57
58
  Args:
@@ -119,7 +120,8 @@ class Application(BaseApi):
119
120
 
120
121
  api_key, app_id = Application._validate_params(api_key, app_id)
121
122
 
122
- if (prompt is None or not prompt) and (messages is None or len(messages) == 0):
123
+ if (prompt is None or not prompt) and (messages is None
124
+ or len(messages) == 0):
123
125
  raise InputRequired('prompt or messages is required!')
124
126
 
125
127
  if workspace is not None and workspace:
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env python3
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
2
  """
3
3
  @File : application_response.py
4
4
  @Date : 2024-02-24
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  # yapf: disable
2
4
 
3
5
  from dashscope.assistants.assistant_types import (Assistant, AssistantFile,
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  # adapter from openai sdk
2
4
  from dataclasses import dataclass
3
5
  from typing import Dict, List, Optional, Union
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  from typing import Dict, List, Optional
2
4
 
3
5
  from dashscope.assistants.assistant_types import (Assistant, AssistantList,