dashscope 1.22.2__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.
- dashscope/__init__.py +3 -1
- dashscope/aigc/__init__.py +2 -0
- dashscope/aigc/chat_completion.py +282 -0
- dashscope/aigc/code_generation.py +2 -0
- dashscope/aigc/conversation.py +2 -0
- dashscope/aigc/generation.py +2 -0
- dashscope/aigc/image_synthesis.py +2 -0
- dashscope/aigc/multimodal_conversation.py +2 -0
- dashscope/aigc/video_synthesis.py +2 -0
- dashscope/api_entities/aiohttp_request.py +3 -0
- dashscope/api_entities/api_request_data.py +3 -0
- dashscope/api_entities/api_request_factory.py +2 -0
- dashscope/api_entities/base_request.py +2 -0
- dashscope/api_entities/chat_completion_types.py +344 -0
- dashscope/api_entities/dashscope_response.py +63 -0
- dashscope/api_entities/http_request.py +3 -0
- dashscope/api_entities/websocket_request.py +3 -0
- dashscope/app/__init__.py +2 -0
- dashscope/app/application.py +17 -15
- dashscope/app/application_response.py +1 -1
- dashscope/assistants/__init__.py +2 -0
- dashscope/assistants/assistant_types.py +2 -0
- dashscope/assistants/assistants.py +2 -0
- dashscope/assistants/files.py +2 -0
- dashscope/audio/__init__.py +4 -2
- dashscope/audio/asr/__init__.py +2 -0
- dashscope/audio/asr/asr_phrase_manager.py +2 -0
- dashscope/audio/asr/recognition.py +2 -0
- dashscope/audio/asr/transcription.py +3 -0
- dashscope/audio/asr/translation_recognizer.py +2 -0
- dashscope/audio/asr/vocabulary.py +3 -0
- dashscope/audio/qwen_tts/__init__.py +5 -0
- dashscope/audio/qwen_tts/speech_synthesizer.py +77 -0
- dashscope/audio/tts/__init__.py +2 -0
- dashscope/audio/tts/speech_synthesizer.py +2 -0
- dashscope/audio/tts_v2/__init__.py +2 -0
- dashscope/audio/tts_v2/enrollment.py +3 -0
- dashscope/audio/tts_v2/speech_synthesizer.py +4 -1
- dashscope/client/base_api.py +4 -1
- dashscope/common/api_key.py +2 -0
- dashscope/common/base_type.py +2 -0
- dashscope/common/constants.py +2 -0
- dashscope/common/env.py +2 -0
- dashscope/common/error.py +3 -0
- dashscope/common/logging.py +2 -0
- dashscope/common/message_manager.py +2 -0
- dashscope/common/utils.py +3 -0
- dashscope/customize/customize_types.py +2 -0
- dashscope/customize/deployments.py +2 -0
- dashscope/customize/finetunes.py +2 -0
- dashscope/embeddings/__init__.py +2 -0
- dashscope/embeddings/batch_text_embedding.py +2 -0
- dashscope/embeddings/batch_text_embedding_response.py +3 -0
- dashscope/embeddings/multimodal_embedding.py +2 -0
- dashscope/embeddings/text_embedding.py +2 -0
- dashscope/files.py +2 -0
- dashscope/io/input_output.py +2 -0
- dashscope/model.py +2 -0
- dashscope/models.py +2 -0
- dashscope/nlp/understanding.py +2 -0
- dashscope/protocol/websocket.py +3 -0
- dashscope/rerank/text_rerank.py +2 -0
- dashscope/threads/__init__.py +2 -0
- dashscope/threads/messages/files.py +2 -0
- dashscope/threads/messages/messages.py +2 -0
- dashscope/threads/runs/runs.py +2 -0
- dashscope/threads/runs/steps.py +2 -0
- dashscope/threads/thread_types.py +2 -0
- dashscope/threads/threads.py +2 -0
- dashscope/tokenizers/__init__.py +2 -0
- dashscope/tokenizers/qwen_tokenizer.py +2 -0
- dashscope/tokenizers/tokenization.py +2 -0
- dashscope/tokenizers/tokenizer.py +2 -0
- dashscope/tokenizers/tokenizer_base.py +2 -0
- dashscope/utils/oss_utils.py +3 -0
- dashscope/version.py +3 -1
- {dashscope-1.22.2.dist-info → dashscope-1.23.0.dist-info}/LICENSE +2 -4
- {dashscope-1.22.2.dist-info → dashscope-1.23.0.dist-info}/METADATA +1 -1
- dashscope-1.23.0.dist-info/RECORD +95 -0
- dashscope/audio/asr/transcribe.py +0 -270
- dashscope/deployment.py +0 -163
- dashscope/file.py +0 -94
- dashscope/finetune.py +0 -175
- dashscope-1.22.2.dist-info/RECORD +0 -95
- {dashscope-1.22.2.dist-info → dashscope-1.23.0.dist-info}/WHEEL +0 -0
- {dashscope-1.22.2.dist-info → dashscope-1.23.0.dist-info}/entry_points.txt +0 -0
- {dashscope-1.22.2.dist-info → dashscope-1.23.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
2
|
+
|
|
3
|
+
# adapter from openai sdk
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from typing import List, Literal, Optional
|
|
6
|
+
|
|
7
|
+
from dashscope.common.base_type import BaseObjectMixin
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(init=False)
|
|
11
|
+
class CompletionUsage(BaseObjectMixin):
|
|
12
|
+
completion_tokens: int
|
|
13
|
+
"""Number of tokens in the generated completion."""
|
|
14
|
+
|
|
15
|
+
prompt_tokens: int
|
|
16
|
+
"""Number of tokens in the prompt."""
|
|
17
|
+
|
|
18
|
+
total_tokens: int
|
|
19
|
+
"""Total number of tokens used in the request (prompt + completion)."""
|
|
20
|
+
def __init__(self, **kwargs):
|
|
21
|
+
super().__init__(**kwargs)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass(init=False)
|
|
25
|
+
class TopLogprob(BaseObjectMixin):
|
|
26
|
+
token: str
|
|
27
|
+
"""The token."""
|
|
28
|
+
|
|
29
|
+
bytes: Optional[List[int]] = None
|
|
30
|
+
"""A list of integers representing the UTF-8 bytes representation of the token.
|
|
31
|
+
|
|
32
|
+
Useful in instances where characters are represented by multiple tokens and
|
|
33
|
+
their byte representations must be combined to generate the correct text
|
|
34
|
+
representation. Can be `null` if there is no bytes representation for the token.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
logprob: float
|
|
38
|
+
"""The log probability of this token, if it is within the top 20 most likely
|
|
39
|
+
tokens.
|
|
40
|
+
|
|
41
|
+
Otherwise, the value `-9999.0` is used to signify that the token is very
|
|
42
|
+
unlikely.
|
|
43
|
+
"""
|
|
44
|
+
def __init__(self, **kwargs):
|
|
45
|
+
super().__init__(**kwargs)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@dataclass(init=False)
|
|
49
|
+
class ChatCompletionTokenLogprob(BaseObjectMixin):
|
|
50
|
+
token: str
|
|
51
|
+
"""The token."""
|
|
52
|
+
|
|
53
|
+
bytes: Optional[List[int]] = None
|
|
54
|
+
"""A list of integers representing the UTF-8 bytes representation of the token.
|
|
55
|
+
|
|
56
|
+
Useful in instances where characters are represented by multiple tokens and
|
|
57
|
+
their byte representations must be combined to generate the correct text
|
|
58
|
+
representation. Can be `null` if there is no bytes representation for the token.
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
logprob: float
|
|
62
|
+
"""The log probability of this token, if it is within the top 20 most likely
|
|
63
|
+
tokens.
|
|
64
|
+
|
|
65
|
+
Otherwise, the value `-9999.0` is used to signify that the token is very
|
|
66
|
+
unlikely.
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
top_logprobs: List[TopLogprob]
|
|
70
|
+
"""List of the most likely tokens and their log probability, at this token
|
|
71
|
+
position.
|
|
72
|
+
|
|
73
|
+
In rare cases, there may be fewer than the number of requested `top_logprobs`
|
|
74
|
+
returned.
|
|
75
|
+
"""
|
|
76
|
+
def __init__(self, **kwargs):
|
|
77
|
+
if 'top_logprobs' in kwargs and kwargs[
|
|
78
|
+
'top_logprobs'] is not None and kwargs['top_logprobs']:
|
|
79
|
+
top_logprobs = []
|
|
80
|
+
for logprob in kwargs['top_logprobs']:
|
|
81
|
+
top_logprobs.append(ChatCompletionTokenLogprob(**logprob))
|
|
82
|
+
self.top_logprobs = top_logprobs
|
|
83
|
+
else:
|
|
84
|
+
self.top_logprobs = None
|
|
85
|
+
|
|
86
|
+
super().__init__(**kwargs)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@dataclass(init=False)
|
|
90
|
+
class ChoiceLogprobs(BaseObjectMixin):
|
|
91
|
+
content: Optional[List[ChatCompletionTokenLogprob]] = None
|
|
92
|
+
"""A list of message content tokens with log probability information."""
|
|
93
|
+
def __init__(self, **kwargs):
|
|
94
|
+
if 'content' in kwargs and kwargs['content'] is not None and kwargs[
|
|
95
|
+
'content']:
|
|
96
|
+
logprobs = []
|
|
97
|
+
for logprob in kwargs['content']:
|
|
98
|
+
logprobs.append(ChatCompletionTokenLogprob(**logprob))
|
|
99
|
+
self.content = logprobs
|
|
100
|
+
else:
|
|
101
|
+
self.content = None
|
|
102
|
+
|
|
103
|
+
super().__init__(**kwargs)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
@dataclass(init=False)
|
|
107
|
+
class FunctionCall(BaseObjectMixin):
|
|
108
|
+
arguments: str
|
|
109
|
+
"""
|
|
110
|
+
The arguments to call the function with, as generated by the model in JSON
|
|
111
|
+
format. Note that the model does not always generate valid JSON, and may
|
|
112
|
+
hallucinate parameters not defined by your function schema. Validate the
|
|
113
|
+
arguments in your code before calling your function.
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
name: str
|
|
117
|
+
"""The name of the function to call."""
|
|
118
|
+
def __init__(self, **kwargs):
|
|
119
|
+
super().__init__(**kwargs)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
@dataclass(init=False)
|
|
123
|
+
class Function(BaseObjectMixin):
|
|
124
|
+
arguments: str
|
|
125
|
+
"""
|
|
126
|
+
The arguments to call the function with, as generated by the model in JSON
|
|
127
|
+
format. Note that the model does not always generate valid JSON, and may
|
|
128
|
+
hallucinate parameters not defined by your function schema. Validate the
|
|
129
|
+
arguments in your code before calling your function.
|
|
130
|
+
"""
|
|
131
|
+
|
|
132
|
+
name: str
|
|
133
|
+
"""The name of the function to call."""
|
|
134
|
+
def __init__(self, **kwargs):
|
|
135
|
+
super().__init__(**kwargs)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
@dataclass(init=False)
|
|
139
|
+
class ChatCompletionMessageToolCall(BaseObjectMixin):
|
|
140
|
+
id: str
|
|
141
|
+
"""The ID of the tool call."""
|
|
142
|
+
|
|
143
|
+
function: Function
|
|
144
|
+
"""The function that the model called."""
|
|
145
|
+
|
|
146
|
+
type: Literal['function']
|
|
147
|
+
"""The type of the tool. Currently, only `function` is supported."""
|
|
148
|
+
def __init__(self, **kwargs):
|
|
149
|
+
if 'function' in kwargs and kwargs['function'] is not None and kwargs[
|
|
150
|
+
'function']:
|
|
151
|
+
self.function = Function(**kwargs.pop('function', {}))
|
|
152
|
+
else:
|
|
153
|
+
self.function = None
|
|
154
|
+
|
|
155
|
+
super().__init__(**kwargs)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
@dataclass(init=False)
|
|
159
|
+
class ChatCompletionMessage(BaseObjectMixin):
|
|
160
|
+
content: Optional[str] = None
|
|
161
|
+
"""The contents of the message."""
|
|
162
|
+
|
|
163
|
+
role: Literal['assistant']
|
|
164
|
+
"""The role of the author of this message."""
|
|
165
|
+
|
|
166
|
+
function_call: Optional[FunctionCall] = None
|
|
167
|
+
"""Deprecated and replaced by `tool_calls`.
|
|
168
|
+
|
|
169
|
+
The name and arguments of a function that should be called, as generated by the
|
|
170
|
+
model.
|
|
171
|
+
"""
|
|
172
|
+
|
|
173
|
+
tool_calls: Optional[List[ChatCompletionMessageToolCall]] = None
|
|
174
|
+
"""The tool calls generated by the model, such as function calls."""
|
|
175
|
+
def __init__(self, **kwargs):
|
|
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']:
|
|
183
|
+
tool_calls = []
|
|
184
|
+
for tool_call in kwargs['tool_calls']:
|
|
185
|
+
tool_calls.append(ChatCompletionMessageToolCall(**tool_call))
|
|
186
|
+
self.tool_calls = tool_calls
|
|
187
|
+
|
|
188
|
+
super().__init__(**kwargs)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
@dataclass(init=False)
|
|
192
|
+
class Choice(BaseObjectMixin):
|
|
193
|
+
finish_reason: Literal['stop', 'length', 'tool_calls', 'content_filter',
|
|
194
|
+
'function_call']
|
|
195
|
+
"""The reason the model stopped generating tokens.
|
|
196
|
+
|
|
197
|
+
This will be `stop` if the model hit a natural stop point or a provided stop
|
|
198
|
+
sequence, `length` if the maximum number of tokens specified in the request was
|
|
199
|
+
reached, `content_filter` if content was omitted due to a flag from our content
|
|
200
|
+
filters, `tool_calls` if the model called a tool, or `function_call`
|
|
201
|
+
(deprecated) if the model called a function.
|
|
202
|
+
"""
|
|
203
|
+
|
|
204
|
+
index: int
|
|
205
|
+
"""The index of the choice in the list of choices."""
|
|
206
|
+
|
|
207
|
+
logprobs: Optional[ChoiceLogprobs] = None
|
|
208
|
+
"""Log probability information for the choice."""
|
|
209
|
+
|
|
210
|
+
message: ChatCompletionMessage
|
|
211
|
+
"""A chat completion message generated by the model."""
|
|
212
|
+
def __init__(self, **kwargs):
|
|
213
|
+
if 'message' in kwargs and kwargs['message'] is not None and kwargs[
|
|
214
|
+
'message']:
|
|
215
|
+
self.message = ChatCompletionMessage(**kwargs.pop('message', {}))
|
|
216
|
+
else:
|
|
217
|
+
self.message = None
|
|
218
|
+
|
|
219
|
+
if 'logprobs' in kwargs and kwargs['logprobs'] is not None and kwargs[
|
|
220
|
+
'logprobs']:
|
|
221
|
+
self.logprobs = ChoiceLogprobs(**kwargs.pop('logprobs', {}))
|
|
222
|
+
|
|
223
|
+
super().__init__(**kwargs)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
@dataclass(init=False)
|
|
227
|
+
class ChatCompletion(BaseObjectMixin):
|
|
228
|
+
status_code: int
|
|
229
|
+
"""The call response status_code, 200 indicate create success.
|
|
230
|
+
"""
|
|
231
|
+
code: str
|
|
232
|
+
"""The request failed, this is the error code.
|
|
233
|
+
"""
|
|
234
|
+
message: str
|
|
235
|
+
"""The request failed, this is the error message.
|
|
236
|
+
"""
|
|
237
|
+
id: str
|
|
238
|
+
"""A unique identifier for the chat completion.
|
|
239
|
+
"""
|
|
240
|
+
choices: List[Choice]
|
|
241
|
+
"""A list of chat completion choices.
|
|
242
|
+
|
|
243
|
+
Can be more than one if `n` is greater than 1.
|
|
244
|
+
"""
|
|
245
|
+
|
|
246
|
+
created: int
|
|
247
|
+
"""The Unix timestamp (in seconds) of when the chat completion was created."""
|
|
248
|
+
|
|
249
|
+
model: str
|
|
250
|
+
"""The model used for the chat completion."""
|
|
251
|
+
|
|
252
|
+
object: Literal['chat.completion']
|
|
253
|
+
"""The object type, which is always `chat.completion`."""
|
|
254
|
+
|
|
255
|
+
system_fingerprint: Optional[str] = None
|
|
256
|
+
"""This fingerprint represents the backend configuration that the model runs with.
|
|
257
|
+
|
|
258
|
+
Can be used in conjunction with the `seed` request parameter to understand when
|
|
259
|
+
backend changes have been made that might impact determinism.
|
|
260
|
+
"""
|
|
261
|
+
|
|
262
|
+
usage: Optional[CompletionUsage] = None
|
|
263
|
+
"""Usage statistics for the completion request."""
|
|
264
|
+
def __init__(self, **kwargs):
|
|
265
|
+
if 'usage' in kwargs and kwargs['usage'] is not None and kwargs[
|
|
266
|
+
'usage']:
|
|
267
|
+
self.usage = CompletionUsage(**kwargs.pop('usage', {}))
|
|
268
|
+
else:
|
|
269
|
+
self.usage = None
|
|
270
|
+
|
|
271
|
+
if 'choices' in kwargs and kwargs['choices'] is not None and kwargs[
|
|
272
|
+
'choices']:
|
|
273
|
+
choices = []
|
|
274
|
+
for choice in kwargs.pop('choices', []):
|
|
275
|
+
choices.append(Choice(**choice))
|
|
276
|
+
self.choices = choices
|
|
277
|
+
else:
|
|
278
|
+
self.choices = None
|
|
279
|
+
super().__init__(**kwargs)
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
@dataclass(init=False)
|
|
283
|
+
class ChatCompletionChunk(BaseObjectMixin):
|
|
284
|
+
status_code: int
|
|
285
|
+
"""The call response status_code, 200 indicate create success.
|
|
286
|
+
"""
|
|
287
|
+
code: str
|
|
288
|
+
"""The request failed, this is the error code.
|
|
289
|
+
"""
|
|
290
|
+
message: str
|
|
291
|
+
"""The request failed, this is the error message.
|
|
292
|
+
"""
|
|
293
|
+
id: str
|
|
294
|
+
"""A unique identifier for the chat completion. Each chunk has the same ID."""
|
|
295
|
+
|
|
296
|
+
choices: List[Choice]
|
|
297
|
+
"""A list of chat completion choices.
|
|
298
|
+
|
|
299
|
+
Can contain more than one elements if `n` is greater than 1. Can also be empty
|
|
300
|
+
for the last chunk if you set `stream_options: {"include_usage": true}`.
|
|
301
|
+
"""
|
|
302
|
+
|
|
303
|
+
created: int
|
|
304
|
+
"""The Unix timestamp (in seconds) of when the chat completion was created.
|
|
305
|
+
|
|
306
|
+
Each chunk has the same timestamp.
|
|
307
|
+
"""
|
|
308
|
+
|
|
309
|
+
model: str
|
|
310
|
+
"""The model to generate the completion."""
|
|
311
|
+
|
|
312
|
+
object: Literal['chat.completion.chunk']
|
|
313
|
+
"""The object type, which is always `chat.completion.chunk`."""
|
|
314
|
+
|
|
315
|
+
system_fingerprint: Optional[str] = None
|
|
316
|
+
"""
|
|
317
|
+
This fingerprint represents the backend configuration that the model runs with.
|
|
318
|
+
Can be used in conjunction with the `seed` request parameter to understand when
|
|
319
|
+
backend changes have been made that might impact determinism.
|
|
320
|
+
"""
|
|
321
|
+
|
|
322
|
+
usage: Optional[CompletionUsage] = None
|
|
323
|
+
"""
|
|
324
|
+
An optional field that will only be present when you set
|
|
325
|
+
`stream_options: {"include_usage": true}` in your request. When present, it
|
|
326
|
+
contains a null value except for the last chunk which contains the token usage
|
|
327
|
+
statistics for the entire request.
|
|
328
|
+
"""
|
|
329
|
+
def __init__(self, **kwargs):
|
|
330
|
+
if 'usage' in kwargs and kwargs['usage'] is not None and kwargs[
|
|
331
|
+
'usage']:
|
|
332
|
+
self.usage = CompletionUsage(**kwargs.pop('usage', {}))
|
|
333
|
+
else:
|
|
334
|
+
self.usage = None
|
|
335
|
+
|
|
336
|
+
if 'choices' in kwargs and kwargs['choices'] is not None and kwargs[
|
|
337
|
+
'choices']:
|
|
338
|
+
choices = []
|
|
339
|
+
for choice in kwargs.pop('choices', []):
|
|
340
|
+
choices.append(Choice(**choice))
|
|
341
|
+
self.choices = choices
|
|
342
|
+
else:
|
|
343
|
+
self.choices = None
|
|
344
|
+
super().__init__(**kwargs)
|
|
@@ -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
|
|
@@ -620,3 +622,64 @@ class ReRankResponse(DashScopeAPIResponse):
|
|
|
620
622
|
request_id=api_response.request_id,
|
|
621
623
|
code=api_response.code,
|
|
622
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,
|
dashscope/app/__init__.py
CHANGED
dashscope/app/application.py
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
|
|
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,
|
|
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
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
) -> Union[ApplicationResponse, Generator[ApplicationResponse, 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
|
|
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:
|
dashscope/assistants/__init__.py
CHANGED
dashscope/assistants/files.py
CHANGED
dashscope/audio/__init__.py
CHANGED
dashscope/audio/asr/__init__.py
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
2
|
+
|
|
1
3
|
import asyncio
|
|
2
4
|
import time
|
|
3
5
|
from typing import List, Union
|
|
4
6
|
|
|
5
7
|
import aiohttp
|
|
8
|
+
|
|
6
9
|
from dashscope.api_entities.dashscope_response import (DashScopeAPIResponse,
|
|
7
10
|
TranscriptionResponse)
|
|
8
11
|
from dashscope.client.base_api import BaseAsyncApi
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
2
|
+
|
|
1
3
|
import asyncio
|
|
2
4
|
import time
|
|
3
5
|
from typing import List
|
|
4
6
|
|
|
5
7
|
import aiohttp
|
|
8
|
+
|
|
6
9
|
from dashscope.client.base_api import BaseApi
|
|
7
10
|
from dashscope.common.constants import ApiProtocol, HTTPMethod
|
|
8
11
|
from dashscope.common.logging import logger
|