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.
- dashscope/__init__.py +61 -14
- dashscope/aigc/__init__.py +10 -3
- dashscope/aigc/chat_completion.py +282 -0
- dashscope/aigc/code_generation.py +145 -0
- dashscope/aigc/conversation.py +71 -12
- dashscope/aigc/generation.py +288 -16
- dashscope/aigc/image_synthesis.py +473 -31
- dashscope/aigc/multimodal_conversation.py +299 -14
- dashscope/aigc/video_synthesis.py +610 -0
- dashscope/api_entities/aiohttp_request.py +8 -5
- dashscope/api_entities/api_request_data.py +4 -2
- dashscope/api_entities/api_request_factory.py +68 -20
- dashscope/api_entities/base_request.py +20 -3
- dashscope/api_entities/chat_completion_types.py +344 -0
- dashscope/api_entities/dashscope_response.py +243 -15
- dashscope/api_entities/encryption.py +179 -0
- dashscope/api_entities/http_request.py +216 -62
- dashscope/api_entities/websocket_request.py +43 -34
- dashscope/app/__init__.py +5 -0
- dashscope/app/application.py +203 -0
- dashscope/app/application_response.py +246 -0
- dashscope/assistants/__init__.py +16 -0
- dashscope/assistants/assistant_types.py +175 -0
- dashscope/assistants/assistants.py +311 -0
- dashscope/assistants/files.py +197 -0
- dashscope/audio/__init__.py +4 -2
- dashscope/audio/asr/__init__.py +17 -1
- dashscope/audio/asr/asr_phrase_manager.py +203 -0
- dashscope/audio/asr/recognition.py +167 -27
- dashscope/audio/asr/transcription.py +107 -14
- dashscope/audio/asr/translation_recognizer.py +1006 -0
- dashscope/audio/asr/vocabulary.py +177 -0
- dashscope/audio/qwen_asr/__init__.py +7 -0
- dashscope/audio/qwen_asr/qwen_transcription.py +189 -0
- dashscope/audio/qwen_omni/__init__.py +11 -0
- dashscope/audio/qwen_omni/omni_realtime.py +524 -0
- dashscope/audio/qwen_tts/__init__.py +5 -0
- dashscope/audio/qwen_tts/speech_synthesizer.py +77 -0
- dashscope/audio/qwen_tts_realtime/__init__.py +10 -0
- dashscope/audio/qwen_tts_realtime/qwen_tts_realtime.py +355 -0
- dashscope/audio/tts/__init__.py +2 -0
- dashscope/audio/tts/speech_synthesizer.py +5 -0
- dashscope/audio/tts_v2/__init__.py +12 -0
- dashscope/audio/tts_v2/enrollment.py +179 -0
- dashscope/audio/tts_v2/speech_synthesizer.py +886 -0
- dashscope/cli.py +157 -37
- dashscope/client/base_api.py +652 -87
- dashscope/common/api_key.py +2 -0
- dashscope/common/base_type.py +135 -0
- dashscope/common/constants.py +13 -16
- dashscope/common/env.py +2 -0
- dashscope/common/error.py +58 -22
- dashscope/common/logging.py +2 -0
- dashscope/common/message_manager.py +2 -0
- dashscope/common/utils.py +276 -46
- dashscope/customize/__init__.py +0 -0
- dashscope/customize/customize_types.py +192 -0
- dashscope/customize/deployments.py +146 -0
- dashscope/customize/finetunes.py +234 -0
- dashscope/embeddings/__init__.py +5 -1
- dashscope/embeddings/batch_text_embedding.py +208 -0
- dashscope/embeddings/batch_text_embedding_response.py +65 -0
- dashscope/embeddings/multimodal_embedding.py +118 -10
- dashscope/embeddings/text_embedding.py +13 -1
- dashscope/{file.py → files.py} +19 -4
- dashscope/io/input_output.py +2 -0
- dashscope/model.py +11 -2
- dashscope/models.py +43 -0
- dashscope/multimodal/__init__.py +20 -0
- dashscope/multimodal/dialog_state.py +56 -0
- dashscope/multimodal/multimodal_constants.py +28 -0
- dashscope/multimodal/multimodal_dialog.py +648 -0
- dashscope/multimodal/multimodal_request_params.py +313 -0
- dashscope/multimodal/tingwu/__init__.py +10 -0
- dashscope/multimodal/tingwu/tingwu.py +80 -0
- dashscope/multimodal/tingwu/tingwu_realtime.py +579 -0
- dashscope/nlp/__init__.py +0 -0
- dashscope/nlp/understanding.py +64 -0
- dashscope/protocol/websocket.py +3 -0
- dashscope/rerank/__init__.py +0 -0
- dashscope/rerank/text_rerank.py +69 -0
- dashscope/resources/qwen.tiktoken +151643 -0
- dashscope/threads/__init__.py +26 -0
- dashscope/threads/messages/__init__.py +0 -0
- dashscope/threads/messages/files.py +113 -0
- dashscope/threads/messages/messages.py +220 -0
- dashscope/threads/runs/__init__.py +0 -0
- dashscope/threads/runs/runs.py +501 -0
- dashscope/threads/runs/steps.py +112 -0
- dashscope/threads/thread_types.py +665 -0
- dashscope/threads/threads.py +212 -0
- dashscope/tokenizers/__init__.py +7 -0
- dashscope/tokenizers/qwen_tokenizer.py +111 -0
- dashscope/tokenizers/tokenization.py +125 -0
- dashscope/tokenizers/tokenizer.py +45 -0
- dashscope/tokenizers/tokenizer_base.py +32 -0
- dashscope/utils/__init__.py +0 -0
- dashscope/utils/message_utils.py +838 -0
- dashscope/utils/oss_utils.py +243 -0
- dashscope/utils/param_utils.py +29 -0
- dashscope/version.py +3 -1
- {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info}/METADATA +53 -50
- dashscope-1.25.6.dist-info/RECORD +112 -0
- {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info}/WHEEL +1 -1
- {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info}/entry_points.txt +0 -1
- {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info/licenses}/LICENSE +2 -4
- dashscope/deployment.py +0 -129
- dashscope/finetune.py +0 -149
- dashscope-1.8.0.dist-info/RECORD +0 -49
- {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
2
|
+
|
|
3
|
+
from typing import Dict, List, Optional
|
|
4
|
+
|
|
5
|
+
from dashscope.assistants.assistant_types import (Assistant, AssistantList,
|
|
6
|
+
DeleteResponse)
|
|
7
|
+
from dashscope.client.base_api import (CancelMixin, CreateMixin, DeleteMixin,
|
|
8
|
+
GetStatusMixin, ListObjectMixin,
|
|
9
|
+
UpdateMixin)
|
|
10
|
+
from dashscope.common.error import ModelRequired
|
|
11
|
+
|
|
12
|
+
__all__ = ['Assistants']
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Assistants(CreateMixin, CancelMixin, DeleteMixin, ListObjectMixin,
|
|
16
|
+
GetStatusMixin, UpdateMixin):
|
|
17
|
+
SUB_PATH = 'assistants'
|
|
18
|
+
|
|
19
|
+
@classmethod
|
|
20
|
+
def _create_assistant_object(
|
|
21
|
+
cls,
|
|
22
|
+
model: str = None,
|
|
23
|
+
name: str = None,
|
|
24
|
+
description: str = None,
|
|
25
|
+
instructions: str = None,
|
|
26
|
+
tools: Optional[List[Dict]] = None,
|
|
27
|
+
file_ids: Optional[List[str]] = [],
|
|
28
|
+
metadata: Dict = {},
|
|
29
|
+
top_p: Optional[float] = None,
|
|
30
|
+
top_k: Optional[int] = None,
|
|
31
|
+
temperature: Optional[float] = None,
|
|
32
|
+
max_tokens: Optional[int] = None,
|
|
33
|
+
):
|
|
34
|
+
obj = {}
|
|
35
|
+
if model:
|
|
36
|
+
obj['model'] = model
|
|
37
|
+
if name:
|
|
38
|
+
obj['name'] = name
|
|
39
|
+
if description:
|
|
40
|
+
obj['description'] = description
|
|
41
|
+
if instructions:
|
|
42
|
+
obj['instructions'] = instructions
|
|
43
|
+
if tools is not None:
|
|
44
|
+
obj['tools'] = tools
|
|
45
|
+
obj['file_ids'] = file_ids
|
|
46
|
+
obj['metadata'] = metadata
|
|
47
|
+
|
|
48
|
+
if top_p is not None:
|
|
49
|
+
obj['top_p'] = top_p
|
|
50
|
+
if top_k is not None:
|
|
51
|
+
obj['top_k'] = top_k
|
|
52
|
+
if temperature is not None:
|
|
53
|
+
obj['temperature'] = temperature
|
|
54
|
+
if max_tokens is not None:
|
|
55
|
+
obj['max_tokens'] = max_tokens
|
|
56
|
+
|
|
57
|
+
return obj
|
|
58
|
+
|
|
59
|
+
@classmethod
|
|
60
|
+
def call(cls,
|
|
61
|
+
*,
|
|
62
|
+
model: str,
|
|
63
|
+
name: str = None,
|
|
64
|
+
description: str = None,
|
|
65
|
+
instructions: str = None,
|
|
66
|
+
tools: Optional[List[Dict]] = None,
|
|
67
|
+
file_ids: Optional[List[str]] = [],
|
|
68
|
+
metadata: Dict = None,
|
|
69
|
+
workspace: str = None,
|
|
70
|
+
api_key: str = None,
|
|
71
|
+
**kwargs) -> Assistant:
|
|
72
|
+
"""Create Assistant.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
model (str): The model to use.
|
|
76
|
+
name (str, optional): The assistant name. Defaults to None.
|
|
77
|
+
description (str, optional): The assistant description. Defaults to None.
|
|
78
|
+
instructions (str, optional): The system instructions this assistant uses. Defaults to None.
|
|
79
|
+
tools (Optional[List[Dict]], optional): List of tools to use. Defaults to [].
|
|
80
|
+
file_ids (Optional[List[str]], optional): : The files to use. Defaults to [].
|
|
81
|
+
metadata (Dict, optional): Custom key-value pairs associate with assistant. Defaults to None.
|
|
82
|
+
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
|
83
|
+
api_key (str, optional): The DashScope api key. Defaults to None.
|
|
84
|
+
|
|
85
|
+
Raises:
|
|
86
|
+
ModelRequired: The model is required.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
Assistant: The `Assistant` object.
|
|
90
|
+
"""
|
|
91
|
+
return cls.create(model=model,
|
|
92
|
+
name=name,
|
|
93
|
+
description=description,
|
|
94
|
+
instructions=instructions,
|
|
95
|
+
tools=tools,
|
|
96
|
+
file_ids=file_ids,
|
|
97
|
+
metadata=metadata,
|
|
98
|
+
workspace=workspace,
|
|
99
|
+
api_key=api_key,
|
|
100
|
+
**kwargs)
|
|
101
|
+
|
|
102
|
+
@classmethod
|
|
103
|
+
def create(cls,
|
|
104
|
+
*,
|
|
105
|
+
model: str,
|
|
106
|
+
name: str = None,
|
|
107
|
+
description: str = None,
|
|
108
|
+
instructions: str = None,
|
|
109
|
+
tools: Optional[List[Dict]] = None,
|
|
110
|
+
file_ids: Optional[List[str]] = [],
|
|
111
|
+
metadata: Dict = None,
|
|
112
|
+
workspace: str = None,
|
|
113
|
+
api_key: str = None,
|
|
114
|
+
top_p: Optional[float] = None,
|
|
115
|
+
top_k: Optional[int] = None,
|
|
116
|
+
temperature: Optional[float] = None,
|
|
117
|
+
max_tokens: Optional[int] = None,
|
|
118
|
+
**kwargs) -> Assistant:
|
|
119
|
+
"""Create Assistant.
|
|
120
|
+
|
|
121
|
+
Args:
|
|
122
|
+
model (str): The model to use.
|
|
123
|
+
name (str, optional): The assistant name. Defaults to None.
|
|
124
|
+
description (str, optional): The assistant description. Defaults to None.
|
|
125
|
+
instructions (str, optional): The system instructions this assistant uses. Defaults to None.
|
|
126
|
+
tools (Optional[List[Dict]], optional): List of tools to use. Defaults to [].
|
|
127
|
+
file_ids (Optional[List[str]], optional): : The files to use. Defaults to [].
|
|
128
|
+
metadata (Dict, optional): Custom key-value pairs associate with assistant. Defaults to None.
|
|
129
|
+
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
|
130
|
+
api_key (str, optional): The DashScope api key. Defaults to None.
|
|
131
|
+
top_p (float, optional): top_p parameter for model. Defaults to None.
|
|
132
|
+
top_k (int, optional): top_p parameter for model. Defaults to None.
|
|
133
|
+
temperature (float, optional): temperature parameter for model. Defaults to None.
|
|
134
|
+
max_tokens (int, optional): max_tokens parameter for model. Defaults to None.
|
|
135
|
+
|
|
136
|
+
Raises:
|
|
137
|
+
ModelRequired: The model is required.
|
|
138
|
+
|
|
139
|
+
Returns:
|
|
140
|
+
Assistant: The `Assistant` object.
|
|
141
|
+
"""
|
|
142
|
+
if not model:
|
|
143
|
+
raise ModelRequired('Model is required!')
|
|
144
|
+
data = cls._create_assistant_object(model, name, description,
|
|
145
|
+
instructions, tools, file_ids,
|
|
146
|
+
metadata, top_p, top_k, temperature, max_tokens)
|
|
147
|
+
response = super().call(data=data,
|
|
148
|
+
api_key=api_key,
|
|
149
|
+
flattened_output=True,
|
|
150
|
+
workspace=workspace,
|
|
151
|
+
**kwargs)
|
|
152
|
+
return Assistant(**response)
|
|
153
|
+
|
|
154
|
+
@classmethod
|
|
155
|
+
def retrieve(cls,
|
|
156
|
+
assistant_id: str,
|
|
157
|
+
*,
|
|
158
|
+
workspace: str = None,
|
|
159
|
+
api_key: str = None,
|
|
160
|
+
**kwargs) -> Assistant:
|
|
161
|
+
"""Get the `Assistant`.
|
|
162
|
+
|
|
163
|
+
Args:
|
|
164
|
+
assistant_id (str): The assistant id.
|
|
165
|
+
workspace (str): The dashscope workspace id.
|
|
166
|
+
api_key (str, optional): The api key. Defaults to None.
|
|
167
|
+
|
|
168
|
+
Returns:
|
|
169
|
+
Assistant: The `Assistant` object.
|
|
170
|
+
"""
|
|
171
|
+
return cls.get(assistant_id,
|
|
172
|
+
workspace=workspace,
|
|
173
|
+
api_key=api_key,
|
|
174
|
+
**kwargs)
|
|
175
|
+
|
|
176
|
+
@classmethod
|
|
177
|
+
def get(cls,
|
|
178
|
+
assistant_id: str,
|
|
179
|
+
*,
|
|
180
|
+
workspace: str = None,
|
|
181
|
+
api_key: str = None,
|
|
182
|
+
**kwargs) -> Assistant:
|
|
183
|
+
"""Get the `Assistant`.
|
|
184
|
+
|
|
185
|
+
Args:
|
|
186
|
+
assistant_id (str): The assistant id.
|
|
187
|
+
workspace (str): The dashscope workspace id.
|
|
188
|
+
api_key (str, optional): The api key. Defaults to None.
|
|
189
|
+
|
|
190
|
+
Returns:
|
|
191
|
+
Assistant: The `Assistant` object.
|
|
192
|
+
"""
|
|
193
|
+
if not assistant_id:
|
|
194
|
+
raise ModelRequired('assistant_id is required!')
|
|
195
|
+
response = super().get(assistant_id,
|
|
196
|
+
workspace=workspace,
|
|
197
|
+
api_key=api_key,
|
|
198
|
+
flattened_output=True,
|
|
199
|
+
**kwargs)
|
|
200
|
+
return Assistant(**response)
|
|
201
|
+
|
|
202
|
+
@classmethod
|
|
203
|
+
def list(cls,
|
|
204
|
+
*,
|
|
205
|
+
limit: int = None,
|
|
206
|
+
order: str = None,
|
|
207
|
+
after: str = None,
|
|
208
|
+
before: str = None,
|
|
209
|
+
workspace: str = None,
|
|
210
|
+
api_key: str = None,
|
|
211
|
+
**kwargs) -> AssistantList:
|
|
212
|
+
"""List assistants
|
|
213
|
+
|
|
214
|
+
Args:
|
|
215
|
+
limit (int, optional): How many assistant to retrieve. Defaults to None.
|
|
216
|
+
order (str, optional): Sort order by created_at. Defaults to None.
|
|
217
|
+
after (str, optional): Assistant id after. Defaults to None.
|
|
218
|
+
before (str, optional): Assistant id before. Defaults to None.
|
|
219
|
+
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
|
220
|
+
api_key (str, optional): Your DashScope api key. Defaults to None.
|
|
221
|
+
|
|
222
|
+
Returns:
|
|
223
|
+
AssistantList: The list of assistants.
|
|
224
|
+
"""
|
|
225
|
+
response = super().list(limit=limit,
|
|
226
|
+
order=order,
|
|
227
|
+
after=after,
|
|
228
|
+
before=before,
|
|
229
|
+
workspace=workspace,
|
|
230
|
+
api_key=api_key,
|
|
231
|
+
flattened_output=True,
|
|
232
|
+
**kwargs)
|
|
233
|
+
return AssistantList(**response)
|
|
234
|
+
|
|
235
|
+
@classmethod
|
|
236
|
+
def update(cls,
|
|
237
|
+
assistant_id: str,
|
|
238
|
+
*,
|
|
239
|
+
model: str = None,
|
|
240
|
+
name: str = None,
|
|
241
|
+
description: str = None,
|
|
242
|
+
instructions: str = None,
|
|
243
|
+
tools: Optional[List[Dict]] = None,
|
|
244
|
+
file_ids: Optional[List[str]] = [],
|
|
245
|
+
metadata: Dict = None,
|
|
246
|
+
workspace: str = None,
|
|
247
|
+
api_key: str = None,
|
|
248
|
+
top_p: Optional[float] = None,
|
|
249
|
+
top_k: Optional[int] = None,
|
|
250
|
+
temperature: Optional[float] = None,
|
|
251
|
+
max_tokens: Optional[int] = None,
|
|
252
|
+
**kwargs) -> Assistant:
|
|
253
|
+
"""Update an exist assistants
|
|
254
|
+
|
|
255
|
+
Args:
|
|
256
|
+
assistant_id (str): The target assistant id.
|
|
257
|
+
model (str): The model to use.
|
|
258
|
+
name (str, optional): The assistant name. Defaults to None.
|
|
259
|
+
description (str, optional): The assistant description . Defaults to None.
|
|
260
|
+
instructions (str, optional): The system instructions this assistant uses.. Defaults to None.
|
|
261
|
+
tools (Optional[str], optional): List of tools to use.. Defaults to [].
|
|
262
|
+
file_ids (Optional[str], optional): The files to use in assistants.. Defaults to [].
|
|
263
|
+
metadata (Dict, optional): Custom key-value pairs associate with assistant. Defaults to None.
|
|
264
|
+
workspace (str): The DashScope workspace id.
|
|
265
|
+
api_key (str, optional): The DashScope workspace id. Defaults to None.
|
|
266
|
+
top_p (float, optional): top_p parameter for model. Defaults to None.
|
|
267
|
+
top_k (int, optional): top_p parameter for model. Defaults to None.
|
|
268
|
+
temperature (float, optional): temperature parameter for model. Defaults to None.
|
|
269
|
+
max_tokens (int, optional): max_tokens parameter for model. Defaults to None.
|
|
270
|
+
|
|
271
|
+
Returns:
|
|
272
|
+
Assistant: The updated assistant.
|
|
273
|
+
"""
|
|
274
|
+
if not assistant_id:
|
|
275
|
+
raise ModelRequired('assistant_id is required!')
|
|
276
|
+
response = super().update(assistant_id,
|
|
277
|
+
cls._create_assistant_object(
|
|
278
|
+
model, name, description, instructions,
|
|
279
|
+
tools, file_ids, metadata, top_p, top_k, temperature, max_tokens),
|
|
280
|
+
api_key=api_key,
|
|
281
|
+
workspace=workspace,
|
|
282
|
+
flattened_output=True,
|
|
283
|
+
method='post',
|
|
284
|
+
**kwargs)
|
|
285
|
+
return Assistant(**response)
|
|
286
|
+
|
|
287
|
+
@classmethod
|
|
288
|
+
def delete(cls,
|
|
289
|
+
assistant_id: str,
|
|
290
|
+
*,
|
|
291
|
+
workspace: str = None,
|
|
292
|
+
api_key: str = None,
|
|
293
|
+
**kwargs) -> DeleteResponse:
|
|
294
|
+
"""Delete uploaded file.
|
|
295
|
+
|
|
296
|
+
Args:
|
|
297
|
+
assistant_id (str): The assistant id want to delete.
|
|
298
|
+
workspace (str): The DashScope workspace id.
|
|
299
|
+
api_key (str, optional): The api key. Defaults to None.
|
|
300
|
+
|
|
301
|
+
Returns:
|
|
302
|
+
AssistantsDeleteResponse: Delete result.
|
|
303
|
+
"""
|
|
304
|
+
if not assistant_id:
|
|
305
|
+
raise ModelRequired('assistant_id is required!')
|
|
306
|
+
response = super().delete(assistant_id,
|
|
307
|
+
api_key=api_key,
|
|
308
|
+
workspace=workspace,
|
|
309
|
+
flattened_output=True,
|
|
310
|
+
**kwargs)
|
|
311
|
+
return DeleteResponse(**response)
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
from dashscope.assistants.assistant_types import (AssistantFile,
|
|
5
|
+
AssistantFileList,
|
|
6
|
+
DeleteResponse)
|
|
7
|
+
from dashscope.client.base_api import (CreateMixin, DeleteMixin,
|
|
8
|
+
GetStatusMixin, ListObjectMixin)
|
|
9
|
+
from dashscope.common.error import InputRequired
|
|
10
|
+
|
|
11
|
+
__all__ = ['Files']
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Files(CreateMixin, DeleteMixin, ListObjectMixin, GetStatusMixin):
|
|
15
|
+
SUB_PATH = 'assistants'
|
|
16
|
+
|
|
17
|
+
@classmethod
|
|
18
|
+
def call(cls,
|
|
19
|
+
assistant_id: str,
|
|
20
|
+
*,
|
|
21
|
+
file_id: str,
|
|
22
|
+
workspace: str = None,
|
|
23
|
+
api_key: str = None,
|
|
24
|
+
**kwargs) -> AssistantFile:
|
|
25
|
+
"""Create assistant file.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
assistant_id (str): The target assistant id.
|
|
29
|
+
file_id (str): The file id.
|
|
30
|
+
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
|
31
|
+
api_key (str, optional): The DashScope api key. Defaults to None.
|
|
32
|
+
|
|
33
|
+
Raises:
|
|
34
|
+
InputRequired: The assistant id and file id are required.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
AssistantFile: The assistant file object.
|
|
38
|
+
"""
|
|
39
|
+
return cls.create(assistant_id,
|
|
40
|
+
file_id=file_id,
|
|
41
|
+
workspace=workspace,
|
|
42
|
+
api_key=api_key,
|
|
43
|
+
**kwargs)
|
|
44
|
+
|
|
45
|
+
@classmethod
|
|
46
|
+
def create(cls,
|
|
47
|
+
assistant_id: str,
|
|
48
|
+
*,
|
|
49
|
+
file_id: str,
|
|
50
|
+
workspace: str = None,
|
|
51
|
+
api_key: str = None,
|
|
52
|
+
**kwargs) -> AssistantFile:
|
|
53
|
+
"""Create assistant file.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
assistant_id (str): The target assistant id.
|
|
57
|
+
file_id (str): The file id.
|
|
58
|
+
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
|
59
|
+
api_key (str, optional): The DashScope api key. Defaults to None.
|
|
60
|
+
|
|
61
|
+
Raises:
|
|
62
|
+
InputRequired: The assistant id and file id is required.
|
|
63
|
+
|
|
64
|
+
Returns:
|
|
65
|
+
AssistantFile: _description_
|
|
66
|
+
"""
|
|
67
|
+
if not file_id or not assistant_id:
|
|
68
|
+
raise InputRequired('input file_id and assistant_id is required!')
|
|
69
|
+
|
|
70
|
+
response = super().call(data={'file_id': file_id},
|
|
71
|
+
path=f'assistants/{assistant_id}/files',
|
|
72
|
+
api_key=api_key,
|
|
73
|
+
flattened_output=True,
|
|
74
|
+
workspace=workspace,
|
|
75
|
+
**kwargs)
|
|
76
|
+
return AssistantFile(**response)
|
|
77
|
+
|
|
78
|
+
@classmethod
|
|
79
|
+
def list(cls,
|
|
80
|
+
assistant_id: str,
|
|
81
|
+
*,
|
|
82
|
+
limit: int = None,
|
|
83
|
+
order: str = None,
|
|
84
|
+
after: str = None,
|
|
85
|
+
before: str = None,
|
|
86
|
+
workspace: str = None,
|
|
87
|
+
api_key: str = None,
|
|
88
|
+
**kwargs) -> AssistantFileList:
|
|
89
|
+
"""List assistant files.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
assistant_id (str): The assistant id.
|
|
93
|
+
limit (int, optional): How many assistant to retrieve. Defaults to None.
|
|
94
|
+
order (str, optional): Sort order by created_at. Defaults to None.
|
|
95
|
+
after (str, optional): Assistant id after. Defaults to None.
|
|
96
|
+
before (str, optional): Assistant id before. Defaults to None.
|
|
97
|
+
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
|
98
|
+
api_key (str, optional): Your DashScope api key. Defaults to None.
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
ListAssistantFile: The list of file objects.
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
response = super().list(limit=limit,
|
|
105
|
+
order=order,
|
|
106
|
+
after=after,
|
|
107
|
+
before=before,
|
|
108
|
+
path=f'assistants/{assistant_id}/files',
|
|
109
|
+
api_key=api_key,
|
|
110
|
+
flattened_output=True,
|
|
111
|
+
workspace=workspace,
|
|
112
|
+
**kwargs)
|
|
113
|
+
return AssistantFileList(**response)
|
|
114
|
+
|
|
115
|
+
@classmethod
|
|
116
|
+
def retrieve(cls,
|
|
117
|
+
file_id: str,
|
|
118
|
+
*,
|
|
119
|
+
assistant_id: str,
|
|
120
|
+
workspace: str = None,
|
|
121
|
+
api_key: str = None,
|
|
122
|
+
**kwargs) -> AssistantFile:
|
|
123
|
+
"""Retrieve file information.
|
|
124
|
+
|
|
125
|
+
Args:
|
|
126
|
+
file_id (str): The file if.
|
|
127
|
+
assistant_id (str): The assistant id of the file.
|
|
128
|
+
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
|
129
|
+
api_key (str, optional): Your DashScope api key. Defaults to None.
|
|
130
|
+
|
|
131
|
+
Returns:
|
|
132
|
+
AssistantFile: The `AssistantFile` object.
|
|
133
|
+
"""
|
|
134
|
+
if not assistant_id or not file_id:
|
|
135
|
+
raise InputRequired('assistant id and file id are required!')
|
|
136
|
+
response = super().get(
|
|
137
|
+
file_id,
|
|
138
|
+
path=f'assistants/{assistant_id}/files/{file_id}',
|
|
139
|
+
api_key=api_key,
|
|
140
|
+
flattened_output=True,
|
|
141
|
+
workspace=workspace,
|
|
142
|
+
**kwargs)
|
|
143
|
+
return AssistantFile(**response)
|
|
144
|
+
|
|
145
|
+
@classmethod
|
|
146
|
+
def get(cls,
|
|
147
|
+
file_id: str,
|
|
148
|
+
*,
|
|
149
|
+
assistant_id: str,
|
|
150
|
+
workspace: str = None,
|
|
151
|
+
api_key: str = None,
|
|
152
|
+
**kwargs) -> Optional[AssistantFile]:
|
|
153
|
+
"""Retrieve file information.
|
|
154
|
+
|
|
155
|
+
Args:
|
|
156
|
+
file_id (str): The file if.
|
|
157
|
+
assistant_id (str): The assistant id of the file.
|
|
158
|
+
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
|
159
|
+
api_key (str, optional): Your DashScope api key. Defaults to None.
|
|
160
|
+
|
|
161
|
+
Returns:
|
|
162
|
+
AssistantFile: The `AssistantFile` object.
|
|
163
|
+
"""
|
|
164
|
+
response = super().get(target=assistant_id + '/files/' + file_id, api_key=api_key, workspace=workspace, **kwargs)
|
|
165
|
+
if response.status_code == 200 and response.output:
|
|
166
|
+
return AssistantFile(**response.output)
|
|
167
|
+
else:
|
|
168
|
+
return None
|
|
169
|
+
|
|
170
|
+
@classmethod
|
|
171
|
+
def delete(cls,
|
|
172
|
+
file_id: str,
|
|
173
|
+
*,
|
|
174
|
+
assistant_id: str,
|
|
175
|
+
workspace: str = None,
|
|
176
|
+
api_key: str = None,
|
|
177
|
+
**kwargs) -> DeleteResponse:
|
|
178
|
+
"""Delete the `file_id`.
|
|
179
|
+
|
|
180
|
+
Args:
|
|
181
|
+
file_id (str): The file to be deleted.
|
|
182
|
+
assistant_id (str): The assistant id of the file.
|
|
183
|
+
workspace (str, optional): The DashScope workspace id. Defaults to None.
|
|
184
|
+
api_key (str, optional): Your DashScope api key. Defaults to None.
|
|
185
|
+
|
|
186
|
+
Returns:
|
|
187
|
+
AssistantsDeleteResponse: _description_
|
|
188
|
+
"""
|
|
189
|
+
|
|
190
|
+
response = super().delete(
|
|
191
|
+
file_id,
|
|
192
|
+
path=f'assistants/{assistant_id}/files/{file_id}',
|
|
193
|
+
api_key=api_key,
|
|
194
|
+
flattened_output=True,
|
|
195
|
+
workspace=workspace,
|
|
196
|
+
**kwargs)
|
|
197
|
+
return DeleteResponse(**response)
|
dashscope/audio/__init__.py
CHANGED
dashscope/audio/asr/__init__.py
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
|
+
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
2
|
+
|
|
3
|
+
from .asr_phrase_manager import AsrPhraseManager
|
|
1
4
|
from .recognition import Recognition, RecognitionCallback, RecognitionResult
|
|
2
5
|
from .transcription import Transcription
|
|
6
|
+
from .translation_recognizer import (TranscriptionResult, Translation,
|
|
7
|
+
TranslationRecognizerCallback,
|
|
8
|
+
TranslationRecognizerChat,
|
|
9
|
+
TranslationRecognizerRealtime,
|
|
10
|
+
TranslationRecognizerResultPack,
|
|
11
|
+
TranslationResult)
|
|
12
|
+
from .vocabulary import VocabularyService, VocabularyServiceException
|
|
3
13
|
|
|
4
|
-
__all__ = [
|
|
14
|
+
__all__ = [
|
|
15
|
+
'Transcription', 'Recognition', 'RecognitionCallback', 'RecognitionResult',
|
|
16
|
+
'AsrPhraseManager', 'VocabularyServiceException', 'VocabularyService',
|
|
17
|
+
'TranslationRecognizerRealtime', 'TranslationRecognizerChat',
|
|
18
|
+
'TranslationRecognizerCallback', 'Translation', 'TranslationResult',
|
|
19
|
+
'TranscriptionResult', 'TranslationRecognizerResultPack'
|
|
20
|
+
]
|