Legacy 1.x API¶
The 1.x API classes are archived under dashscope.legacy_1x and remain
importable from the dashscope root module for backward compatibility
(from dashscope import Generation still works). The layer is frozen: it
receives no new features. New code should use the new Client.
Frozen layer
The 1.x surface receives no new features. Assistants / Threads
additionally emit DeprecationWarning on access.
Text generation¶
Generation
¶
Bases: BaseApi
task
class-attribute
instance-attribute
¶
task = 'text-generation'
API for AI-Generated Content(AIGC) models.
Models
¶
@deprecated, use qwen_turbo instead
call
classmethod
¶
call(
model: str,
prompt: Any = None,
history: list | None = None,
api_key: str | None = None,
messages: List[Message] | None = None,
plugins: Union[str, Dict[str, Any], None] = None,
workspace: str | None = None,
stream: bool | None = None,
temperature: float | None = None,
top_p: float | None = None,
top_k: int | None = None,
max_tokens: int | None = None,
seed: int | None = None,
stop: Union[str, List[str], None] = None,
repetition_penalty: float | None = None,
presence_penalty: float | None = None,
result_format: str | None = None,
incremental_output: bool | None = None,
enable_search: bool | None = None,
tools: List[Dict[str, Any]] | None = None,
tool_choice: Union[str, Dict[str, Any], None] = None,
enable_thinking: bool | None = None,
thinking_budget: int | None = None,
n: int | None = None,
logprobs: bool | None = None,
top_logprobs: int | None = None,
search_options: Dict[str, Any] | None = None,
parallel_tool_calls: bool | None = None,
response_format: Dict[str, Any] | None = None,
output_format: str | None = None,
**kwargs: Any
) -> Union[
GenerationResponse,
Generator[GenerationResponse, None, None],
]
Call generation model service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The requested model, such as qwen-turbo. |
required |
prompt
|
Any
|
The input prompt. |
None
|
history
|
list
|
The user provided history, deprecated. |
None
|
api_key
|
str
|
The api api_key, can be None. |
None
|
messages
|
list
|
The generation messages. |
None
|
plugins
|
Any
|
The plugin config, str or dict. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
stream
|
bool
|
Enable streaming output. |
None
|
temperature
|
float
|
Controls randomness, range [0, 2). |
None
|
top_p
|
float
|
Nucleus sampling, range (0, 1.0]. |
None
|
top_k
|
int
|
Size of candidate token set for sampling. |
None
|
max_tokens
|
int
|
Maximum output token count. |
None
|
seed
|
int
|
Random seed for reproducibility. |
None
|
stop
|
str or list
|
Stop sequences. |
None
|
repetition_penalty
|
float
|
Penalizes repeated sequences. 1.0 means no penalty. |
None
|
presence_penalty
|
float
|
Controls content repetition, range [-2.0, 2.0]. |
None
|
result_format
|
str
|
"message" or "text". |
None
|
incremental_output
|
bool
|
In streaming mode, output only new tokens (True) vs. cumulative output (False). |
None
|
enable_search
|
bool
|
Enable web search. |
None
|
tools
|
list
|
Tool definitions for function calling. |
None
|
tool_choice
|
str or dict
|
Tool selection strategy. |
None
|
enable_thinking
|
bool
|
Enable thinking mode for hybrid thinking models. |
None
|
thinking_budget
|
int
|
Maximum token budget for thinking mode. Controls the maximum length of thinking process. |
None
|
n
|
int
|
Number of responses to generate (1-4). |
None
|
logprobs
|
bool
|
Whether to return log probabilities of the output tokens. |
None
|
top_logprobs
|
int
|
Number of most likely tokens to return at each token position when logprobs is enabled. |
None
|
search_options
|
dict
|
Configuration options for web search feature. |
None
|
parallel_tool_calls
|
bool
|
Enable parallel tool calls for function calling. |
None
|
response_format
|
dict
|
Format constraint for response, e.g., {"type": "json_object"} for JSON mode. |
None
|
output_format
|
str
|
Output format for qwen-deep-research model. Options: "model_detailed_report" (default), "model_summary_report". |
None
|
**kwargs
|
Any
|
Additional parameters passed to the API. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[GenerationResponse, Generator[GenerationResponse, None, None]]
|
Union[GenerationResponse, Generator[GenerationResponse, None, None]]: If |
Union[GenerationResponse, Generator[GenerationResponse, None, None]]
|
stream is True, return Generator, otherwise GenerationResponse. |
Source code in dashscope/legacy_1x/aigc/generation.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
AioGeneration
¶
Bases: BaseAioApi
task
class-attribute
instance-attribute
¶
task = 'text-generation'
API for AI-Generated Content(AIGC) models.
Models
¶
@deprecated, use qwen_turbo instead
call
async
classmethod
¶
call(
model: str,
prompt: Any = None,
history: list | None = None,
api_key: str | None = None,
messages: List[Message] | None = None,
plugins: Union[str, Dict[str, Any]] = None,
workspace: str = None,
stream: bool = None,
temperature: float = None,
top_p: float = None,
top_k: int = None,
max_tokens: int = None,
seed: int = None,
stop: Union[str, List] = None,
repetition_penalty: float = None,
presence_penalty: float = None,
result_format: str = None,
incremental_output: bool = None,
enable_search: bool = None,
tools: List[Dict[str, Any]] = None,
tool_choice: Union[str, Dict[str, Any]] = None,
enable_thinking: bool = None,
thinking_budget: int = None,
n: int = None,
logprobs: bool = None,
top_logprobs: int = None,
search_options: Dict[str, Any] = None,
parallel_tool_calls: bool = None,
response_format: Dict[str, Any] = None,
output_format: str = None,
**kwargs: Any
) -> Union[
GenerationResponse,
Generator[GenerationResponse, None, None],
]
Call generation model service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The requested model, such as qwen-turbo. |
required |
prompt
|
Any
|
The input prompt. |
None
|
history
|
list
|
The user provided history, deprecated. |
None
|
api_key
|
str
|
The api api_key, can be None. |
None
|
messages
|
list
|
The generation messages. |
None
|
plugins
|
Any
|
The plugin config, str or dict. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
stream
|
bool
|
Enable streaming output. |
None
|
temperature
|
float
|
Controls randomness, range [0, 2). |
None
|
top_p
|
float
|
Nucleus sampling, range (0, 1.0]. |
None
|
top_k
|
int
|
Size of candidate token set for sampling. |
None
|
max_tokens
|
int
|
Maximum output token count. |
None
|
seed
|
int
|
Random seed for reproducibility. |
None
|
stop
|
str or list
|
Stop sequences. |
None
|
repetition_penalty
|
float
|
Penalizes repeated sequences. |
None
|
presence_penalty
|
float
|
Controls content repetition. |
None
|
result_format
|
str
|
"message" or "text". |
None
|
incremental_output
|
bool
|
In streaming mode, output only new tokens (True) vs. cumulative output (False). |
None
|
enable_search
|
bool
|
Enable web search. |
None
|
tools
|
list
|
Tool definitions for function calling. |
None
|
tool_choice
|
str or dict
|
Tool selection strategy. |
None
|
enable_thinking
|
bool
|
Enable thinking mode. |
None
|
thinking_budget
|
int
|
Maximum token budget for thinking mode. Controls the maximum length of thinking process. |
None
|
n
|
int
|
Number of responses to generate (1-4). |
None
|
logprobs
|
bool
|
Whether to return log probabilities of the output tokens. |
None
|
top_logprobs
|
int
|
Number of most likely tokens to return at each token position when logprobs is enabled. |
None
|
search_options
|
dict
|
Configuration options for web search feature. |
None
|
parallel_tool_calls
|
bool
|
Enable parallel tool calls for function calling. |
None
|
response_format
|
dict
|
Format constraint for response, e.g., {"type": "json_object"} for JSON mode. |
None
|
output_format
|
str
|
Output format for qwen-deep-research model. Options: "model_detailed_report" (default), "model_summary_report". |
None
|
**kwargs
|
Any
|
Additional parameters passed to the API. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[GenerationResponse, Generator[GenerationResponse, None, None]]
|
Union[GenerationResponse, AsyncGenerator[GenerationResponse, None]]: If |
Union[GenerationResponse, Generator[GenerationResponse, None, None]]
|
stream is True, return AsyncGenerator, else GenerationResponse. |
Source code in dashscope/legacy_1x/aigc/generation.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | |
CodeGeneration
¶
Bases: BaseApi
function
class-attribute
instance-attribute
¶
function = 'generation'
API for AI-Generated Content(AIGC) models.
Models
¶
Scenes
¶
call
classmethod
¶
call(
model: str,
scene: str = None,
api_key: str = None,
message: List[MessageParam] = None,
workspace: str = None,
**kwargs: Any
) -> Any
Call generation model service.
Args:
model (str): The requested model, such as tongyi-lingma-v1
scene (str): Scene type, single choice, such as custom
examples:
custom:User defined prompt
nl2code:Natural language generated code
code2comment:annotation
code2explain:explain
commit2msg:Automatically generate commit
uinttest:Generating Unit Tests
codeqa:Code Q&A
nl2sql:Generate SQL code using natural language
api_key (str, optional): The api api_key, can be None,
if None, will get by default rule(TODO: api key doc).
message (list): The generation messages.
scene == custom, examples:
[{"role": "user", "content": "根据下面的功能描述生成一个python函数。代码的功能是计算给定路径下所有文件的总大小。"}] # noqa E501 # pylint: disable=line-too-long
scene == nl2code, examples:
[{"role": "user", "content": "计算给定路径下所有文件的总大小"}, {"role": "attachment", "meta": {"language": "java"}}] # noqa E501 # pylint: disable=line-too-long
scene == code2comment, examples:
[{"role": "user", "content": "1. 生成中文注释
- 仅生成代码部分,不需要额外解释函数功能 "}, {"role": "attachment", "meta": {"code": " @Override public CancelExportTaskResponse cancelExportTask( CancelExportTask cancelExportTask) { AmazonEC2SkeletonInterface ec2Service = ServiceProvider.getInstance().getServiceImpl(AmazonEC2SkeletonInterface.class); return ec2Service.cancelExportTask(cancelExportTask); }", "language": "java"}}] # noqa E501 # pylint: disable=line-too-long scene == code2explain, examples: [{"role": "user", "content": "要求不低于200字"}, {"role": "attachment", "meta": {"code": "@Override public int getHeaderCacheSize() { return 0; }
", "language": "java"}}] # noqa E501 # pylint: disable=line-too-long scene == commit2msg, examples: [{"role": "attachment", "meta": {"diff_list": [{"diff": "--- src/com/siondream/core/PlatformResolver.java +++ src/com/siondream/core/PlatformResolver.java @@ -1,11 +1,8 @@ package com.siondream.core; - -import com.badlogic.gdx.files.FileHandle;
public interface PlatformResolver {
public void openURL(String url);
public void rateApp();
public void sendFeedback();
- public FileHandle[] listFolder(String path);
}
", "old_file_path": "src/com/siondream/core/PlatformResolver.java", "new_file_path": "src/com/siondream/core/PlatformResolver.java"}]}}] # noqa E501 # pylint: disable=line-too-long
scene == unittest, examples:
[{"role": "attachment", "meta": {"code": "public static
if (input == null) {
return null;
}
TimestampMap result;
typeClass = AttributeUtils.getStandardizedType(typeClass);
if (typeClass.equals(String.class)) {
result = new TimestampStringMap();
} else if (typeClass.equals(Byte.class)) {
result = new TimestampByteMap();
} else if (typeClass.equals(Short.class)) {
result = new TimestampShortMap();
} else if (typeClass.equals(Integer.class)) {
result = new TimestampIntegerMap();
} else if (typeClass.equals(Long.class)) {
result = new TimestampLongMap();
} else if (typeClass.equals(Float.class)) {
result = new TimestampFloatMap();
} else if (typeClass.equals(Double.class)) {
result = new TimestampDoubleMap();
} else if (typeClass.equals(Boolean.class)) {
result = new TimestampBooleanMap();
} else if (typeClass.equals(Character.class)) {
result = new TimestampCharMap();
} else {
throw new IllegalArgumentException("Unsupported type " + typeClass.getClass().getCanonicalName());
}
if (input.equalsIgnoreCase(EMPTY_VALUE)) {
return result;
}
StringReader reader = new StringReader(input + ' ');// Add 1 space so
// reader.skip
// function always
// works when
// necessary (end of
// string not
// reached).
try {
int r;
char c;
while ((r = reader.read()) != -1) {
c = (char) r;
switch (c) {
case LEFT_BOUND_SQUARE_BRACKET:
case LEFT_BOUND_BRACKET:
parseTimestampAndValue(typeClass, reader, result, timeZone);
break;
default:
// Ignore other chars outside of bounds
}
}
} catch (IOException ex) {
throw new RuntimeException("Unexpected expection while parsing timestamps", ex);
}
return result;
}", "language": "java"}}] # noqa E501 # pylint: disable=line-too-long
scene == codeqa, examples:
[{"role": "user", "content": "I'm writing a small web server in Python, using BaseHTTPServer and a custom subclass of BaseHTTPServer.BaseHTTPRequestHandler. Is it possible to make this listen on more than one port?
What I'm doing now: class MyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): def doGET [...]
class ThreadingHTTPServer(ThreadingMixIn, HTTPServer): pass
server = ThreadingHTTPServer(('localhost', 80), MyRequestHandler)
server.serve_forever()"}] # noqa E501 # pylint: disable=line-too-long
scene == nl2sql, examples:
[{"role": "user", "content": "小明的总分数是多少"}, {"role": "attachment", "meta": {"synonym_infos": {"学生姓名": "姓名|名字|名称", "学生分数": "分数|得分"}, "recall_infos": [{"content": "student_score.id='小明'", "score": "0.83"}], "schema_infos": [{"table_id": "student_score", "table_desc": "学生分数表", "columns": [{"col_name": "id", "col_caption": "学生id", "col_desc": "例值为:1,2,3", "col_type": "string"}, {"col_name": "name", "col_caption": "学生姓名", "col_desc": "例值为:张三,李四,小明", "col_type": "string"}, {"col_name": "score", "col_caption": "学生分数", "col_desc": "例值为:98,100,66", "col_type": "string"}]}]}}] # noqa E501 # pylint: disable=line-too-long
workspace (str): The dashscope workspace id.
**kwargs:
n(
int,
optional
): The number of output results, currently only supports 1, with a default value of 1 # noqa E501
Returns:
Union[DashScopeAPIResponse,
Generator[DashScopeAPIResponse, None, None]]: If
stream is True, return Generator, otherwise DashScopeAPIResponse.
Source code in dashscope/legacy_1x/aigc/code_generation.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
Conversation
¶
Conversation(history: History | None = None)
Bases: BaseApi
Conversational robot interface.
Init a chat.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
history
|
dict
|
The conversation initialization settings. will be recorded in the system history list. Defaults to None. |
None
|
Source code in dashscope/legacy_1x/aigc/conversation.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
Models
¶
@deprecated, use qwen_turbo instead
call
¶
call(
model: str,
prompt: Any = None,
history: History | None = None,
auto_history: bool = False,
n_history: int = -1,
api_key: str = None,
messages: List[Message] = None,
plugins: Union[str, Dict[str, Any]] = None,
workspace: str = None,
**kwargs: Any
) -> Union[
ConversationResponse,
Generator[ConversationResponse, None, None],
]
Call conversational robot generator a response.
Note: This method overrides BaseApi.call() as an instance method instead of a classmethod because Conversation maintains instance state (self.history). Pylint's arguments-renamed warning is disabled because the first parameter changes from 'cls' (in the classmethod) to 'self' (in the instance method). The type checker is instructed to ignore the signature incompatibility via type: ignore[override].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The request model. |
required |
prompt
|
Any
|
The input prompt. |
None
|
history
|
History
|
The user provided history.
Only works for this call, will not be recorded in the
system history list. The |
None
|
auto_history
|
bool
|
Call with the automatically maintenance
conversation history list. The |
False
|
n_history
|
int
|
Number of latest history in conversation, -1 all history. Default to -1 |
-1
|
api_key
|
str
|
The api api_key, if not present, will get by default rule(TODO: api key doc). Defaults to None. |
None
|
messages
|
list
|
The generation messages. examples: [{'role': 'user', 'content': 'The weather is fine today.'}, {'role': 'assistant', 'content': 'Suitable for outings'}] |
None
|
plugins
|
Any
|
The plugin config, Can be plugins config str, or dict. |
None
|
**kwargs
|
(qwen - turbo, qwen - plus)
|
stream(bool, |
{}
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Raises: InputRequired: The prompt cannot be empty. InvalidInput: The history and auto_history are mutually exclusive.
Returns:
| Type | Description |
|---|---|
Union[ConversationResponse, Generator[ConversationResponse, None, None]]
|
Union[ConversationResponse, Generator[ConversationResponse, None, None]]: If |
Union[ConversationResponse, Generator[ConversationResponse, None, None]]
|
stream is True, return Generator, otherwise ConversationResponse. |
Source code in dashscope/legacy_1x/aigc/conversation.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
History
¶
History(items: List[HistoryItem] = None)
Bases: list
Manage the conversation history.
Init a history with list of HistoryItems.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
List[HistoryItem]
|
The history items. Defaults to None. |
None
|
Source code in dashscope/legacy_1x/aigc/conversation.py
64 65 66 67 68 69 70 71 72 73 74 75 | |
HistoryItem
¶
HistoryItem(role: str, text: str = None, **kwargs)
Bases: dict
A conversation history item.
Init a history item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
role
|
str
|
The role name. |
required |
text
|
str
|
The text history. Default ot None. |
None
|
**kwargs
|
Any
|
The key/value pair of history content. |
{}
|
Raises:
| Type | Description |
|---|---|
InvalidInput
|
The key and value must pair. |
Source code in dashscope/legacy_1x/aigc/conversation.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
add
¶
add(key: str, content: Any)
Add a key/value to history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key of the content. |
required |
content
|
Any
|
The history content. |
required |
Source code in dashscope/legacy_1x/aigc/conversation.py
51 52 53 54 55 56 57 58 | |
Multimodal conversation¶
MultiModalConversation
¶
Bases: BaseApi
MultiModal conversational robot interface.
call
classmethod
¶
call(
model: str,
messages: List[Any] | None = None,
api_key: str | None = None,
workspace: str | None = None,
text: str | None = None,
voice: str | None = None,
language_type: str = None,
stream: bool | None = None,
temperature: float | None = None,
top_p: float | None = None,
top_k: int | None = None,
max_tokens: int | None = None,
seed: int | None = None,
stop: Union[str, List[str], None] = None,
repetition_penalty: float = None,
presence_penalty: float = None,
result_format: str | None = None,
incremental_output: bool | None = None,
enable_search: bool | None = None,
tools: List[Dict[str, Any]] | None = None,
tool_choice: Union[str, Dict[str, Any], None] = None,
enable_thinking: bool | None = None,
n: int | None = None,
ocr_options: Dict[str, Any] | None = None,
logprobs: bool | None = None,
top_logprobs: int | None = None,
**kwargs: Any
) -> Union[
MultiModalConversationResponse,
Generator[MultiModalConversationResponse, None, None],
]
Call the conversation model service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The requested model, such as 'qwen-vl-max'. |
required |
messages
|
list
|
The generation messages. |
None
|
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
text
|
str
|
The text to generate. |
None
|
voice
|
str
|
The voice name for qwen tts. |
None
|
language_type
|
str
|
The synthesized language type. |
None
|
stream
|
bool
|
Enable streaming output. |
None
|
temperature
|
float
|
Controls randomness, range [0, 2). |
None
|
top_p
|
float
|
Nucleus sampling, range (0, 1.0]. |
None
|
top_k
|
int
|
Size of candidate token set for sampling. |
None
|
max_tokens
|
int
|
Maximum output token count. |
None
|
seed
|
int
|
Random seed for reproducibility. |
None
|
stop
|
str or list
|
Stop sequences. |
None
|
repetition_penalty
|
float
|
Penalizes repeated sequences. |
None
|
presence_penalty
|
float
|
Controls content repetition. |
None
|
result_format
|
str
|
"message" or "text". |
None
|
incremental_output
|
bool
|
In streaming mode, output only new tokens (True) vs. cumulative output (False). |
None
|
enable_search
|
bool
|
Enable web search. |
None
|
tools
|
list
|
Tool definitions for function calling. |
None
|
tool_choice
|
str or dict
|
Tool selection strategy. |
None
|
enable_thinking
|
bool
|
Enable thinking mode. |
None
|
n
|
int
|
Number of responses to generate (1-4). |
None
|
ocr_options
|
dict
|
OCR task options for qwen-ocr models. |
None
|
logprobs
|
bool
|
Whether to return log probabilities of the output tokens. |
None
|
top_logprobs
|
int
|
Number of most likely tokens to return at each token position. |
None
|
**kwargs
|
Any
|
Additional parameters passed to the API. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[MultiModalConversationResponse, Generator[MultiModalConversationResponse, None, None]]
|
Union[MultiModalConversationResponse, Generator[MultiModalConversationResponse, None, None]]: If |
Union[MultiModalConversationResponse, Generator[MultiModalConversationResponse, None, None]]
|
stream is True, return Generator, otherwise |
Source code in dashscope/legacy_1x/aigc/multimodal_conversation.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
AioMultiModalConversation
¶
Bases: BaseAioApi
Async MultiModal conversational robot interface.
call
async
classmethod
¶
call(
model: str,
messages: List[Any] | None = None,
api_key: str | None = None,
workspace: str | None = None,
text: str = None,
voice: str = None,
language_type: str = None,
stream: bool = None,
temperature: float = None,
top_p: float = None,
top_k: int = None,
max_tokens: int = None,
seed: int = None,
stop: Union[str, List] = None,
repetition_penalty: float = None,
presence_penalty: float = None,
result_format: str = None,
incremental_output: bool = None,
enable_search: bool = None,
tools: List[Dict[str, Any]] = None,
tool_choice: Union[str, Dict[str, Any]] = None,
enable_thinking: bool = None,
n: int = None,
ocr_options: Dict[str, Any] = None,
logprobs: bool = None,
top_logprobs: int = None,
**kwargs: Any
) -> Union[
MultiModalConversationResponse,
Generator[MultiModalConversationResponse, None, None],
]
Call the conversation model service asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The requested model, such as 'qwen-vl-max'. |
required |
messages
|
list
|
The generation messages. |
None
|
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
text
|
str
|
The text to generate. |
None
|
voice
|
str
|
The voice name for qwen tts. |
None
|
language_type
|
str
|
The synthesized language type. |
None
|
stream
|
bool
|
Enable streaming output. |
None
|
temperature
|
float
|
Controls randomness, range [0, 2). |
None
|
top_p
|
float
|
Nucleus sampling, range (0, 1.0]. |
None
|
top_k
|
int
|
Size of candidate token set for sampling. |
None
|
max_tokens
|
int
|
Maximum output token count. |
None
|
seed
|
int
|
Random seed for reproducibility. |
None
|
stop
|
str or list
|
Stop sequences. |
None
|
repetition_penalty
|
float
|
Penalizes repeated sequences. |
None
|
presence_penalty
|
float
|
Controls content repetition. |
None
|
result_format
|
str
|
"message" or "text". |
None
|
incremental_output
|
bool
|
In streaming mode, output only new tokens (True) vs. cumulative output (False). |
None
|
enable_search
|
bool
|
Enable web search. |
None
|
tools
|
list
|
Tool definitions for function calling. |
None
|
tool_choice
|
str or dict
|
Tool selection strategy. |
None
|
enable_thinking
|
bool
|
Enable thinking mode. |
None
|
n
|
int
|
Number of responses to generate (1-4). |
None
|
ocr_options
|
dict
|
OCR task options for qwen-ocr models. |
None
|
logprobs
|
bool
|
Whether to return log probabilities of the output tokens. |
None
|
top_logprobs
|
int
|
Number of most likely tokens to return at each token position. |
None
|
**kwargs
|
Any
|
Additional parameters passed to the API. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[MultiModalConversationResponse, Generator[MultiModalConversationResponse, None, None]]
|
Union[MultiModalConversationResponse, AsyncGenerator[MultiModalConversationResponse, None]]: If |
Union[MultiModalConversationResponse, Generator[MultiModalConversationResponse, None, None]]
|
stream is True, return AsyncGenerator, otherwise |
Source code in dashscope/legacy_1x/aigc/multimodal_conversation.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
Image & video synthesis¶
ImageSynthesis
¶
Bases: BaseAsyncApi
Models
¶
call
classmethod
¶
call(
model: str,
prompt: Any,
negative_prompt: Any = None,
images: List[str] | None = None,
api_key: str | None = None,
sketch_image_url: str = None,
ref_img: str = None,
workspace: str = None,
extra_input: Dict = None,
task: str = None,
function: str = None,
mask_image_url: str = None,
base_image_url: str = None,
size: str | None = None,
n: int | None = None,
seed: int | None = None,
style: str | None = None,
ref_strength: float | None = None,
ref_mode: str = None,
prompt_extend: bool | None = None,
watermark: bool | None = None,
bbox_list: List = None,
enable_sequential: bool = None,
thinking_mode: str = None,
color_palette: str = None,
**kwargs: Any
) -> ImageSynthesisResponse
Call image(s) synthesis service and get result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The model, reference |
required |
prompt
|
Any
|
The prompt for image(s) synthesis. |
required |
negative_prompt
|
Any
|
The negative_prompt. Defaults to None. |
None
|
images
|
List[str]
|
The input list of images url, currently not supported. |
None
|
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
sketch_image_url
|
str
|
Only for wanx-sketch-to-image-v1, can be local file. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
extra_input
|
Dict
|
The extra input parameters. |
None
|
task
|
str
|
The task of api, ref doc. |
None
|
function
|
str
|
The specific functions to be achieved. like: colorization,super_resolution,expand,remove_watermaker,doodle, description_edit_with_mask,description_edit,stylization_local,stylization_all |
None
|
base_image_url
|
str
|
Enter the URL address of the target edited image. |
None
|
mask_image_url
|
str
|
Provide the URL address of the image of the marked area by the user. It should be consistent with the image resolution of the base_image_url. # pylint: disable=line-too-long |
None
|
size
|
str
|
The output image(s) size(width*height). |
None
|
n
|
int
|
Number of images to synthesis. |
None
|
seed
|
int
|
Random seed for image generation. |
None
|
style
|
str
|
The output image style. Supported values:
|
None
|
ref_strength
|
float
|
Control the similarity between output image and reference image. Range [0.0, 1.0]. Higher value means more similar to reference image. |
None
|
ref_mode
|
str
|
Mode for generating image based on reference image. Supported values: repaint (default, based on content), refonly (based on style). |
None
|
prompt_extend
|
bool
|
Whether to extend prompt automatically for better results. |
None
|
watermark
|
bool
|
Whether to add watermark. |
None
|
bbox_list
|
List
|
List of bounding boxes for region-specific editing. |
None
|
enable_sequential
|
bool
|
Enable sequential generation mode. |
None
|
thinking_mode
|
str
|
Thinking mode for generation. Supported values: fast, balanced, quality. |
None
|
color_palette
|
str
|
Color palette specification for consistent styling. |
None
|
**kwargs
|
Any
|
similarity(float, |
{}
|
Raises:
| Type | Description |
|---|---|
InputRequired
|
The prompt cannot be empty. |
Returns:
| Name | Type | Description |
|---|---|---|
ImageSynthesisResponse |
ImageSynthesisResponse
|
The image(s) synthesis result. |
Source code in dashscope/legacy_1x/aigc/image_synthesis.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
sync_call
classmethod
¶
sync_call(
model: str,
prompt: Any,
negative_prompt: Any = None,
images: List[str] | None = None,
api_key: str | None = None,
sketch_image_url: str = None,
ref_img: str = None,
workspace: str = None,
extra_input: Dict = None,
task: str = None,
function: str = None,
mask_image_url: str = None,
base_image_url: str = None,
size: str = None,
n: int = None,
seed: int = None,
style: str = None,
ref_strength: float = None,
ref_mode: str = None,
prompt_extend: bool = None,
watermark: bool = None,
bbox_list: List = None,
enable_sequential: bool = None,
thinking_mode: str = None,
color_palette: str = None,
**kwargs: Any
) -> ImageSynthesisResponse
This method currently now only supports wan2.2-t2i-flash and wan2.2-t2i-plus. # noqa: E501 # pylint: disable=line-too-long
Using other models will result in an error,More raw image models may be added for use later # pylint: disable=line-too-long
Source code in dashscope/legacy_1x/aigc/image_synthesis.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
async_call
classmethod
¶
async_call(
model: str,
prompt: Any,
negative_prompt: Any = None,
images: List[str] | None = None,
api_key: str | None = None,
sketch_image_url: str = None,
ref_img: str = None,
workspace: str = None,
extra_input: Dict = None,
task: str = None,
function: str = None,
mask_image_url: str = None,
base_image_url: str = None,
size: str = None,
n: int = None,
seed: int = None,
style: str = None,
ref_strength: float = None,
ref_mode: str = None,
prompt_extend: bool = None,
watermark: bool = None,
bbox_list: List = None,
enable_sequential: bool = None,
thinking_mode: str = None,
color_palette: str = None,
**kwargs: Any
) -> ImageSynthesisResponse
Create a image(s) synthesis task, and return task information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The model, reference |
required |
prompt
|
Any
|
The prompt for image(s) synthesis. |
required |
negative_prompt
|
Any
|
The negative_prompt. Defaults to None. |
None
|
images
|
List[str]
|
The input list of images url. |
None
|
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
sketch_image_url
|
str
|
Only for wanx-sketch-to-image-v1. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
extra_input
|
Dict
|
The extra input parameters. |
None
|
task
|
str
|
The task of api, ref doc. |
None
|
function
|
str
|
The specific functions to be achieved. |
None
|
mask_image_url
|
str
|
Provide the URL address of the image of the marked area by the user. |
None
|
base_image_url
|
str
|
Enter the URL address of the target edited image. |
None
|
size
|
str
|
The output image(s) size(width*height). |
None
|
seed
|
int
|
Random seed for image generation. |
None
|
style
|
str
|
The output image style. Supported values:
|
None
|
ref_strength
|
float
|
Control the similarity between output image and reference image. Range [0.0, 1.0]. |
None
|
ref_mode
|
str
|
Mode for generating image based on reference image. Supported values: repaint (default, based on content), refonly (based on style). |
None
|
prompt_extend
|
bool
|
Whether to extend prompt automatically for better results. |
None
|
watermark
|
bool
|
Whether to add watermark. |
None
|
bbox_list
|
List
|
List of bounding boxes for region-specific editing. |
None
|
enable_sequential
|
bool
|
Enable sequential generation mode. |
None
|
thinking_mode
|
str
|
Thinking mode for generation. Supported values: fast, balanced, quality. |
None
|
color_palette
|
str
|
Color palette specification for consistent styling. |
None
|
Source code in dashscope/legacy_1x/aigc/image_synthesis.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
fetch
classmethod
¶
fetch(
task: Union[str, ImageSynthesisResponse],
api_key: str | None = None,
workspace: str | None = None,
) -> ImageSynthesisResponse
Fetch image(s) synthesis task status or result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, ImageSynthesisResponse]
|
The task_id or ImageSynthesisResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ImageSynthesisResponse |
ImageSynthesisResponse
|
The task status or result. |
Source code in dashscope/legacy_1x/aigc/image_synthesis.py
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
wait
classmethod
¶
wait(
task: Union[str, ImageSynthesisResponse],
api_key: str | None = None,
workspace: str | None = None,
**kwargs: Any
) -> ImageSynthesisResponse
Wait for image(s) synthesis task to complete, and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, ImageSynthesisResponse]
|
The task_id or ImageSynthesisResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ImageSynthesisResponse |
ImageSynthesisResponse
|
The task result. |
Source code in dashscope/legacy_1x/aigc/image_synthesis.py
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 | |
cancel
classmethod
¶
cancel(
task: Union[str, ImageSynthesisResponse],
api_key: str = None,
workspace: str = None,
) -> DashScopeAPIResponse
Cancel image synthesis task. Only tasks whose status is PENDING can be canceled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, ImageSynthesisResponse]
|
The task_id or ImageSynthesisResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The response data. |
Source code in dashscope/legacy_1x/aigc/image_synthesis.py
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
list
classmethod
¶
list(
start_time: str = None,
end_time: str = None,
model_name: str = None,
api_key_id: str = None,
region: str = None,
status: str = None,
page_no: int = 1,
page_size: int = 10,
api_key: str = None,
workspace: str = None,
**kwargs
) -> DashScopeAPIResponse
List async tasks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_time
|
str
|
The tasks start time, for example: 20230420000000. Defaults to None. |
None
|
end_time
|
str
|
The tasks end time, for example: 20230420000000. Defaults to None. |
None
|
model_name
|
str
|
The tasks model name. Defaults to None. |
None
|
api_key_id
|
str
|
The tasks api-key-id. Defaults to None. |
None
|
region
|
str
|
The service region, for example: cn-beijing. Defaults to None. |
None
|
status
|
str
|
The status of tasks[PENDING, RUNNING, SUCCEEDED, FAILED, CANCELED]. Defaults to None. |
None
|
page_no
|
int
|
The page number. Defaults to 1. |
1
|
page_size
|
int
|
The page size. Defaults to 10. |
10
|
api_key
|
str
|
The user api-key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The response data. |
Source code in dashscope/legacy_1x/aigc/image_synthesis.py
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 | |
AioImageSynthesis
¶
Bases: BaseAsyncAioApi
call
async
classmethod
¶
call(
model: str,
prompt: Any,
negative_prompt: Any = None,
images: List[str] = None,
api_key: str = None,
sketch_image_url: str = None,
ref_img: str = None,
workspace: str = None,
extra_input: Dict = None,
task: str = None,
function: str = None,
mask_image_url: str = None,
base_image_url: str = None,
size: str = None,
n: int = None,
seed: int = None,
style: str = None,
ref_strength: float = None,
ref_mode: str = None,
prompt_extend: bool = None,
watermark: bool = None,
bbox_list: List = None,
enable_sequential: bool = None,
thinking_mode: str = None,
color_palette: str = None,
**kwargs
) -> ImageSynthesisResponse
Call image(s) synthesis service and get result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The model, reference |
required |
prompt
|
Any
|
The prompt for image(s) synthesis. |
required |
negative_prompt
|
Any
|
The negative_prompt. Defaults to None. |
None
|
images
|
List[str]
|
The input list of images url, currently not supported. |
None
|
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
sketch_image_url
|
str
|
Only for wanx-sketch-to-image-v1, can be local file. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
extra_input
|
Dict
|
The extra input parameters. |
None
|
task
|
str
|
The task of api, ref doc. |
None
|
function
|
str
|
The specific functions to be achieved. like: colorization,super_resolution,expand,remove_watermaker,doodle, description_edit_with_mask,description_edit,stylization_local,stylization_all |
None
|
base_image_url
|
str
|
Enter the URL address of the target edited image. |
None
|
mask_image_url
|
str
|
Provide the URL address of the image of the marked area by the user. It should be consistent with the image resolution of the base_image_url. # pylint: disable=line-too-long |
None
|
size
|
str
|
The output image(s) size(width*height). |
None
|
n
|
int
|
Number of images to synthesis. |
None
|
seed
|
int
|
Random seed for image generation. |
None
|
style
|
str
|
The output image style. Supported values:
|
None
|
ref_strength
|
float
|
Control the similarity between output image and reference image. Range [0.0, 1.0]. |
None
|
ref_mode
|
str
|
Mode for generating image based on reference image. Supported values: repaint (default, based on content), refonly (based on style). |
None
|
prompt_extend
|
bool
|
Whether to extend prompt automatically for better results. |
None
|
watermark
|
bool
|
Whether to add watermark. |
None
|
bbox_list
|
List
|
List of bounding boxes for region-specific editing. |
None
|
enable_sequential
|
bool
|
Enable sequential generation mode. |
None
|
thinking_mode
|
str
|
Thinking mode for generation. Supported values: fast, balanced, quality. |
None
|
color_palette
|
str
|
Color palette specification for consistent styling. |
None
|
**kwargs
|
Any
|
similarity(float, |
{}
|
Raises:
| Type | Description |
|---|---|
InputRequired
|
The prompt cannot be empty. |
Returns:
| Name | Type | Description |
|---|---|---|
ImageSynthesisResponse |
ImageSynthesisResponse
|
The image(s) synthesis result. |
Source code in dashscope/legacy_1x/aigc/image_synthesis.py
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 | |
sync_call
async
classmethod
¶
sync_call(
model: str,
prompt: Any,
negative_prompt: Any = None,
images: List[str] = None,
api_key: str = None,
sketch_image_url: str = None,
ref_img: str = None,
workspace: str = None,
extra_input: Dict = None,
task: str = None,
function: str = None,
mask_image_url: str = None,
base_image_url: str = None,
size: str = None,
n: int = None,
seed: int = None,
style: str = None,
ref_strength: float = None,
ref_mode: str = None,
prompt_extend: bool = None,
watermark: bool = None,
bbox_list: List = None,
enable_sequential: bool = None,
thinking_mode: str = None,
color_palette: str = None,
**kwargs
) -> ImageSynthesisResponse
This method currently now only supports wan2.2-t2i-flash and wan2.2-t2i-plus. # noqa: E501 # pylint: disable=line-too-long
Using other models will result in an error,More raw image models may be added for use later # pylint: disable=line-too-long
Source code in dashscope/legacy_1x/aigc/image_synthesis.py
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 | |
async_call
async
classmethod
¶
async_call(
model: str,
prompt: Any,
negative_prompt: Any = None,
images: List[str] = None,
api_key: str = None,
sketch_image_url: str = None,
ref_img: str = None,
workspace: str = None,
extra_input: Dict = None,
task: str = None,
function: str = None,
mask_image_url: str = None,
base_image_url: str = None,
size: str = None,
n: int = None,
seed: int = None,
style: str = None,
ref_strength: float = None,
ref_mode: str = None,
prompt_extend: bool = None,
watermark: bool = None,
bbox_list: List = None,
enable_sequential: bool = None,
thinking_mode: str = None,
color_palette: str = None,
**kwargs
) -> ImageSynthesisResponse
Create a image(s) synthesis task, and return task information.
Note: This method overrides BaseAsyncAioApi.async_call() with renamed parameters to provide a more user-friendly API. The generic parameters (input_data, task_group) are replaced with domain-specific ones (prompt, negative_prompt, images, etc.). Pylint's arguments-renamed warning is disabled for this reason.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The model, reference |
required |
prompt
|
Any
|
The prompt for image(s) synthesis. |
required |
negative_prompt
|
Any
|
The negative_prompt. Defaults to None. |
None
|
images
|
List[str]
|
The input list of images url. |
None
|
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
sketch_image_url
|
str
|
Only for wanx-sketch-to-image-v1. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
extra_input
|
Dict
|
The extra input parameters. |
None
|
task
|
str
|
The task of api, ref doc. |
None
|
function
|
str
|
The specific functions to be achieved. like: colorization,super_resolution,expand,remove_watermaker,doodle, description_edit_with_mask,description_edit,stylization_local,stylization_all |
None
|
base_image_url
|
str
|
Enter the URL address of the target edited image. |
None
|
mask_image_url
|
str
|
Provide the URL address of the image of the marked area by the user. It should be consistent with the image resolution of the base_image_url. # pylint: disable=line-too-long |
None
|
**kwargs
|
wanx - v1
|
n(int, |
{}
|
Raises:
| Type | Description |
|---|---|
InputRequired
|
The prompt cannot be empty. |
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
ImageSynthesisResponse
|
The image synthesis task id in the response. |
Source code in dashscope/legacy_1x/aigc/image_synthesis.py
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 | |
fetch
async
classmethod
¶
fetch(
task: Union[str, ImageSynthesisResponse],
api_key: str = None,
workspace: str = None,
**kwargs
) -> ImageSynthesisResponse
Fetch image(s) synthesis task status or result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, ImageSynthesisResponse]
|
The task_id or ImageSynthesisResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ImageSynthesisResponse |
ImageSynthesisResponse
|
The task status or result. |
Source code in dashscope/legacy_1x/aigc/image_synthesis.py
971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 | |
wait
async
classmethod
¶
wait(
task: Union[str, ImageSynthesisResponse],
api_key: str = None,
workspace: str = None,
wait_timeout: int = -1,
**kwargs
) -> ImageSynthesisResponse
Wait for image(s) synthesis task to complete, and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, ImageSynthesisResponse]
|
The task_id or ImageSynthesisResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
wait_timeout
|
int
|
The maximum seconds to wait. Default is -1 (no timeout). |
-1
|
Returns:
| Name | Type | Description |
|---|---|---|
ImageSynthesisResponse |
ImageSynthesisResponse
|
The task result. |
Source code in dashscope/legacy_1x/aigc/image_synthesis.py
997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 | |
cancel
async
classmethod
¶
cancel(
task: Union[str, ImageSynthesisResponse],
api_key: str = None,
workspace: str = None,
**kwargs
) -> DashScopeAPIResponse
Cancel image synthesis task. Only tasks whose status is PENDING can be canceled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, ImageSynthesisResponse]
|
The task_id or ImageSynthesisResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The response data. |
Source code in dashscope/legacy_1x/aigc/image_synthesis.py
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 | |
list
async
classmethod
¶
list(
start_time: str = None,
end_time: str = None,
model_name: str = None,
api_key_id: str = None,
region: str = None,
status: str = None,
page_no: int = 1,
page_size: int = 10,
api_key: str = None,
workspace: str = None,
**kwargs
) -> DashScopeAPIResponse
List async tasks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_time
|
str
|
The tasks start time, for example: 20230420000000. Defaults to None. |
None
|
end_time
|
str
|
The tasks end time, for example: 20230420000000. Defaults to None. |
None
|
model_name
|
str
|
The tasks model name. Defaults to None. |
None
|
api_key_id
|
str
|
The tasks api-key-id. Defaults to None. |
None
|
region
|
str
|
The service region, for example: cn-beijing. Defaults to None. |
None
|
status
|
str
|
The status of tasks[PENDING, RUNNING, SUCCEEDED, FAILED, CANCELED]. Defaults to None. |
None
|
page_no
|
int
|
The page number. Defaults to 1. |
1
|
page_size
|
int
|
The page size. Defaults to 10. |
10
|
api_key
|
str
|
The user api-key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The response data. |
Source code in dashscope/legacy_1x/aigc/image_synthesis.py
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 | |
ImageGeneration
¶
Bases: BaseApi, BaseAsyncApi
function
class-attribute
instance-attribute
¶
function = 'generation'
API for AI-Generated Content(AIGC) models.
Models
¶
call
classmethod
¶
call(
model: str,
api_key: str = None,
messages: List[Message] = None,
workspace: str = None,
**kwargs
) -> Union[
ImageGenerationResponse,
Generator[ImageGenerationResponse, None, None],
]
Call generation model service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The requested model |
required |
api_key
|
str
|
The api api_key, can be None, if None, will get by default rule(TODO: api key doc). |
None
|
messages
|
list
|
The generation messages. examples: [{'role': 'user', 'content': 'The weather is fine today.'}, {'role': 'assistant', 'content': 'Suitable for outings'}] |
None
|
**kwargs
|
Any
|
stream(bool, |
{}
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Raises: InvalidInput: The history and auto_history are mutually exclusive.
Returns:
| Type | Description |
|---|---|
Union[ImageGenerationResponse, Generator[ImageGenerationResponse, None, None]]
|
Union[ImageGenerationResponse, Generator[ImageGenerationResponse, None, None]]: If |
Union[ImageGenerationResponse, Generator[ImageGenerationResponse, None, None]]
|
stream is True, return Generator, otherwise ImageGenerationResponse. |
Source code in dashscope/legacy_1x/aigc/image_generation.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
async_call
classmethod
¶
async_call(
model: str,
api_key: str = None,
messages: List[Message] = None,
workspace: str = None,
**kwargs
) -> Union[
ImageGenerationResponse,
Generator[ImageGenerationResponse, None, None],
]
Source code in dashscope/legacy_1x/aigc/image_generation.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
fetch
classmethod
¶
fetch(
task: Union[str, ImageGenerationResponse],
api_key: str = None,
workspace: str = None,
**kwargs
) -> DashScopeAPIResponse
Fetch image(s) synthesis task status or result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, ImageGenerationResponse]
|
The task_id or ImageGenerationResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The task status or result. |
Source code in dashscope/legacy_1x/aigc/image_generation.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
wait
classmethod
¶
wait(
task: Union[str, ImageGenerationResponse],
api_key: str = None,
workspace: str = None,
wait_timeout: int = -1,
**kwargs
) -> DashScopeAPIResponse
Wait for image(s) synthesis task to complete, and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, ImageGenerationResponse]
|
The task_id or ImageGenerationResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
wait_timeout
|
int
|
The maximum seconds to wait. Default is -1 (no timeout). |
-1
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The task result. |
Source code in dashscope/legacy_1x/aigc/image_generation.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
cancel
classmethod
¶
cancel(
task: Union[str, ImageGenerationResponse],
api_key: str = None,
workspace: str = None,
**kwargs
) -> DashScopeAPIResponse
Cancel image synthesis task. Only tasks whose status is PENDING can be canceled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, ImageGenerationResponse]
|
The task_id or ImageGenerationResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The response data. |
Source code in dashscope/legacy_1x/aigc/image_generation.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
list
classmethod
¶
list(
start_time: str = None,
end_time: str = None,
model_name: str = None,
api_key_id: str = None,
region: str = None,
status: str = None,
page_no: int = 1,
page_size: int = 10,
api_key: str = None,
workspace: str = None,
**kwargs
) -> DashScopeAPIResponse
List async tasks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_time
|
str
|
The tasks start time, for example: 20230420000000. Defaults to None. |
None
|
end_time
|
str
|
The tasks end time, for example: 20230420000000. Defaults to None. |
None
|
model_name
|
str
|
The tasks model name. Defaults to None. |
None
|
api_key_id
|
str
|
The tasks api-key-id. Defaults to None. |
None
|
region
|
str
|
The service region, for example: cn-beijing. Defaults to None. |
None
|
status
|
str
|
The status of tasks[PENDING, RUNNING, SUCCEEDED, FAILED, CANCELED]. Defaults to None. |
None
|
page_no
|
int
|
The page number. Defaults to 1. |
1
|
page_size
|
int
|
The page size. Defaults to 10. |
10
|
api_key
|
str
|
The user api-key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The response data. |
Source code in dashscope/legacy_1x/aigc/image_generation.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
AioImageGeneration
¶
Bases: BaseAioApi, BaseAsyncAioApi
function
class-attribute
instance-attribute
¶
function = 'generation'
API for AI-Generated Content(AIGC) models.
Models
¶
call
async
classmethod
¶
call(
model: str,
api_key: str = None,
messages: List[Message] = None,
workspace: str = None,
**kwargs
) -> Union[
ImageGenerationResponse,
AsyncGenerator[ImageGenerationResponse, None],
]
Call generation model service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The requested model |
required |
api_key
|
str
|
The api api_key, can be None, if None, will get by default rule(TODO: api key doc). |
None
|
messages
|
list
|
The generation messages. examples: [{'role': 'user', 'content': 'The weather is fine today.'}, {'role': 'assistant', 'content': 'Suitable for outings'}] |
None
|
**kwargs
|
Any
|
stream(bool, |
{}
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Raises: InvalidInput: The history and auto_history are mutually exclusive.
Returns:
| Type | Description |
|---|---|
Union[ImageGenerationResponse, AsyncGenerator[ImageGenerationResponse, None]]
|
Union[ImageGenerationResponse, AsyncGenerator[ImageGenerationResponse, None]]: If |
Union[ImageGenerationResponse, AsyncGenerator[ImageGenerationResponse, None]]
|
stream is True, return AsyncGenerator, otherwise ImageGenerationResponse. |
Source code in dashscope/legacy_1x/aigc/image_generation.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |
async_call
async
classmethod
¶
async_call(
model: str,
api_key: str = None,
messages: List[Message] = None,
workspace: str = None,
**kwargs
) -> Union[
ImageGenerationResponse,
AsyncGenerator[ImageGenerationResponse, None],
]
Source code in dashscope/legacy_1x/aigc/image_generation.py
453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
fetch
async
classmethod
¶
fetch(
task: Union[str, ImageGenerationResponse],
api_key: str = None,
workspace: str = None,
**kwargs
) -> DashScopeAPIResponse
Fetch image(s) synthesis task status or result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, ImageGenerationResponse]
|
The task_id or ImageGenerationResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The task status or result. |
Source code in dashscope/legacy_1x/aigc/image_generation.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 | |
wait
async
classmethod
¶
wait(
task: Union[str, ImageGenerationResponse],
api_key: str = None,
workspace: str = None,
wait_timeout: int = -1,
**kwargs
) -> DashScopeAPIResponse
Wait for image(s) synthesis task to complete, and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, ImageGenerationResponse]
|
The task_id or ImageGenerationResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
wait_timeout
|
int
|
The maximum seconds to wait. Default is -1 (no timeout). |
-1
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The task result. |
Source code in dashscope/legacy_1x/aigc/image_generation.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |
cancel
async
classmethod
¶
cancel(
task: Union[str, ImageGenerationResponse],
api_key: str = None,
workspace: str = None,
**kwargs
) -> DashScopeAPIResponse
Cancel image synthesis task. Only tasks whose status is PENDING can be canceled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, ImageGenerationResponse]
|
The task_id or ImageGenerationResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The response data. |
Source code in dashscope/legacy_1x/aigc/image_generation.py
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
list
async
classmethod
¶
list(
start_time: str = None,
end_time: str = None,
model_name: str = None,
api_key_id: str = None,
region: str = None,
status: str = None,
page_no: int = 1,
page_size: int = 10,
api_key: str = None,
workspace: str = None,
**kwargs
) -> DashScopeAPIResponse
List async tasks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_time
|
str
|
The tasks start time, for example: 20230420000000. Defaults to None. |
None
|
end_time
|
str
|
The tasks end time, for example: 20230420000000. Defaults to None. |
None
|
model_name
|
str
|
The tasks model name. Defaults to None. |
None
|
api_key_id
|
str
|
The tasks api-key-id. Defaults to None. |
None
|
region
|
str
|
The service region, for example: cn-beijing. Defaults to None. |
None
|
status
|
str
|
The status of tasks[PENDING, RUNNING, SUCCEEDED, FAILED, CANCELED]. Defaults to None. |
None
|
page_no
|
int
|
The page number. Defaults to 1. |
1
|
page_size
|
int
|
The page size. Defaults to 10. |
10
|
api_key
|
str
|
The user api-key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The response data. |
Source code in dashscope/legacy_1x/aigc/image_generation.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 | |
VideoSynthesis
¶
Bases: BaseAsyncApi
Models
¶
@deprecated, use wanx2.1-t2v-plus instead
wanx_txt2video_pro
class-attribute
instance-attribute
¶
wanx_txt2video_pro = 'wanx-txt2video-pro'
@deprecated, use wanx2.1-i2v-plus instead
MediaType
¶
call
classmethod
¶
call(
model: str,
prompt: Any = None,
extend_prompt: bool = True,
negative_prompt: str | None = None,
template: str = None,
img_url: str | None = None,
audio_url: str | None = None,
reference_video_urls: List[str] | None = None,
reference_urls: List[str] = None,
reference_url: str = None,
reference_video_description: List[str] = None,
api_key: str | None = None,
extra_input: Dict = None,
workspace: str | None = None,
task: str = None,
head_frame: str = None,
tail_frame: str = None,
first_frame_url: str = None,
last_frame_url: str = None,
media: List[Dict] = None,
size: str | None = None,
duration: int | None = None,
seed: int | None = None,
prompt_extend: bool | None = None,
watermark: bool | None = None,
resolution: str | None = None,
ratio: str | None = None,
shot_type: Optional[str] = None,
audio_setting: Optional[str] = None,
enable_thinking: Optional[bool] = None,
**kwargs: Any
) -> VideoSynthesisResponse
Call video synthesis service and get result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The model, reference |
required |
prompt
|
Any
|
The prompt for video synthesis. |
None
|
extend_prompt
|
bool
|
@deprecated, use prompt_extend in parameters |
True
|
negative_prompt
|
str
|
The negative prompt is the opposite of the prompt meaning. |
None
|
template
|
str
|
LoRa input, such as gufeng, katong, etc. |
None
|
img_url
|
str
|
The input image url. |
None
|
audio_url
|
str
|
The input audio url. |
None
|
reference_video_urls
|
List[str]
|
Character reference video file urls. |
None
|
reference_urls
|
List[str]
|
Character reference file urls. |
None
|
reference_url
|
str
|
Reference file url. |
None
|
reference_video_description
|
List[str]
|
Description for reference video picture and sound. |
None
|
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
extra_input
|
Dict
|
The extra input parameters. |
None
|
task
|
str
|
The task of api, ref doc. |
None
|
head_frame
|
str
|
URL of the first frame image. |
None
|
tail_frame
|
str
|
URL of the last frame image. |
None
|
first_frame_url
|
str
|
URL of the first frame image. |
None
|
last_frame_url
|
str
|
URL of the last frame image. |
None
|
media
|
list
|
media file list. |
None
|
size
|
str
|
Output video size (widthheight), e.g. "1280720". |
None
|
duration
|
int
|
Duration of video in seconds. Default is 5. |
None
|
seed
|
int
|
Random seed for video generation. |
None
|
prompt_extend
|
bool
|
Whether to extend prompt automatically for better results. |
None
|
watermark
|
bool
|
Whether to add watermark. |
None
|
resolution
|
str
|
Output resolution, e.g. "720P", "1080P". |
None
|
ratio
|
str
|
Aspect ratio, e.g. "16:9", "9:16". |
None
|
shot_type
|
str
|
Shot type for video generation. |
None
|
audio_setting
|
str
|
Audio setting for video, "auto" or "origin". |
None
|
enable_thinking
|
bool
|
Whether to use Agentic PE. |
None
|
**kwargs
|
Any
|
Additional parameters passed to the API. |
{}
|
Raises:
| Type | Description |
|---|---|
InputRequired
|
The prompt cannot be empty. |
Returns:
| Name | Type | Description |
|---|---|---|
VideoSynthesisResponse |
VideoSynthesisResponse
|
The video synthesis result. |
Source code in dashscope/legacy_1x/aigc/video_synthesis.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
async_call
classmethod
¶
async_call(
model: str,
prompt: Any = None,
img_url: str | None = None,
audio_url: str | None = None,
reference_video_urls: List[str] | None = None,
reference_urls: List[str] = None,
reference_url: str = None,
reference_video_description: List[str] = None,
extend_prompt: bool = True,
negative_prompt: str | None = None,
template: str = None,
api_key: str | None = None,
extra_input: Dict = None,
workspace: str | None = None,
task: str = None,
head_frame: str = None,
tail_frame: str = None,
first_frame_url: str = None,
last_frame_url: str = None,
media: List[Dict] = None,
size: str | None = None,
duration: int | None = None,
seed: int | None = None,
prompt_extend: bool | None = None,
watermark: bool | None = None,
resolution: str | None = None,
ratio: str | None = None,
shot_type: Optional[str] = None,
audio_setting: Optional[str] = None,
enable_thinking: Optional[bool] = None,
**kwargs: Any
) -> VideoSynthesisResponse
Create a video synthesis task, and return task information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The model, reference |
required |
prompt
|
Any
|
The prompt for video synthesis. |
None
|
extend_prompt
|
bool
|
@deprecated, use prompt_extend in parameters |
True
|
negative_prompt
|
str
|
The negative prompt is the opposite of the prompt meaning. |
None
|
template
|
str
|
LoRa input, such as gufeng, katong, etc. |
None
|
img_url
|
str
|
The input image url. |
None
|
audio_url
|
str
|
The input audio url. |
None
|
reference_video_urls
|
List[str]
|
Character reference video file urls. |
None
|
reference_urls
|
List[str]
|
Character reference file urls. |
None
|
reference_url
|
str
|
Reference file url. |
None
|
reference_video_description
|
List[str]
|
Description for reference video picture and sound. |
None
|
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
extra_input
|
Dict
|
The extra input parameters. |
None
|
task
|
str
|
The task of api, ref doc. |
None
|
head_frame
|
str
|
URL of the first frame image. |
None
|
tail_frame
|
str
|
URL of the last frame image. |
None
|
first_frame_url
|
str
|
URL of the first frame image. |
None
|
last_frame_url
|
str
|
URL of the last frame image. |
None
|
media
|
list
|
media file list. |
None
|
size
|
str
|
Output video size (width*height). |
None
|
duration
|
int
|
Duration of video in seconds. |
None
|
seed
|
int
|
Random seed for video generation. |
None
|
prompt_extend
|
bool
|
Whether to extend prompt. |
None
|
watermark
|
bool
|
Whether to add watermark. |
None
|
resolution
|
str
|
Output resolution. |
None
|
ratio
|
str
|
Aspect ratio, e.g. "16:9". |
None
|
shot_type
|
str
|
Shot type for video generation. |
None
|
audio_setting
|
str
|
Audio setting for video, "auto" or "origin". |
None
|
enable_thinking
|
bool
|
Whether to use Agentic PE. |
None
|
**kwargs
|
Any
|
Additional parameters passed to the API. |
{}
|
Raises:
| Type | Description |
|---|---|
InputRequired
|
The prompt cannot be empty. |
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
VideoSynthesisResponse
|
The video synthesis task id in the response. |
Source code in dashscope/legacy_1x/aigc/video_synthesis.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | |
fetch
classmethod
¶
fetch(
task: Union[str, VideoSynthesisResponse],
api_key: str | None = None,
workspace: str | None = None,
) -> VideoSynthesisResponse
Fetch video synthesis task status or result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, VideoSynthesisResponse]
|
The task_id or VideoSynthesisResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
VideoSynthesisResponse |
VideoSynthesisResponse
|
The task status or result. |
Source code in dashscope/legacy_1x/aigc/video_synthesis.py
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 | |
wait
classmethod
¶
wait(
task: Union[str, VideoSynthesisResponse],
api_key: str | None = None,
workspace: str | None = None,
**kwargs: Any
) -> VideoSynthesisResponse
Wait for video synthesis task to complete, and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, VideoSynthesisResponse]
|
The task_id or VideoSynthesisResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
VideoSynthesisResponse |
VideoSynthesisResponse
|
The task result. |
Source code in dashscope/legacy_1x/aigc/video_synthesis.py
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 | |
cancel
classmethod
¶
cancel(
task: Union[str, VideoSynthesisResponse],
api_key: str | None = None,
workspace: str | None = None,
) -> DashScopeAPIResponse
Cancel video synthesis task. Only tasks whose status is PENDING can be canceled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, VideoSynthesisResponse]
|
The task_id or VideoSynthesisResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The response data. |
Source code in dashscope/legacy_1x/aigc/video_synthesis.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | |
list
classmethod
¶
list(
start_time: str = None,
end_time: str = None,
model_name: str = None,
api_key_id: str = None,
region: str = None,
status: str = None,
page_no: int = 1,
page_size: int = 10,
api_key: str = None,
workspace: str = None,
**kwargs
) -> DashScopeAPIResponse
List async tasks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_time
|
str
|
The tasks start time, for example: 20230420000000. Defaults to None. |
None
|
end_time
|
str
|
The tasks end time, for example: 20230420000000. Defaults to None. |
None
|
model_name
|
str
|
The tasks model name. Defaults to None. |
None
|
api_key_id
|
str
|
The tasks api-key-id. Defaults to None. |
None
|
region
|
str
|
The service region, for example: cn-beijing. Defaults to None. |
None
|
status
|
str
|
The status of tasks[PENDING, RUNNING, SUCCEEDED, FAILED, CANCELED]. Defaults to None. |
None
|
page_no
|
int
|
The page number. Defaults to 1. |
1
|
page_size
|
int
|
The page size. Defaults to 10. |
10
|
api_key
|
str
|
The user api-key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The response data. |
Source code in dashscope/legacy_1x/aigc/video_synthesis.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 | |
AioVideoSynthesis
¶
Bases: BaseAsyncAioApi
call
async
classmethod
¶
call(
model: str,
prompt: Any = None,
img_url: str = None,
audio_url: str = None,
reference_video_urls: List[str] = None,
reference_urls: List[str] = None,
reference_url: str = None,
reference_video_description: List[str] = None,
extend_prompt: bool = True,
negative_prompt: str = None,
template: str = None,
api_key: str = None,
extra_input: Dict = None,
workspace: str = None,
task: str = None,
head_frame: str = None,
tail_frame: str = None,
first_frame_url: str = None,
last_frame_url: str = None,
media: List[Dict] = None,
size: str = None,
duration: int = None,
seed: int = None,
prompt_extend: bool = None,
watermark: bool = None,
resolution: str = None,
ratio: str = None,
shot_type: str = None,
audio_setting: str = None,
enable_thinking: bool = None,
**kwargs
) -> VideoSynthesisResponse
Call video synthesis service and get result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The model, reference |
required |
prompt
|
Any
|
The prompt for video synthesis. |
None
|
extend_prompt
|
bool
|
@deprecated, use prompt_extend in parameters |
True
|
negative_prompt
|
str
|
The negative prompt is the opposite of the prompt meaning. |
None
|
template
|
str
|
LoRa input, such as gufeng, katong, etc. |
None
|
img_url
|
str
|
The input image url. |
None
|
audio_url
|
str
|
The input audio url. |
None
|
reference_video_urls
|
List[str]
|
Character reference video file urls. |
None
|
reference_urls
|
List[str]
|
Character reference file urls. |
None
|
reference_url
|
str
|
Reference file url. |
None
|
reference_video_description
|
List[str]
|
Description for reference video picture and sound. |
None
|
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
extra_input
|
Dict
|
The extra input parameters. |
None
|
task
|
str
|
The task of api, ref doc. |
None
|
head_frame
|
str
|
URL of the first frame image. |
None
|
tail_frame
|
str
|
URL of the last frame image. |
None
|
first_frame_url
|
str
|
URL of the first frame image. |
None
|
last_frame_url
|
str
|
URL of the last frame image. |
None
|
media
|
list
|
media file list. |
None
|
size
|
str
|
Output video size (width*height). |
None
|
duration
|
int
|
Duration of video in seconds. |
None
|
seed
|
int
|
Random seed for video generation. |
None
|
prompt_extend
|
bool
|
Whether to extend prompt. |
None
|
watermark
|
bool
|
Whether to add watermark. |
None
|
resolution
|
str
|
Output resolution. |
None
|
ratio
|
str
|
Aspect ratio, e.g. "16:9". |
None
|
shot_type
|
str
|
Shot type for video generation. |
None
|
audio_setting
|
str
|
Audio setting for video, "auto" or "origin". |
None
|
enable_thinking
|
bool
|
Whether to use Agentic PE. |
None
|
**kwargs
|
Any
|
Additional parameters passed to the API. |
{}
|
Raises:
| Type | Description |
|---|---|
InputRequired
|
The prompt cannot be empty. |
Returns:
| Name | Type | Description |
|---|---|---|
VideoSynthesisResponse |
VideoSynthesisResponse
|
The video synthesis result. |
Source code in dashscope/legacy_1x/aigc/video_synthesis.py
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 | |
async_call
async
classmethod
¶
async_call(
model: str,
prompt: Any = None,
img_url: str = None,
audio_url: str = None,
reference_video_urls: List[str] = None,
reference_urls: List[str] = None,
reference_url: str = None,
reference_video_description: List[str] = None,
extend_prompt: bool = True,
negative_prompt: str = None,
template: str = None,
api_key: str = None,
extra_input: Dict = None,
workspace: str = None,
task: str = None,
head_frame: str = None,
tail_frame: str = None,
first_frame_url: str = None,
last_frame_url: str = None,
media: List[Dict] = None,
size: str = None,
duration: int = None,
seed: int = None,
prompt_extend: bool = None,
watermark: bool = None,
resolution: str = None,
ratio: str = None,
shot_type: str = None,
audio_setting: str = None,
enable_thinking: bool = None,
**kwargs
) -> VideoSynthesisResponse
Create a video synthesis task, and return task information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The model, reference |
required |
prompt
|
Any
|
The prompt for video synthesis. |
None
|
extend_prompt
|
bool
|
@deprecated, use prompt_extend in parameters |
True
|
negative_prompt
|
str
|
The negative prompt is the opposite of the prompt meaning. |
None
|
template
|
str
|
LoRa input, such as gufeng, katong, etc. |
None
|
img_url
|
str
|
The input image url. |
None
|
audio_url
|
str
|
The input audio url. |
None
|
reference_video_urls
|
List[str]
|
Character reference video file urls. |
None
|
reference_urls
|
List[str]
|
Character reference file urls. |
None
|
reference_url
|
str
|
Reference file url. |
None
|
reference_video_description
|
List[str]
|
Description for reference video picture and sound. |
None
|
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
extra_input
|
Dict
|
The extra input parameters. |
None
|
task
|
str
|
The task of api, ref doc. |
None
|
head_frame
|
str
|
URL of the first frame image. |
None
|
tail_frame
|
str
|
URL of the last frame image. |
None
|
first_frame_url
|
str
|
URL of the first frame image. |
None
|
last_frame_url
|
str
|
URL of the last frame image. |
None
|
media
|
list
|
media file list. |
None
|
size
|
str
|
Output video size (width*height). |
None
|
duration
|
int
|
Duration of video in seconds. |
None
|
seed
|
int
|
Random seed for video generation. |
None
|
prompt_extend
|
bool
|
Whether to extend prompt. |
None
|
watermark
|
bool
|
Whether to add watermark. |
None
|
resolution
|
str
|
Output resolution. |
None
|
ratio
|
str
|
Aspect ratio, e.g. "16:9". |
None
|
shot_type
|
str
|
Shot type for video generation. |
None
|
enable_thinking
|
bool
|
Whether to use Agentic PE. |
None
|
audio_setting
|
str
|
Audio setting for video, |
None
|
**kwargs
|
Any
|
Additional parameters passed to the API. |
{}
|
Raises:
| Type | Description |
|---|---|
InputRequired
|
The prompt cannot be empty. |
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
VideoSynthesisResponse
|
The video synthesis task id in the response. |
Source code in dashscope/legacy_1x/aigc/video_synthesis.py
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 | |
fetch
async
classmethod
¶
fetch(
task: Union[str, VideoSynthesisResponse],
api_key: str = None,
workspace: str = None,
**kwargs
) -> VideoSynthesisResponse
Fetch video synthesis task status or result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, VideoSynthesisResponse]
|
The task_id or VideoSynthesisResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
VideoSynthesisResponse |
VideoSynthesisResponse
|
The task status or result. |
Source code in dashscope/legacy_1x/aigc/video_synthesis.py
920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 | |
wait
async
classmethod
¶
wait(
task: Union[str, VideoSynthesisResponse],
api_key: str = None,
workspace: str = None,
wait_timeout: int = -1,
**kwargs
) -> VideoSynthesisResponse
Wait for video synthesis task to complete, and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, VideoSynthesisResponse]
|
The task_id or VideoSynthesisResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
wait_timeout
|
int
|
The maximum seconds to wait. Default is -1 (no timeout). |
-1
|
Returns:
| Name | Type | Description |
|---|---|---|
VideoSynthesisResponse |
VideoSynthesisResponse
|
The task result. |
Source code in dashscope/legacy_1x/aigc/video_synthesis.py
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 | |
cancel
async
classmethod
¶
cancel(
task: Union[str, VideoSynthesisResponse],
api_key: str = None,
workspace: str = None,
**kwargs
) -> DashScopeAPIResponse
Cancel video synthesis task. Only tasks whose status is PENDING can be canceled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, VideoSynthesisResponse]
|
The task_id or VideoSynthesisResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The response data. |
Source code in dashscope/legacy_1x/aigc/video_synthesis.py
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 | |
list
async
classmethod
¶
list(
start_time: str = None,
end_time: str = None,
model_name: str = None,
api_key_id: str = None,
region: str = None,
status: str = None,
page_no: int = 1,
page_size: int = 10,
api_key: str = None,
workspace: str = None,
**kwargs
) -> DashScopeAPIResponse
List async tasks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_time
|
str
|
The tasks start time, for example: 20230420000000. Defaults to None. |
None
|
end_time
|
str
|
The tasks end time, for example: 20230420000000. Defaults to None. |
None
|
model_name
|
str
|
The tasks model name. Defaults to None. |
None
|
api_key_id
|
str
|
The tasks api-key-id. Defaults to None. |
None
|
region
|
str
|
The service region, for example: cn-beijing. Defaults to None. |
None
|
status
|
str
|
The status of tasks[PENDING, RUNNING, SUCCEEDED, FAILED, CANCELED]. Defaults to None. |
None
|
page_no
|
int
|
The page number. Defaults to 1. |
1
|
page_size
|
int
|
The page size. Defaults to 10. |
10
|
api_key
|
str
|
The user api-key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The response data. |
Source code in dashscope/legacy_1x/aigc/video_synthesis.py
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 | |
Embeddings¶
TextEmbedding
¶
Bases: BaseApi
Models
¶
qwen3_7_text_embedding
class-attribute
instance-attribute
¶
qwen3_7_text_embedding = 'qwen3.7-text-embedding'
call
classmethod
¶
call(
model: str,
input: Union[str, List[str]],
workspace: str | None = None,
api_key: str | None = None,
text_type: str | None = None,
dimension: int | None = None,
output_type: str | None = None,
instruct: str | None = None,
**kwargs: Any
) -> DashScopeAPIResponse
Get embedding of text input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The embedding model name. |
required |
input
|
Union[str, List[str], IOBase]
|
The text input, can be a text or list of text or opened file object, if opened file object, will read all lines, one embedding per line. |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
text_type
|
str
|
"query" for search queries, "document" (default) for corpus/symmetric tasks. |
None
|
dimension
|
int
|
Output vector dimension. Options: 2048 (v4 only), 1536 (v4 only), 1024 (default), 768, 512, 256, 128, 64. Only for v3/v4. |
None
|
output_type
|
str
|
Output format: "dense" (default), "sparse", or "dense&sparse". Only for v3/v4. |
None
|
instruct
|
str
|
Custom task instruction to guide model understanding of query intent. |
None
|
**kwargs
|
Any
|
Additional parameters passed to the API. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The embedding result. |
Source code in dashscope/legacy_1x/embeddings/text_embedding.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
BatchTextEmbedding
¶
Bases: BaseAsyncApi
function
class-attribute
instance-attribute
¶
function = 'text-embedding'
API for async text embedding.
Models
¶
call
classmethod
¶
call(
model: str,
url: str,
api_key: str | None = None,
workspace: str | None = None,
**kwargs: Any
) -> BatchTextEmbeddingResponse
Call async text embedding service and get result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The model, reference |
required |
url
|
Any
|
The async request file url, which contains text to embedding line by line. |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
**kwargs
|
Any
|
text_type(str, |
{}
|
Raises: InputRequired: The url cannot be empty.
Returns:
| Name | Type | Description |
|---|---|---|
AsyncTextEmbeddingResponse |
BatchTextEmbeddingResponse
|
The async text embedding task result. |
Source code in dashscope/legacy_1x/embeddings/batch_text_embedding.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
async_call
classmethod
¶
async_call(
model: str,
url: str,
api_key: str | None = None,
workspace: str | None = None,
**kwargs: Any
) -> BatchTextEmbeddingResponse
Create a async text embedding task, and return task information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The model, reference |
required |
url
|
Any
|
The async request file url, which contains text to embedding line by line. |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
**kwargs
|
Any
|
text_type(str, |
{}
|
Raises:
| Type | Description |
|---|---|
InputRequired
|
The url cannot be empty. |
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
BatchTextEmbeddingResponse
|
The image synthesis task id in the response. |
Source code in dashscope/legacy_1x/embeddings/batch_text_embedding.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
fetch
classmethod
¶
fetch(
task: Any,
api_key: str | None = None,
workspace: str | None = None,
) -> BatchTextEmbeddingResponse
Fetch async text embedding task status or result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, AsyncTextEmbeddingResponse]
|
The task_id or AsyncTextEmbeddingResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
AsyncTextEmbeddingResponse |
BatchTextEmbeddingResponse
|
The task status or result. |
Source code in dashscope/legacy_1x/embeddings/batch_text_embedding.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
wait
classmethod
¶
wait(
task: Any,
api_key: str | None = None,
workspace: str | None = None,
**kwargs: Any
) -> BatchTextEmbeddingResponse
Wait for async text embedding task to complete, and return the result. # noqa: E501
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, AsyncTextEmbeddingResponse]
|
The task_id or AsyncTextEmbeddingResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
AsyncTextEmbeddingResponse |
BatchTextEmbeddingResponse
|
The task result. |
Source code in dashscope/legacy_1x/embeddings/batch_text_embedding.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
cancel
classmethod
¶
cancel(
task: Any,
api_key: str | None = None,
workspace: str | None = None,
) -> DashScopeAPIResponse
Cancel async text embedding task. Only tasks whose status is PENDING can be canceled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, AsyncTextEmbeddingResponse]
|
The task_id or AsyncTextEmbeddingResponse return by async_call(). |
required |
api_key
|
str
|
The api api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The response data. |
Source code in dashscope/legacy_1x/embeddings/batch_text_embedding.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
list
classmethod
¶
list(
start_time: str = None,
end_time: str = None,
model_name: str = None,
api_key_id: str = None,
region: str = None,
status: str = None,
page_no: int = 1,
page_size: int = 10,
api_key: str = None,
workspace: str = None,
**kwargs
) -> DashScopeAPIResponse
List async tasks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_time
|
str
|
The tasks start time, for example: 20230420000000. Defaults to None. |
None
|
end_time
|
str
|
The tasks end time, for example: 20230420000000. Defaults to None. |
None
|
model_name
|
str
|
The tasks model name. Defaults to None. |
None
|
api_key_id
|
str
|
The tasks api-key-id. Defaults to None. |
None
|
region
|
str
|
The service region, for example: cn-beijing. Defaults to None. |
None
|
status
|
str
|
The status of tasks[PENDING, RUNNING, SUCCEEDED, FAILED, CANCELED]. Defaults to None. |
None
|
page_no
|
int
|
The page number. Defaults to 1. |
1
|
page_size
|
int
|
The page size. Defaults to 10. |
10
|
api_key
|
str
|
The user api-key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The response data. |
Source code in dashscope/legacy_1x/embeddings/batch_text_embedding.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
BatchTextEmbeddingResponse
dataclass
¶
BatchTextEmbeddingResponse(
status_code: int,
request_id: str = "",
code: str = "",
message: str = "",
output: Any = None,
usage: Any = None,
headers: Dict[Any, Any] = None,
**kwargs
)
Bases: DashScopeAPIResponse
Source code in dashscope/legacy_1x/api_entities/dashscope_response.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
from_api_response
staticmethod
¶
from_api_response(api_response: DashScopeAPIResponse)
Source code in dashscope/legacy_1x/embeddings/batch_text_embedding_response.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
MultiModalEmbedding
¶
Bases: BaseApi
Models
¶
multimodal_embedding_one_peace_v1
class-attribute
instance-attribute
¶
multimodal_embedding_one_peace_v1 = (
"multimodal-embedding-one-peace-v1"
)
multimodal_embedding_v1
class-attribute
instance-attribute
¶
multimodal_embedding_v1 = 'multimodal-embedding-v1'
qwen2_5_vl_embedding
class-attribute
instance-attribute
¶
qwen2_5_vl_embedding = 'qwen2.5-vl-embedding'
tongyi_embedding_vision_plus
class-attribute
instance-attribute
¶
tongyi_embedding_vision_plus = (
"tongyi-embedding-vision-plus"
)
tongyi_embedding_vision_flash
class-attribute
instance-attribute
¶
tongyi_embedding_vision_flash = (
"tongyi-embedding-vision-flash"
)
call
classmethod
¶
call(
model: str,
input: Any,
api_key: str | None = None,
workspace: str | None = None,
dimension: int | None = None,
output_type: str = None,
fps: float = None,
instruct: str = None,
enable_fusion: bool = None,
res_level: int = None,
max_video_frames: int = None,
**kwargs: Any
) -> DashScopeAPIResponse
Get embedding multimodal contents..
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The embedding model name. |
required |
input
|
List[MultiModalEmbeddingElement]
|
The embedding elements, every element include data, modal, factor field. |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
dimension
|
int
|
Output vector dimensions. Model-specific supported values. |
None
|
output_type
|
str
|
Output vector format, currently only "dense" is supported. |
None
|
fps
|
float
|
Video frame extraction ratio in range [0,1]. Default: 1.0. |
None
|
instruct
|
str
|
Custom task instruction to guide model understanding of query intent. |
None
|
enable_fusion
|
bool
|
Only for qwen3-vl-embedding. When True, fuses all contents into 1 vector. |
None
|
res_level
|
int
|
Resolution tier: 0/1/2/3. Only for snapshot models. |
None
|
max_video_frames
|
int
|
Max video sampling frames, up to 64. Only for snapshot models. |
None
|
**kwargs
|
Any
|
auto_truncation(bool, |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The embedding result. |
Source code in dashscope/legacy_1x/embeddings/multimodal_embedding.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
AioMultiModalEmbedding
¶
Bases: BaseAioApi
Models
¶
multimodal_embedding_one_peace_v1
class-attribute
instance-attribute
¶
multimodal_embedding_one_peace_v1 = (
"multimodal-embedding-one-peace-v1"
)
multimodal_embedding_v1
class-attribute
instance-attribute
¶
multimodal_embedding_v1 = 'multimodal-embedding-v1'
qwen2_5_vl_embedding
class-attribute
instance-attribute
¶
qwen2_5_vl_embedding = 'qwen2.5-vl-embedding'
tongyi_embedding_vision_plus
class-attribute
instance-attribute
¶
tongyi_embedding_vision_plus = (
"tongyi-embedding-vision-plus"
)
tongyi_embedding_vision_flash
class-attribute
instance-attribute
¶
tongyi_embedding_vision_flash = (
"tongyi-embedding-vision-flash"
)
call
async
classmethod
¶
call(
model: str,
input: Any,
api_key: str | None = None,
workspace: str | None = None,
dimension: int | None = None,
output_type: str = None,
fps: float = None,
instruct: str = None,
enable_fusion: bool = None,
res_level: int = None,
max_video_frames: int = None,
**kwargs: Any
) -> DashScopeAPIResponse
Get embedding multimodal contents..
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The embedding model name. |
required |
input
|
List[MultiModalEmbeddingElement]
|
The embedding elements, every element include data, modal, factor field. |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
dimension
|
int
|
Output vector dimensions. Model-specific supported values. |
None
|
output_type
|
str
|
Output vector format, currently only "dense" is supported. |
None
|
fps
|
float
|
Video frame extraction ratio in range [0,1]. Default: 1.0. |
None
|
instruct
|
str
|
Custom task instruction to guide model understanding of query intent. |
None
|
enable_fusion
|
bool
|
Only for qwen3-vl-embedding. When True, fuses all contents into 1 vector. |
None
|
res_level
|
int
|
Resolution tier: 0/1/2/3. Only for snapshot models. |
None
|
max_video_frames
|
int
|
Max video sampling frames, up to 64. Only for snapshot models. |
None
|
**kwargs
|
Any
|
auto_truncation(bool, |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The embedding result. |
Source code in dashscope/legacy_1x/embeddings/multimodal_embedding.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
MultiModalEmbeddingItemText
dataclass
¶
MultiModalEmbeddingItemText(
text: str, factor: float, **kwargs
)
Bases: MultiModalEmbeddingItemBase
Source code in dashscope/legacy_1x/embeddings/multimodal_embedding.py
29 30 31 | |
MultiModalEmbeddingItemImage
dataclass
¶
MultiModalEmbeddingItemImage(
image: str, factor: float, **kwargs
)
Bases: MultiModalEmbeddingItemBase
Source code in dashscope/legacy_1x/embeddings/multimodal_embedding.py
38 39 40 | |
MultiModalEmbeddingItemAudio
dataclass
¶
MultiModalEmbeddingItemAudio(
audio: str, factor: float, **kwargs
)
Bases: MultiModalEmbeddingItemBase
Source code in dashscope/legacy_1x/embeddings/multimodal_embedding.py
47 48 49 | |
Rerank¶
TextReRank
¶
Bases: BaseApi
Models
¶
qwen3_7_text_rerank
class-attribute
instance-attribute
¶
qwen3_7_text_rerank = 'qwen3.7-text-rerank'
call
classmethod
¶
call(
model: str,
query: str,
documents: List[str],
return_documents: bool | None = None,
top_n: int | None = None,
api_key: str | None = None,
instruct: str | None = None,
**kwargs: Any
) -> ReRankResponse
Calling rerank service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The model to use. |
required |
query
|
str
|
The query string. |
required |
documents
|
List[str]
|
The documents to rank. |
required |
return_documents
|
bool, `optional`
|
enable return origin documents, system default is false. |
None
|
top_n
|
int, `optional`
|
how many documents to return, default return all the documents. |
None
|
api_key
|
str
|
The DashScope api key. Defaults to None. |
None
|
instruct
|
str
|
Custom task instruction to guide ranking strategy. English recommended. |
None
|
Raises:
| Type | Description |
|---|---|
InputRequired
|
The query and documents are required. |
ModelRequired
|
The model is required. |
Returns:
| Name | Type | Description |
|---|---|---|
RerankResponse |
ReRankResponse
|
The rerank result. |
Source code in dashscope/legacy_1x/rerank/text_rerank.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
AioTextReRank
¶
Bases: BaseAioApi
call
async
classmethod
¶
call(
model: str,
query: str,
documents: List[str],
return_documents: bool | None = None,
top_n: int | None = None,
api_key: str | None = None,
workspace: str = None,
instruct: str | None = None,
**kwargs: Any
) -> ReRankResponse
Calling rerank service asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The model to use. |
required |
query
|
str
|
The query string. |
required |
documents
|
List[str]
|
The documents to rank. |
required |
return_documents
|
bool, `optional`
|
enable return origin documents, system default is false. |
None
|
top_n
|
int, `optional`
|
how many documents to return, default return all the documents. |
None
|
api_key
|
str
|
The DashScope api key. Defaults to None. |
None
|
workspace
|
str
|
The DashScope workspace id. |
None
|
instruct
|
str
|
Custom task instruction to guide ranking strategy. English recommended. |
None
|
Raises:
| Type | Description |
|---|---|
InputRequired
|
The query and documents are required. |
ModelRequired
|
The model is required. |
Returns:
| Name | Type | Description |
|---|---|---|
RerankResponse |
ReRankResponse
|
The rerank result. |
Source code in dashscope/legacy_1x/rerank/text_rerank.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
NLP understanding¶
Understanding
¶
Bases: BaseApi
nlu_task
class-attribute
instance-attribute
¶
nlu_task = 'nlu'
API for AI-Generated Content(AIGC) models.
call
classmethod
¶
call(
model: str,
sentence: str = None,
labels: str = None,
task: str = None,
api_key: str = None,
**kwargs
) -> DashScopeAPIResponse
Call generation model service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The requested model, such as opennlu-v1 |
required |
sentence
|
str
|
The text content entered by the user that needs to be processed supports both Chinese and English. (The maximum limit for input is 1024 tokens, which is the sum of all input fields). # noqa E501 # pylint: disable=line-too-long |
None
|
labels
|
list
|
For the extraction task, label is the name of the type that needs to be extracted. For classification tasks, label is the classification system. Separate different labels with Chinese commas.. # noqa E501 # pylint: disable=line-too-long |
None
|
task
|
str
|
Task type, optional as extraction or classification, default as extraction. |
None
|
api_key
|
str
|
The api api_key, can be None, if None, will get by default rule(TODO: api key doc). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The understanding result. |
Source code in dashscope/legacy_1x/nlp/understanding.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
Application calls¶
Application
¶
Bases: BaseApi
DocReferenceType
¶
call
classmethod
¶
call(
app_id: str,
prompt: str | None = None,
history: list | None = None,
workspace: str | None = None,
api_key: str | None = None,
messages: List[Message] | None = None,
stream: Optional[bool] = None,
temperature: Optional[float] = None,
top_p: Optional[float] = None,
top_k: Optional[int] = None,
seed: Optional[int] = None,
session_id: Optional[str] = None,
biz_params: Optional[Dict[str, Any]] = None,
has_thoughts: Optional[bool] = None,
doc_tag_codes: Optional[List[str]] = None,
doc_reference_type: Optional[str] = None,
memory_id: Optional[str] = None,
image_list: Optional[List[str]] = None,
file_list: Optional[List[str]] = None,
rag_options: Optional[Dict[str, Any]] = None,
incremental_output: Optional[bool] = None,
**kwargs: Any
) -> Union[
ApplicationResponse,
Generator[ApplicationResponse, None, None],
]
Call app completion service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_id
|
str
|
Id of bailian application |
required |
prompt
|
str
|
The input prompt. |
None
|
history
|
list
|
The user provided history examples: [{'user':'The weather is fine today.', 'bot': 'Suitable for outings'}]. Defaults to None. |
None
|
workspace
|
str, `optional`
|
Workspace for app completion call |
None
|
api_key
|
str
|
The api api_key, can be None, if None, will get by default rule(TODO: api key doc). |
None
|
messages
|
list
|
The generation messages. |
None
|
stream
|
bool
|
Enable server-sent events (ref: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) # noqa E501 # pylint: disable=line-too-long the result will back partially[qwen-turbo,bailian-v1]. |
None
|
temperature
|
float
|
Used to control the degree of randomness and diversity. Specifically, the temperature value controls the degree to which the probability distribution of each candidate word is smoothed when generating text. A higher temperature value will reduce the peak value of the probability, allowing more low-probability words to be selected, and the generated results will be more diverse; while a lower temperature value will enhance the peak value of the probability, making it easier for high-probability words to be selected, the generated results are more deterministic, range(0, 2) .[qwen-turbo,qwen-plus]. |
None
|
top_p
|
float
|
A sampling strategy, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered[qwen-turbo,bailian-v1]. |
None
|
top_k
|
int
|
The size of the sample candidate set when generated. # noqa E501 # pylint: disable=line-too-long For example, when the value is 50, only the 50 highest-scoring tokens # noqa E501 # pylint: disable=line-too-long in a single generation form a randomly sampled candidate set. # noqa E501 The larger the value, the higher the randomness generated; # noqa E501 the smaller the value, the higher the certainty generated. # noqa E501 The default value is 0, which means the top_k policy is # noqa E501 not enabled. At this time, only the top_p policy takes effect. # noqa E501 |
None
|
seed
|
int
|
When generating, the seed of the random number is used to control the # pylint: disable=line-too-long randomness of the model generation. If you use the same seed, each run will generate the same results; # pylint: disable=line-too-long you can use the same seed when you need to reproduce the model's generated results. # pylint: disable=line-too-long The seed parameter supports unsigned 64-bit integer types. Default value 1234 |
None
|
session_id
|
str
|
Session if for multiple rounds call. |
None
|
biz_params
|
dict
|
The extra parameters for flow or plugin. |
None
|
has_thoughts
|
bool
|
Flag to return rag or plugin process details. Default value false. # pylint: disable=line-too-long |
None
|
doc_tag_codes
|
list[str]
|
Tag code list for doc retrival. |
None
|
doc_reference_type
|
str
|
The type of doc reference. simple: simple format of doc retrival which not include index in response text but in doc reference list. # pylint: disable=line-too-long indexed: include both index in response text and doc reference list |
None
|
memory_id
|
str
|
Used to store long term context summary between end users and assistant. # pylint: disable=line-too-long |
None
|
image_list
|
list
|
Used to pass image url list. |
None
|
file_list
|
list
|
Used to pass file url list. |
None
|
rag_options
|
dict
|
Rag options for retrieval augmented generation options. # pylint: disable=line-too-long |
None
|
incremental_output
|
bool
|
In streaming mode, output only new tokens (True) vs. cumulative output (False). |
None
|
**kwargs
|
Any
|
Additional parameters passed to the API. |
{}
|
Raises:
| Type | Description |
|---|---|
InvalidInput
|
The history and auto_history are mutually exclusive. |
Returns:
| Type | Description |
|---|---|
Union[ApplicationResponse, Generator[ApplicationResponse, None, None]]
|
Union[CompletionResponse, Generator[CompletionResponse, None, None]]: If |
Union[ApplicationResponse, Generator[ApplicationResponse, None, None]]
|
stream is True, return Generator, otherwise GenerationResponse. |
Source code in dashscope/legacy_1x/app/application.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
ApplicationResponse
dataclass
¶
ApplicationResponse()
Bases: DashScopeAPIResponse
from_api_response
staticmethod
¶
from_api_response(api_response: DashScopeAPIResponse)
Source code in dashscope/legacy_1x/app/application_response.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
Speech synthesis (1.x)¶
SpeechSynthesizer
¶
Bases: BaseApi
Text-to-speech interface.
AudioFormat
¶
call
classmethod
¶
call(
model: str,
text: str,
callback: ResultCallback | None = None,
workspace: str | None = None,
**kwargs: Any
) -> SpeechSynthesisResult
Convert text to speech synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The requested model_id. |
required |
text
|
str
|
Text content used for speech synthesis. |
required |
callback
|
ResultCallback
|
A callback that returns speech synthesis results. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
**kwargs
|
Any
|
format(str, |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
SpeechSynthesisResult |
SpeechSynthesisResult
|
The result of systhesis. |
Source code in dashscope/legacy_1x/audio/tts/speech_synthesizer.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
ResultCallback
¶
An interface that defines callback methods for getting speech synthesis results. # noqa E501 Derive from this class and implement its function to provide your own data.
on_open
¶
on_open() -> None
Source code in dashscope/legacy_1x/audio/tts/speech_synthesizer.py
76 77 | |
on_complete
¶
on_complete() -> None
Source code in dashscope/legacy_1x/audio/tts/speech_synthesizer.py
79 80 | |
on_error
¶
on_error(response: SpeechSynthesisResponse) -> None
Source code in dashscope/legacy_1x/audio/tts/speech_synthesizer.py
82 83 | |
on_close
¶
on_close() -> None
Source code in dashscope/legacy_1x/audio/tts/speech_synthesizer.py
85 86 | |
on_event
¶
on_event(result: SpeechSynthesisResult) -> None
Source code in dashscope/legacy_1x/audio/tts/speech_synthesizer.py
88 89 | |
SpeechSynthesisResult
¶
SpeechSynthesisResult(
frame: bytes,
data: bytes,
sentence: Dict[str, str],
sentences: List[Dict[str, str]],
response: SpeechSynthesisResponse,
)
The result set of speech synthesis, including audio data, timestamp information, and final result information.
Source code in dashscope/legacy_1x/audio/tts/speech_synthesizer.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
get_audio_frame
¶
get_audio_frame() -> bytes
Obtain the audio frame data of speech synthesis through callbacks.
Source code in dashscope/legacy_1x/audio/tts/speech_synthesizer.py
45 46 47 | |
get_audio_data
¶
get_audio_data() -> bytes
Get complete audio data for speech synthesis.
Source code in dashscope/legacy_1x/audio/tts/speech_synthesizer.py
49 50 51 | |
get_timestamp
¶
get_timestamp() -> Dict[str, str]
Obtain the timestamp information of the current speech synthesis sentence through the callback.
Source code in dashscope/legacy_1x/audio/tts/speech_synthesizer.py
53 54 55 56 57 | |
get_timestamps
¶
get_timestamps() -> List[Dict[str, str]]
Get complete timestamp information for all speech synthesis sentences.
Source code in dashscope/legacy_1x/audio/tts/speech_synthesizer.py
59 60 61 | |
get_response
¶
get_response() -> SpeechSynthesisResponse
Obtain the status information of the current speech synthesis task, including error information and billing information.
Source code in dashscope/legacy_1x/audio/tts/speech_synthesizer.py
63 64 65 66 67 | |
HttpSpeechSynthesizer
¶
Bases: BaseApi
HTTP-based text-to-speech interface for CosyVoice.
AudioFormat
¶
call
classmethod
¶
call(
model: str,
text: str,
voice: str,
audio_format: str = "wav",
sample_rate: int = 24000,
stream: bool = False,
workspace: Optional[str] = None,
api_key: Optional[str] = None,
url: Optional[str] = None,
**kwargs
) -> Union[
HttpSpeechSynthesisResult,
Iterator[HttpSpeechSynthesisResult],
]
Convert text to speech via HTTP API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The speech synthesis model, e.g., 'cosyvoice-v3-flash'. |
required |
text
|
str
|
The text to synthesize. |
required |
voice
|
str
|
The voice to use for synthesis. |
required |
audio_format
|
str
|
Audio encoding format ('wav', 'pcm', 'mp3'). Defaults to 'wav'. |
'wav'
|
sample_rate
|
int
|
Audio sample rate in Hz. Defaults to 24000. |
24000
|
stream
|
bool
|
Whether to use streaming (SSE) mode. Defaults to False. |
False
|
workspace
|
str
|
The DashScope workspace ID. |
None
|
api_key
|
str
|
The DashScope API key. |
None
|
url
|
str
|
custom http url if needed. |
None
|
**kwargs
|
Any
|
Additional parameters like volume, rate, pitch, etc. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
HttpSpeechSynthesisResult |
Union[HttpSpeechSynthesisResult, Iterator[HttpSpeechSynthesisResult]]
|
For non-streaming mode. |
Union[HttpSpeechSynthesisResult, Iterator[HttpSpeechSynthesisResult]]
|
Iterator[HttpSpeechSynthesisResult]: For streaming mode. |
Source code in dashscope/legacy_1x/audio/http_tts/http_speech_synthesizer.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
SpeechSynthesizer
¶
SpeechSynthesizer(
model,
voice,
format: AudioFormat = AudioFormat.DEFAULT,
volume=50,
speech_rate=1.0,
pitch_rate=1.0,
seed=0,
synthesis_type=0,
instruction=None,
language_hints: list = None,
headers=None,
callback: ResultCallback = None,
workspace=None,
url=None,
hot_fix=None,
additional_params=None,
)
CosyVoice Speech Synthesis SDK Parameters:
model: str Model name. voice: str Voice name. format: AudioFormat Synthesis audio format. volume: int The volume of the synthesized audio, with a range from 0 to 100. Default is 50. rate: float The speech rate of the synthesized audio, with a range from 0.5 to 2. Default is 1.0. # noqa: E501 # pylint: disable=line-too-long pitch: float The pitch of the synthesized audio, with a range from 0.5 to 2. Default is 1.0. # noqa: E501 # pylint: disable=line-too-long headers: Dict User-defined headers. callback: ResultCallback Callback to receive real-time synthesis results. workspace: str Dashscope workspace ID. url: str Dashscope WebSocket URL. seed: int The seed of the synthesizer, with a range from 0 to 65535. Default is 0. synthesis_type: int The type of the synthesizer, Default is 0. instruction: str The instruction of the synthesizer, max length is 128. language_hints: list The language hints of the synthesizer. supported language: zh, en. additional_params: Dict Additional parameters for the Dashscope API. hot_fix: Dict or HotFix Hot fix parameters for pronunciation and text replacement. Example: { "pronunciation": [{"草地": "cao3 di4"}], "replace": [{"草地": "草弟"}] } enable_markdown_filter: bool Whether to enable markdown filter. should be set into additional_params.
Source code in dashscope/legacy_1x/audio/tts_v2/speech_synthesizer.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
streaming_call
¶
streaming_call(text: str)
Streaming input mode: You can call the streaming_call function multiple times to send text. A session will be created on the first call. The session ends after calling streaming_complete. Parameters:
text: str utf-8 encoded text
Source code in dashscope/legacy_1x/audio/tts_v2/speech_synthesizer.py
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 | |
streaming_flush
¶
streaming_flush()
send tts flush request.
Source code in dashscope/legacy_1x/audio/tts_v2/speech_synthesizer.py
644 645 646 647 648 649 650 651 652 653 654 655 | |
streaming_complete
¶
streaming_complete(complete_timeout_millis=600000)
Synchronously stop the streaming input speech synthesis task. Wait for all remaining synthesized audio before returning
Parameters:¶
complete_timeout_millis: int Throws TimeoutError exception if it times out. If the timeout is not None # noqa: E501 and greater than zero, it will wait for the corresponding number of milliseconds; otherwise, it will wait indefinitely.
Raises:¶
If the server reported a task-failed event, its error is raised here, unless a callback is set, in which case the error has already been delivered through ResultCallback.on_error.
Source code in dashscope/legacy_1x/audio/tts_v2/speech_synthesizer.py
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 | |
async_streaming_complete
¶
async_streaming_complete(complete_timeout_millis=600000)
Asynchronously stop the streaming input speech synthesis task, returns immediately. # noqa: E501 # pylint: disable=line-too-long You need to listen and handle the STREAM_INPUT_TTS_EVENT_SYNTHESIS_COMPLETE event in the on_event callback. # noqa: E501 # pylint: disable=line-too-long Do not destroy the object and callback before this event.
Parameters:¶
complete_timeout_millis: int Throws TimeoutError exception if it times out. If the timeout is not None # noqa: E501 and greater than zero, it will wait for the corresponding number of milliseconds; otherwise, it will wait indefinitely.
Source code in dashscope/legacy_1x/audio/tts_v2/speech_synthesizer.py
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 | |
streaming_cancel
¶
streaming_cancel(complete_timeout_millis=10000)
Immediately terminate the streaming input speech synthesis task and discard any remaining audio that is not yet delivered.
A finish-task message with payload.input.directive=cancel is sent to notify the server to stop synthesis in advance. The server will then respond with a task-finished message, after which the connection is closed.
Parameters:¶
complete_timeout_millis: int If it times out waiting for the server's task-finished message, the connection is force-closed and a warning is logged. If the timeout is not None and greater than zero, it will wait for the corresponding number of milliseconds; otherwise, it will wait indefinitely.
Source code in dashscope/legacy_1x/audio/tts_v2/speech_synthesizer.py
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 | |
on_message
¶
on_message(ws, message)
Source code in dashscope/legacy_1x/audio/tts_v2/speech_synthesizer.py
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 | |
call
¶
call(text: str, timeout_millis=None)
Speech synthesis. If callback is set, the audio will be returned in real-time through the on_event interface. # noqa: E501 # pylint: disable=line-too-long Otherwise, this function blocks until all audio is received and then returns the complete audio data. # noqa: E501 # pylint: disable=line-too-long
Parameters:¶
text: str utf-8 encoded text timeoutMillis: Integer or None return: bytes If a callback is not set during initialization, the complete audio is returned # noqa: E501 # pylint: disable=line-too-long as the function's return value. Otherwise, the return value is null. # noqa: E501 If the timeout is set to a value greater than zero and not None, it will wait for the corresponding number of milliseconds; otherwise, it will wait indefinitely. If the server reported a task-failed event, its error is raised instead of returning the partially synthesized audio.
Source code in dashscope/legacy_1x/audio/tts_v2/speech_synthesizer.py
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 | |
on_close
¶
on_close(ws, close_status_code, close_msg)
Source code in dashscope/legacy_1x/audio/tts_v2/speech_synthesizer.py
900 901 902 903 904 905 906 | |
on_error
¶
on_error(ws, error)
Source code in dashscope/legacy_1x/audio/tts_v2/speech_synthesizer.py
909 910 | |
close
¶
close()
Source code in dashscope/legacy_1x/audio/tts_v2/speech_synthesizer.py
915 916 917 | |
get_last_request_id
¶
get_last_request_id()
Source code in dashscope/legacy_1x/audio/tts_v2/speech_synthesizer.py
920 921 | |
get_first_package_delay
¶
get_first_package_delay()
First Package Delay is the time between start sending text and receive first audio package
Source code in dashscope/legacy_1x/audio/tts_v2/speech_synthesizer.py
923 924 925 | |
get_response
¶
get_response()
Source code in dashscope/legacy_1x/audio/tts_v2/speech_synthesizer.py
927 928 | |
ResultCallback
¶
An interface that defines callback methods for getting speech synthesis results. # noqa E501 Derive from this class and implement its function to provide your own data.
on_open
¶
on_open() -> None
Source code in dashscope/legacy_1x/audio/tts_v2/speech_synthesizer.py
75 76 | |
on_complete
¶
on_complete() -> None
Source code in dashscope/legacy_1x/audio/tts_v2/speech_synthesizer.py
78 79 | |
on_error
¶
on_error(message) -> None
Source code in dashscope/legacy_1x/audio/tts_v2/speech_synthesizer.py
81 82 | |
on_close
¶
on_close() -> None
Source code in dashscope/legacy_1x/audio/tts_v2/speech_synthesizer.py
84 85 | |
on_event
¶
on_event(message: str) -> None
Source code in dashscope/legacy_1x/audio/tts_v2/speech_synthesizer.py
87 88 | |
on_data
¶
on_data(data: bytes) -> None
Source code in dashscope/legacy_1x/audio/tts_v2/speech_synthesizer.py
90 91 | |
VoiceEnrollmentService
¶
VoiceEnrollmentService(
api_key=None, workspace=None, model=None, **kwargs
)
Bases: BaseApi
API for voice clone service
Source code in dashscope/legacy_1x/audio/tts_v2/enrollment.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
create_voice
¶
create_voice(
target_model: str,
prefix: str,
url: str,
language_hints: List[str] = None,
max_prompt_audio_length: float = None,
**kwargs
) -> str
Create a new cloned voice. param: target_model TTS model version for the cloned voice param: prefix Custom voice prefix, only digits and lowercase letters allowed, less than 10 characters. param: url Audio file URL for voice cloning param: language_hints Target language for the cloned voice param: max_prompt_audio_length Max length of prompt audio output from audio preprocessing, in seconds. Default is 10s. param: kwargs Additional parameters return: voice_id
Source code in dashscope/legacy_1x/audio/tts_v2/enrollment.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
list_voices
¶
list_voices(
prefix=None, page_index: int = 0, page_size: int = 10
) -> List[dict]
List all created voices. param: page_index Page index for query param: page_size Page size return: List[dict] Voice list, including id, creation time, modification time, and status for each voice.
Source code in dashscope/legacy_1x/audio/tts_v2/enrollment.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
query_voice
¶
query_voice(voice_id: str) -> List[str]
Query voice details. param: voice_id Voice ID to query return: bytes Audio used for voice registration
Source code in dashscope/legacy_1x/audio/tts_v2/enrollment.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
update_voice
¶
update_voice(voice_id: str, url: str) -> None
Update voice. param: voice_id Voice ID param: url Audio file URL for cloning
Source code in dashscope/legacy_1x/audio/tts_v2/enrollment.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
delete_voice
¶
delete_voice(voice_id: str) -> None
Delete voice. param: voice_id Voice ID to delete
Source code in dashscope/legacy_1x/audio/tts_v2/enrollment.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
get_last_request_id
¶
get_last_request_id()
Source code in dashscope/legacy_1x/audio/tts_v2/enrollment.py
245 246 | |
SpeechSynthesizer
¶
Bases: BaseApi
Text-to-speech interface.
call
classmethod
¶
call(
model: str,
text: str,
api_key: str = None,
workspace: str = None,
**kwargs
) -> Union[
TextToSpeechResponse,
Generator[TextToSpeechResponse, None, None],
]
Call the conversation model service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The requested model, such as 'qwen-tts' |
required |
text
|
str
|
Text content used for speech synthesis. |
required |
api_key
|
str
|
The api api_key, can be None, if None, will retrieve by rule [1]. [1]: https://help.aliyun.com/zh/dashscope/developer-reference/api-key-settings. # noqa E501 # pylint: disable=line-too-long |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
**kwargs
|
Any
|
stream(bool, |
{}
|
Raises:
| Type | Description |
|---|---|
InputRequired
|
The input must include the text parameter. |
ModelRequired
|
The input must include the model parameter. |
Returns:
| Type | Description |
|---|---|
Union[TextToSpeechResponse, Generator[TextToSpeechResponse, None, None]]
|
Union[TextToSpeechResponse, Generator[TextToSpeechResponse, None, None]]: If |
Union[TextToSpeechResponse, Generator[TextToSpeechResponse, None, None]]
|
stream is True, return Generator, otherwise TextToSpeechResponse. |
Source code in dashscope/legacy_1x/audio/qwen_tts/speech_synthesizer.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
QwenTtsRealtime
¶
QwenTtsRealtime(
model,
headers=None,
callback: QwenTtsRealtimeCallback = None,
workspace=None,
url=None,
additional_params=None,
)
Qwen Tts Realtime SDK Parameters:
model: str Model name. headers: Dict User-defined headers. callback: OmniRealtimeCallback Callback to receive real-time omni results. workspace: str Dashscope workspace ID. url: str Dashscope WebSocket URL. additional_params: Dict Additional parameters for the Dashscope API.
Source code in dashscope/legacy_1x/audio/qwen_tts_realtime/qwen_tts_realtime.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
connect
¶
connect() -> None
connect to server, create session and return default session configuration # noqa: E501
Source code in dashscope/legacy_1x/audio/qwen_tts_realtime/qwen_tts_realtime.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
update_session
¶
update_session(
voice: str,
response_format: AudioFormat = AudioFormat.PCM_24000HZ_MONO_16BIT,
mode: str = "server_commit",
sample_rate: int = None,
volume: int = None,
speech_rate: float = None,
audio_format: str = None,
pitch_rate: float = None,
bit_rate: int = None,
language_type: str = None,
enable_tn: bool = None,
instructions: str = None,
optimize_instructions: bool = None,
**kwargs
) -> None
update session configuration, should be used before create response
Parameters¶
voice: str voice to be used in session response_format: AudioFormat output audio format mode: str response mode, server_commit or commit language_type: str language type for synthesized audio, default is 'auto' sample_rate: int sampleRate for tts, range [8000,16000,22050,24000,44100,48000] default is 24000 # noqa: E501 # pylint: disable=line-too-long volume: int volume for tts, range [0,100] default is 50 speech_rate: float speech_rate for tts, range [0.5~2.0] default is 1.0 audio_format: str format for tts, support mp3,wav,pcm,opus, default is 'pcm' pitch_rate: float pitch_rate for tts, range [0.5~2.0] default is 1.0 bit_rate: int bit_rate for tts, support 6~510,default is 128kbps. only work on format: opus/mp3 # noqa: E501 # pylint: disable=line-too-long enable_tn: bool enable text normalization for tts, default is None instructions: str instructions for tts, default is None optimize_instructions: bool optimize_instructions for tts, default is None
Source code in dashscope/legacy_1x/audio/qwen_tts_realtime/qwen_tts_realtime.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
append_text
¶
append_text(text: str) -> None
send text
Parameters¶
text: str text to send
Source code in dashscope/legacy_1x/audio/qwen_tts_realtime/qwen_tts_realtime.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
commit
¶
commit() -> None
commit the text sent before, create response and start synthesis audio.
Source code in dashscope/legacy_1x/audio/qwen_tts_realtime/qwen_tts_realtime.py
281 282 283 284 285 286 287 288 289 290 291 292 | |
clear_appended_text
¶
clear_appended_text() -> None
clear the text sent to server before.
Source code in dashscope/legacy_1x/audio/qwen_tts_realtime/qwen_tts_realtime.py
294 295 296 297 298 299 300 301 302 303 304 305 | |
cancel_response
¶
cancel_response() -> None
cancel the current response
Source code in dashscope/legacy_1x/audio/qwen_tts_realtime/qwen_tts_realtime.py
307 308 309 310 311 312 313 314 315 316 317 318 | |
send_raw
¶
send_raw(raw_data: str) -> None
send raw data to server
Source code in dashscope/legacy_1x/audio/qwen_tts_realtime/qwen_tts_realtime.py
320 321 322 323 324 | |
finish
¶
finish() -> None
finish input text stream, server will synthesis all text in buffer and close the connection # noqa: E501 # pylint: disable=line-too-long
Source code in dashscope/legacy_1x/audio/qwen_tts_realtime/qwen_tts_realtime.py
326 327 328 329 330 331 332 333 334 335 336 337 | |
close
¶
close() -> None
close the connection to server
Source code in dashscope/legacy_1x/audio/qwen_tts_realtime/qwen_tts_realtime.py
339 340 341 342 343 | |
on_message
¶
on_message(ws, message)
Source code in dashscope/legacy_1x/audio/qwen_tts_realtime/qwen_tts_realtime.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
on_close
¶
on_close(ws, close_status_code, close_msg)
Source code in dashscope/legacy_1x/audio/qwen_tts_realtime/qwen_tts_realtime.py
403 404 405 406 407 408 409 410 411 412 413 414 | |
on_error
¶
on_error(ws, error)
Source code in dashscope/legacy_1x/audio/qwen_tts_realtime/qwen_tts_realtime.py
417 418 | |
get_session_id
¶
get_session_id()
Source code in dashscope/legacy_1x/audio/qwen_tts_realtime/qwen_tts_realtime.py
423 424 | |
get_last_message
¶
get_last_message()
Source code in dashscope/legacy_1x/audio/qwen_tts_realtime/qwen_tts_realtime.py
426 427 | |
get_last_response_id
¶
get_last_response_id()
Source code in dashscope/legacy_1x/audio/qwen_tts_realtime/qwen_tts_realtime.py
429 430 | |
get_first_audio_delay
¶
get_first_audio_delay()
Source code in dashscope/legacy_1x/audio/qwen_tts_realtime/qwen_tts_realtime.py
432 433 | |
QwenTtsRealtimeCallback
¶
An interface that defines callback methods for getting omni-realtime results. # noqa E501 Derive from this class and implement its function to provide your own data.
on_open
¶
on_open() -> None
Source code in dashscope/legacy_1x/audio/qwen_tts_realtime/qwen_tts_realtime.py
24 25 | |
on_close
¶
on_close(close_status_code, close_msg) -> None
Source code in dashscope/legacy_1x/audio/qwen_tts_realtime/qwen_tts_realtime.py
27 28 | |
on_event
¶
on_event(message: str) -> None
Source code in dashscope/legacy_1x/audio/qwen_tts_realtime/qwen_tts_realtime.py
30 31 | |
Speech recognition (1.x)¶
Recognition
¶
Recognition(
model: str,
callback: RecognitionCallback,
format: str,
sample_rate: int,
workspace: str = None,
disfluency_removal_enabled: Optional[bool] = None,
diarization_enabled: Optional[bool] = None,
speaker_count: Optional[int] = None,
timestamp_alignment_enabled: Optional[bool] = None,
special_word_filter: Optional[str] = None,
audio_event_detection_enabled: Optional[bool] = None,
**kwargs
)
Bases: BaseApi
Speech recognition interface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The requested model_id. |
required |
callback
|
RecognitionCallback
|
A callback that returns speech recognition results. |
required |
format
|
str
|
The input audio format for speech recognition. |
required |
sample_rate
|
int
|
The input audio sample rate for speech recognition. |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
**kwargs
|
Any
|
phrase_id (list, |
{}
|
Raises:
| Type | Description |
|---|---|
InputRequired
|
Input is required. |
Source code in dashscope/legacy_1x/audio/asr/recognition.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
start
¶
start(
phrase_id: str = None,
disfluency_removal_enabled: Optional[bool] = None,
diarization_enabled: Optional[bool] = None,
speaker_count: Optional[int] = None,
timestamp_alignment_enabled: Optional[bool] = None,
special_word_filter: Optional[str] = None,
audio_event_detection_enabled: Optional[bool] = None,
**kwargs
)
Real-time speech recognition in asynchronous mode. Please call 'stop()' after you have completed recognition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phrase_id
|
str, `optional`
|
The ID of phrase. |
None
|
**kwargs
|
Any
|
disfluency_removal_enabled(bool, |
{}
|
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
This interface cannot be called again if it has already been started. |
InvalidTask
|
Task create failed. |
Source code in dashscope/legacy_1x/audio/asr/recognition.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 | |
call
¶
call(
file: str,
phrase_id: str = None,
disfluency_removal_enabled: Optional[bool] = None,
diarization_enabled: Optional[bool] = None,
speaker_count: Optional[int] = None,
timestamp_alignment_enabled: Optional[bool] = None,
special_word_filter: Optional[str] = None,
audio_event_detection_enabled: Optional[bool] = None,
**kwargs
) -> RecognitionResult
Real-time speech recognition in synchronous mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
The path to the local audio file. |
required |
phrase_id
|
str, `optional`
|
The ID of phrase. |
None
|
**kwargs
|
Any
|
disfluency_removal_enabled(bool, |
{}
|
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
This interface cannot be called again if it has already been started. |
InputDataRequired
|
The supplied file was empty. |
Returns:
| Name | Type | Description |
|---|---|---|
RecognitionResult |
RecognitionResult
|
The result of speech recognition. |
Source code in dashscope/legacy_1x/audio/asr/recognition.py
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 | |
stop
¶
stop()
End asynchronous speech recognition.
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
Cannot stop an uninitiated recognition. |
Source code in dashscope/legacy_1x/audio/asr/recognition.py
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 | |
send_audio_frame
¶
send_audio_frame(buffer: bytes)
Push speech recognition.
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
Cannot send data to an uninitiated recognition. |
Source code in dashscope/legacy_1x/audio/asr/recognition.py
620 621 622 623 624 625 626 627 628 629 630 631 632 | |
update_context
¶
update_context(payload_input: dict)
Update recognition context while the task is running.
The context is sent through a continue-task event and takes effect
on subsequent audio frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload_input
|
dict
|
Conversation context messages. |
required |
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
Cannot update an uninitiated recognition, or the context is None. |
Source code in dashscope/legacy_1x/audio/asr/recognition.py
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 | |
get_first_package_delay
¶
get_first_package_delay()
First Package Delay is the time between start sending audio and receive first words package
Source code in dashscope/legacy_1x/audio/asr/recognition.py
703 704 705 | |
get_last_package_delay
¶
get_last_package_delay()
Last Package Delay is the time between stop sending audio and receive last words package
Source code in dashscope/legacy_1x/audio/asr/recognition.py
707 708 709 | |
get_last_request_id
¶
get_last_request_id()
Source code in dashscope/legacy_1x/audio/asr/recognition.py
712 713 | |
RecognitionCallback
¶
An interface that defines callback methods for getting speech recognition results. # noqa E501 # pylint: disable=line-too-long Derive from this class and implement its function to provide your own data.
on_open
¶
on_open() -> None
Source code in dashscope/legacy_1x/audio/asr/recognition.py
147 148 | |
on_complete
¶
on_complete() -> None
Source code in dashscope/legacy_1x/audio/asr/recognition.py
150 151 | |
on_error
¶
on_error(result: RecognitionResult) -> None
Source code in dashscope/legacy_1x/audio/asr/recognition.py
153 154 | |
on_close
¶
on_close() -> None
Source code in dashscope/legacy_1x/audio/asr/recognition.py
156 157 | |
on_event
¶
on_event(result: RecognitionResult) -> None
Source code in dashscope/legacy_1x/audio/asr/recognition.py
159 160 | |
RecognitionResult
¶
RecognitionResult(
response: RecognitionResponse,
sentences: List[Any] = None,
usages: List[Any] = None,
)
Bases: RecognitionResponse
The result set of speech recognition, including the single-sentence recognition result returned by the callback mode, and all recognition results in a synchronized manner.
Source code in dashscope/legacy_1x/audio/asr/recognition.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
get_sentence
¶
get_sentence() -> Union[Dict[str, Any], List[Any]]
The result of speech recognition.
Source code in dashscope/legacy_1x/audio/asr/recognition.py
101 102 103 104 105 106 | |
get_request_id
¶
get_request_id() -> str
The request_id of speech recognition.
Source code in dashscope/legacy_1x/audio/asr/recognition.py
108 109 110 | |
get_usage
¶
get_usage(sentence: Dict[str, Any]) -> Dict[str, Any]
Get billing for the input sentence.
Source code in dashscope/legacy_1x/audio/asr/recognition.py
112 113 114 115 116 117 118 119 120 121 122 123 124 | |
is_sentence_end
staticmethod
¶
is_sentence_end(sentence: Dict[str, Any]) -> bool
Determine whether the speech recognition result is the end of a sentence. # noqa: E501 This is a static method.
Source code in dashscope/legacy_1x/audio/asr/recognition.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
Transcription
¶
Bases: BaseAsyncApi
API for File Transcription models.
Models
¶
call
classmethod
¶
call(
model: str,
file_urls: List[str],
phrase_id: str | None = None,
api_key: str | None = None,
workspace: str | None = None,
**kwargs: Any
) -> TranscriptionResponse
Transcribe the given files synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The requested model_id. |
required |
file_urls
|
List[str]
|
List of stored URLs. |
required |
phrase_id
|
str, `optional`
|
The ID of phrase. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
**kwargs
|
Any
|
channel_id (List[int], optional):
The selected channel_id of audio file.
disfluency_removal_enabled(bool, |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
TranscriptionResponse |
TranscriptionResponse
|
The result of batch transcription. |
Source code in dashscope/legacy_1x/audio/asr/transcription.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
async_call
classmethod
¶
async_call(
model: str,
file_urls: List[str],
phrase_id: str | None = None,
api_key: str | None = None,
workspace: str | None = None,
**kwargs: Any
) -> TranscriptionResponse
Transcribe the given files asynchronously, return the status of task submission for querying results subsequently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The requested model, such as paraformer-16k-1 |
required |
file_urls
|
List[str]
|
List of stored URLs. |
required |
phrase_id
|
str, `optional`
|
The ID of phrase. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
**kwargs:
channel_id (List[int], optional):
The selected channel_id of audio file.
disfluency_removal_enabled(bool, optional):
Filter mood words, turned off by default.
diarization_enabled (bool, optional):
Speech auto diarization, turned off by default.
speaker_count (int, optional): The number of speakers.
timestamp_alignment_enabled (bool, optional):
Timestamp-alignment calibration, turned off by default.
special_word_filter(str, optional): Sensitive word filter.
audio_event_detection_enabled(bool, optional):
Audio event detection, turned off by default.
Returns:
| Name | Type | Description |
|---|---|---|
TranscriptionResponse |
TranscriptionResponse
|
The response including task_id. |
Source code in dashscope/legacy_1x/audio/asr/transcription.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
fetch
classmethod
¶
fetch(
task: Any,
api_key: str | None = None,
workspace: str | None = None,
**kwargs: Any
) -> TranscriptionResponse
Fetch the status of task, including results of batch transcription when task_status is SUCCEEDED. # noqa: E501 # pylint: disable=line-too-long
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, TranscriptionResponse]
|
The task_id or response including task_id returned from async_call(). |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
TranscriptionResponse |
TranscriptionResponse
|
The status of task_id, |
including results of batch transcription when task_status is SUCCEEDED.
Source code in dashscope/legacy_1x/audio/asr/transcription.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
wait
classmethod
¶
wait(
task: Any,
api_key: str | None = None,
workspace: str | None = None,
wait_timeout: int | None = -1,
**kwargs: Any
) -> TranscriptionResponse
Poll task until the final results of transcription is obtained.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, TranscriptionResponse]
|
The task_id or response including task_id returned from async_call(). |
required |
api_key
|
str
|
The api_key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
wait_timeout
|
int
|
The timeout for waiting. Defaults to -1.That means no timeout. If set to a value > 0, the task does not complete within this time, a timeout error response will be returned. |
-1
|
Returns:
| Name | Type | Description |
|---|---|---|
TranscriptionResponse |
TranscriptionResponse
|
The result of batch transcription. |
Source code in dashscope/legacy_1x/audio/asr/transcription.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
AsrPhraseManager
¶
Bases: BaseAsyncApi
Hot word management for speech recognition.
create_phrases
classmethod
¶
create_phrases(
model: str,
phrases: Dict[str, Any],
training_type: str = "compile_asr_phrase",
workspace: str = None,
**kwargs
) -> DashScopeAPIResponse
Create hot words.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The requested model. |
required |
phrases
|
Dict[str, Any]
|
A dictionary that contains phrases, such as {'下一首':90,'上一首':90}. |
required |
training_type
|
str, `optional`
|
The training type, 'compile_asr_phrase' is default. |
'compile_asr_phrase'
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
Parameter input is None or empty! |
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The results of creating hot words. |
Source code in dashscope/legacy_1x/audio/asr/asr_phrase_manager.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
update_phrases
classmethod
¶
update_phrases(
model: str,
phrase_id: str,
phrases: Dict[str, Any],
training_type: str = "compile_asr_phrase",
workspace: str = None,
**kwargs
) -> DashScopeAPIResponse
Update the hot words marked phrase_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The requested model. |
required |
phrase_id
|
str
|
The ID of phrases, which created by create_phrases(). |
required |
phrases
|
Dict[str, Any]
|
A dictionary that contains phrases, such as {'暂停':90}. |
required |
training_type
|
str, `optional`
|
The training type, 'compile_asr_phrase' is default. |
'compile_asr_phrase'
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
Parameter input is None or empty! |
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The results of updating hot words. |
Source code in dashscope/legacy_1x/audio/asr/asr_phrase_manager.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
query_phrases
classmethod
¶
query_phrases(
phrase_id: str, workspace: str = None, **kwargs
) -> DashScopeAPIResponse
Query the hot words by phrase_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phrase_id
|
str
|
The ID of phrases, which created by create_phrases(). |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
phrase_id input is None or empty! |
Returns:
| Name | Type | Description |
|---|---|---|
AsrPhraseManagerResult |
DashScopeAPIResponse
|
The results of querying hot words. |
Source code in dashscope/legacy_1x/audio/asr/asr_phrase_manager.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
list_phrases
classmethod
¶
list_phrases(
page: int = 1,
page_size: int = 10,
workspace: str = None,
**kwargs
) -> DashScopeAPIResponse
List all information of phrases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page
|
int
|
Page number, greater than 0, default value 1. |
1
|
page_size
|
int
|
The paging size, greater than 0 and less than or equal to 100, default value 10. |
10
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The results of listing hot words. |
Source code in dashscope/legacy_1x/audio/asr/asr_phrase_manager.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
delete_phrases
classmethod
¶
delete_phrases(
phrase_id: str, workspace: str = None, **kwargs
) -> DashScopeAPIResponse
Delete the hot words by phrase_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phrase_id
|
str
|
The ID of phrases, which created by create_phrases(). |
required |
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
phrase_id input is None or empty! |
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The results of deleting hot words. |
Source code in dashscope/legacy_1x/audio/asr/asr_phrase_manager.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
TranslationRecognizerRealtime
¶
TranslationRecognizerRealtime(
model: str,
callback: TranslationRecognizerCallback,
format: str,
sample_rate: int,
transcription_enabled: bool = True,
source_language: str = None,
translation_enabled: bool = False,
workspace: str = None,
disfluency_removal_enabled: Optional[bool] = None,
diarization_enabled: Optional[bool] = None,
speaker_count: Optional[int] = None,
timestamp_alignment_enabled: Optional[bool] = None,
special_word_filter: Optional[str] = None,
audio_event_detection_enabled: Optional[bool] = None,
**kwargs
)
Bases: BaseApi
TranslationRecognizerRealtime interface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The requested model_id. |
required |
callback
|
TranslationRecognizerRealtime
|
A callback that returns TranslationRecognizerRealtime results. |
required |
format
|
str
|
The input audio format. |
required |
sample_rate
|
int
|
The input audio sample rate. |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
**kwargs
|
Any
|
phrase_id (list, |
{}
|
Raises:
| Type | Description |
|---|---|
InputRequired
|
Input is required. |
Source code in dashscope/legacy_1x/audio/asr/translation_recognizer.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
start
¶
start(
disfluency_removal_enabled: Optional[bool] = None,
diarization_enabled: Optional[bool] = None,
speaker_count: Optional[int] = None,
timestamp_alignment_enabled: Optional[bool] = None,
special_word_filter: Optional[str] = None,
audio_event_detection_enabled: Optional[bool] = None,
**kwargs
)
Real-time translation recognizer in asynchronous mode. Please call 'stop()' after you have completed translation & recognition. # noqa: E501
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
phrase_id (str, |
{}
|
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
This interface cannot be called again if it has already been started. |
InvalidTask
|
Task create failed. |
Source code in dashscope/legacy_1x/audio/asr/translation_recognizer.py
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | |
call
¶
call(
file: str,
phrase_id: str = None,
disfluency_removal_enabled: Optional[bool] = None,
diarization_enabled: Optional[bool] = None,
speaker_count: Optional[int] = None,
timestamp_alignment_enabled: Optional[bool] = None,
special_word_filter: Optional[str] = None,
audio_event_detection_enabled: Optional[bool] = None,
**kwargs
) -> TranslationRecognizerResultPack
TranslationRecognizerRealtime in synchronous mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
The path to the local audio file. |
required |
phrase_id
|
str, `optional`
|
The ID of phrase. |
None
|
**kwargs
|
Any
|
disfluency_removal_enabled(bool, |
{}
|
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
This interface cannot be called again if it has already been started. |
InputDataRequired
|
The supplied file was empty. |
Returns:
| Name | Type | Description |
|---|---|---|
TranslationRecognizerResultPack |
TranslationRecognizerResultPack
|
The result of speech translation & recognition. # noqa: E501 # pylint: disable=line-too-long |
Source code in dashscope/legacy_1x/audio/asr/translation_recognizer.py
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 | |
stop
¶
stop()
End asynchronous TranslationRecognizerRealtime.
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
Cannot stop an uninitiated TranslationRecognizerRealtime. # noqa: E501 # pylint: disable=line-too-long |
Source code in dashscope/legacy_1x/audio/asr/translation_recognizer.py
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 | |
send_audio_frame
¶
send_audio_frame(buffer: bytes)
Push audio to TranslationRecognizerRealtime.
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
Cannot send data to an uninitiated TranslationRecognizerRealtime. # noqa: E501 # pylint: disable=line-too-long |
Source code in dashscope/legacy_1x/audio/asr/translation_recognizer.py
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 | |
get_first_package_delay
¶
get_first_package_delay()
First Package Delay is the time between start sending audio and receive first words package
Source code in dashscope/legacy_1x/audio/asr/translation_recognizer.py
793 794 795 | |
get_last_package_delay
¶
get_last_package_delay()
Last Package Delay is the time between stop sending audio and receive last words package
Source code in dashscope/legacy_1x/audio/asr/translation_recognizer.py
797 798 799 | |
get_last_request_id
¶
get_last_request_id()
Source code in dashscope/legacy_1x/audio/asr/translation_recognizer.py
802 803 | |
TranslationRecognizerChat
¶
TranslationRecognizerChat(
model: str,
callback: TranslationRecognizerCallback,
format: str,
sample_rate: int,
transcription_enabled: bool = True,
source_language: str = None,
translation_enabled: bool = False,
workspace: str = None,
disfluency_removal_enabled: Optional[bool] = None,
diarization_enabled: Optional[bool] = None,
speaker_count: Optional[int] = None,
timestamp_alignment_enabled: Optional[bool] = None,
special_word_filter: Optional[str] = None,
audio_event_detection_enabled: Optional[bool] = None,
**kwargs
)
Bases: BaseApi
TranslationRecognizerChat interface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The requested model_id. |
required |
callback
|
TranslationRecognizerChat
|
A callback that returns TranslationRecognizerChat results. |
required |
format
|
str
|
The input audio format. |
required |
sample_rate
|
int
|
The input audio sample rate. |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
**kwargs
|
Any
|
phrase_id (list, |
{}
|
Raises:
| Type | Description |
|---|---|
InputRequired
|
Input is required. |
Source code in dashscope/legacy_1x/audio/asr/translation_recognizer.py
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 | |
start
¶
start(
disfluency_removal_enabled: Optional[bool] = None,
diarization_enabled: Optional[bool] = None,
speaker_count: Optional[int] = None,
timestamp_alignment_enabled: Optional[bool] = None,
special_word_filter: Optional[str] = None,
audio_event_detection_enabled: Optional[bool] = None,
**kwargs
)
Real-time translation recognizer in asynchronous mode. Please call 'stop()' after you have completed translation & recognition. # noqa: E501
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
phrase_id (str, |
{}
|
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
This interface cannot be called again if it has already been started. |
InvalidTask
|
Task create failed. |
Source code in dashscope/legacy_1x/audio/asr/translation_recognizer.py
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 | |
stop
¶
stop()
End asynchronous TranslationRecognizerChat.
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
Cannot stop an uninitiated TranslationRecognizerChat. # noqa: E501 |
Source code in dashscope/legacy_1x/audio/asr/translation_recognizer.py
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 | |
send_audio_frame
¶
send_audio_frame(buffer: bytes) -> bool
Push audio to TranslationRecognizerChat.
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
Cannot send data to an uninitiated TranslationRecognizerChat. # noqa: E501 # pylint: disable=line-too-long |
Source code in dashscope/legacy_1x/audio/asr/translation_recognizer.py
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 | |
get_first_package_delay
¶
get_first_package_delay()
First Package Delay is the time between start sending audio and receive first words package
Source code in dashscope/legacy_1x/audio/asr/translation_recognizer.py
1172 1173 1174 | |
get_last_package_delay
¶
get_last_package_delay()
Last Package Delay is the time between stop sending audio and receive last words package
Source code in dashscope/legacy_1x/audio/asr/translation_recognizer.py
1176 1177 1178 | |
get_last_request_id
¶
get_last_request_id()
Source code in dashscope/legacy_1x/audio/asr/translation_recognizer.py
1181 1182 | |
TranslationRecognizerCallback
¶
An interface that defines callback methods for getting translation recognizer results. # noqa E501 # pylint: disable=line-too-long Derive from this class and implement its function to provide your own data.
on_open
¶
on_open() -> None
Source code in dashscope/legacy_1x/audio/asr/translation_recognizer.py
266 267 | |
on_complete
¶
on_complete() -> None
Source code in dashscope/legacy_1x/audio/asr/translation_recognizer.py
269 270 | |
on_error
¶
on_error(message) -> None
Source code in dashscope/legacy_1x/audio/asr/translation_recognizer.py
272 273 | |
on_close
¶
on_close() -> None
Source code in dashscope/legacy_1x/audio/asr/translation_recognizer.py
275 276 | |
on_event
¶
on_event(
request_id,
transcription_result: TranscriptionResult,
translation_result: TranslationResult,
usage,
) -> None
Source code in dashscope/legacy_1x/audio/asr/translation_recognizer.py
278 279 280 281 282 283 284 285 | |
QwenTranscription
¶
Bases: BaseAsyncApi
API for File Transcription models.
call
classmethod
¶
call(
model: str,
file_url: str,
api_key: str = None,
workspace: str = None,
**kwargs
) -> TranscriptionResponse
Transcribe the given files synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The requested model_id. |
required |
file_url
|
str
|
stored URL. |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
TranscriptionResponse |
TranscriptionResponse
|
The result of batch transcription. |
Source code in dashscope/legacy_1x/audio/qwen_asr/qwen_transcription.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
async_call
classmethod
¶
async_call(
model: str,
file_url: str,
api_key: str = None,
workspace: str = None,
**kwargs
) -> TranscriptionResponse
Transcribe the given files asynchronously, return the status of task submission for querying results subsequently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The requested model, such as paraformer-16k-1 |
required |
file_url
|
str
|
stored URL. |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
TranscriptionResponse |
TranscriptionResponse
|
The response including task_id. |
Source code in dashscope/legacy_1x/audio/qwen_asr/qwen_transcription.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
fetch
classmethod
¶
fetch(
task: Union[str, TranscriptionResponse],
api_key: str = None,
workspace: str = None,
**kwargs
) -> TranscriptionResponse
Fetch the status of task, including results of batch transcription when task_status is SUCCEEDED. # noqa: E501 # pylint: disable=line-too-long
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, TranscriptionResponse]
|
The task_id or response including task_id returned from async_call(). |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
TranscriptionResponse |
TranscriptionResponse
|
The status of task_id, |
including results of batch transcription when task_status is SUCCEEDED.
Source code in dashscope/legacy_1x/audio/qwen_asr/qwen_transcription.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
wait
classmethod
¶
wait(
task: Union[str, TranscriptionResponse],
api_key: str = None,
workspace: str = None,
wait_timeout: int = -1,
**kwargs
) -> TranscriptionResponse
Poll task until the final results of transcription is obtained.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Union[str, TranscriptionResponse]
|
The task_id or response including task_id returned from async_call(). |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
wait_timeout
|
int
|
The maximum seconds to wait. Default is -1 (no timeout). |
-1
|
Returns:
| Name | Type | Description |
|---|---|---|
TranscriptionResponse |
TranscriptionResponse
|
The result of batch transcription. |
Source code in dashscope/legacy_1x/audio/qwen_asr/qwen_transcription.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
Omni realtime (1.x)¶
OmniRealtimeConversation
¶
OmniRealtimeConversation(
model,
callback: OmniRealtimeCallback,
headers=None,
workspace=None,
url=None,
api_key: str = None,
additional_params=None,
)
Qwen Omni Realtime SDK Parameters:
model: str Model name. headers: Dict User-defined headers. callback: OmniRealtimeCallback Callback to receive real-time omni results. workspace: str Dashscope workspace ID. url: str Dashscope WebSocket URL. additional_params: Dict Additional parameters for the Dashscope API.
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
connect
¶
connect() -> None
connect to server, create session and return default session configuration # noqa: E501
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
create_item
¶
create_item(item: dict)
send item.create request
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
update_session
¶
update_session(
output_modalities: List[MultiModality],
voice: str = None,
input_audio_format: AudioFormat = AudioFormat.PCM_16000HZ_MONO_16BIT,
output_audio_format: AudioFormat = AudioFormat.PCM_24000HZ_MONO_16BIT,
enable_input_audio_transcription: bool = True,
input_audio_transcription_model: str = None,
enable_turn_detection: bool = True,
turn_detection_type: str = "server_vad",
prefix_padding_ms: int = 300,
turn_detection_threshold: float = 0.2,
turn_detection_silence_duration_ms: int = 800,
turn_detection_param: dict = None,
translation_params: TranslationParams = None,
transcription_params: TranscriptionParams = None,
input_audio_config: AudioFormatConfig = None,
output_audio_config: AudioFormatConfig = None,
input_video_representation_compact: str = None,
**kwargs
) -> None
update session configuration, should be used before create response
Parameters¶
output_modalities: list[MultiModality]
omni output modalities to be used in session
voice: str
voice to be used in session
input_audio_format: AudioFormat
input audio format. Legacy parameter, kept for backward
compatibility and still the default path. Prefer
input_audio_config which supports separate audio format
type and sample rate.
output_audio_format: AudioFormat
output audio format. Legacy parameter, kept for backward
compatibility and still the default path. Prefer
output_audio_config which supports separate audio format
type and sample rate.
enable_turn_detection: bool
enable turn detection
turn_detection_threshold: float
turn detection threshold, range [-1, 1]
In a noisy environment, it may be necessary to increase the threshold to reduce false detections # noqa: E501 # pylint: disable=line-too-long
In a quiet environment, it may be necessary to decrease the threshold to improve sensitivity # noqa: E501 # pylint: disable=line-too-long
turn_detection_silence_duration_ms: int
duration of silence in milliseconds to detect turn, range [200, 6000] # noqa: E501
translation_params: TranslationParams
translation params, include language. Only effective with qwen3-livetranslate-flash-realtime model or # noqa: E501 # pylint: disable=line-too-long
further models. Do not set this parameter for other models.
transcription_params: TranscriptionParams
transcription params, include language, sample_rate, input_audio_format, corpus. # noqa: E501 # pylint: disable=line-too-long
Only effective with qwen3-asr-flash-realtime model or
further models. Do not set this parameter for other models.
input_audio_config: AudioFormatConfig
input(uplink) audio format config. Supports separate format type
(pcm/wav) and sample rate (8000/16000/24000/48000), as well as
free extension parameters via extra_params. When provided,
the request emits the session.audio.input.format structure.
output_audio_config: AudioFormatConfig
output(downlink) audio format config. Supports separate format
type (pcm/wav) and sample rate (8000/16000/24000/48000), as well
as free extension parameters via extra_params. When provided,
the request emits the session.audio.output.format structure.
input_video_representation_compact: str
input video representation compact setting. When provided, the
request emits session.video.input.representation_compact and
passes the string value through without client-side validation.
Notes¶
Once either input_audio_config or output_audio_config is
provided, the legacy top-level input_audio_format /
output_audio_format fields are not sent; an unspecified side
falls back to the server-side default. The top-level format fields
from transcription_params are also skipped in this case.
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 | |
end_session
¶
end_session(timeout: int = 20) -> None
end session
Parameters:¶
timeout: int Timeout in seconds to wait for the session to end. Default is 20 seconds. # noqa: E501
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | |
end_session_async
¶
end_session_async() -> None
end session asynchronously. you need close the connection manually
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
577 578 579 580 581 582 583 584 585 586 587 588 589 | |
append_audio
¶
append_audio(audio_b64: str) -> None
send audio in base64 format
Parameters¶
audio_b64: str base64 audio string
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
append_video
¶
append_video(video_b64: str) -> None
send one image frame in video in base64 format
Parameters¶
video_b64: str base64 image string
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 | |
commit
¶
commit() -> None
Commit the audio and video sent before. When in Server VAD mode, the client does not need to use this method, the server will commit the audio automatically after detecting vad end.
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
633 634 635 636 637 638 639 640 641 642 643 644 645 646 | |
clear_appended_audio
¶
clear_appended_audio() -> None
clear the audio sent to server before.
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
648 649 650 651 652 653 654 655 656 657 658 659 | |
create_response
¶
create_response(
instructions: str = None,
output_modalities: List[MultiModality] = None,
) -> None
create response, use audio and video commited before to request llm. When in Server VAD mode, the client does not need to use this method, the server will create response automatically after detecting vad and sending commit.
Parameters¶
instructions: str instructions to llm output_modalities: list[MultiModality] omni output modalities to be used in session
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 | |
cancel_response
¶
cancel_response() -> None
cancel the current response
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
691 692 693 694 695 696 697 698 699 700 701 702 | |
send_raw
¶
send_raw(raw_data: str) -> None
send raw data to server
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
704 705 706 707 708 | |
close
¶
close() -> None
close the connection to server
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
710 711 712 713 714 | |
get_session_id
¶
get_session_id() -> str
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
811 812 | |
get_last_message
¶
get_last_message() -> str
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
814 815 | |
get_last_response_id
¶
get_last_response_id() -> str
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
817 818 | |
get_last_first_text_delay
¶
get_last_first_text_delay()
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
820 821 | |
get_last_first_audio_delay
¶
get_last_first_audio_delay()
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
823 824 | |
OmniRealtimeCallback
¶
An interface that defines callback methods for getting omni-realtime results. # noqa E501 Derive from this class and implement its function to provide your own data.
on_open
¶
on_open() -> None
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
26 27 | |
on_close
¶
on_close(close_status_code, close_msg) -> None
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
29 30 | |
on_event
¶
on_event(message: str) -> None
Source code in dashscope/legacy_1x/audio/qwen_omni/omni_realtime.py
32 33 | |
Files & models (1.x)¶
Files
¶
Bases: FileUploadMixin, ListMixin, DeleteMixin, GetMixin
upload
classmethod
¶
upload(
file_path: str,
purpose: str = FilePurpose.fine_tune,
description: Optional[str] = None,
api_key: str = None,
workspace: str = None,
**kwargs
) -> DashScopeAPIResponse
Upload file for model fine-tune or other tasks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
The local file name to upload. |
required |
purpose
|
str
|
The purpose of the file[fine-tune|inference] |
fine_tune
|
description
|
str
|
The file description message. |
None
|
api_key
|
str
|
The api key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The upload information |
Source code in dashscope/legacy_1x/files.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
list
classmethod
¶
list(
page=1,
page_size=10,
api_key: str = None,
workspace: str = None,
**kwargs
) -> DashScopeAPIResponse
List uploaded files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str
|
The api api_key, can be None, if None, will get by default rule(TODO: api key doc). |
None
|
page
|
int
|
Page number. Defaults to 1. |
1
|
page_size
|
int
|
Items per page. Defaults to 10. |
10
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The fine-tune jobs in the result. |
Source code in dashscope/legacy_1x/files.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
get
classmethod
¶
get(
file_id: str,
api_key: str = None,
workspace: str = None,
**kwargs
) -> DashScopeAPIResponse
Get the file info.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_id
|
str
|
The file id. |
required |
api_key
|
str
|
The api key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The job info |
Source code in dashscope/legacy_1x/files.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
delete
classmethod
¶
delete(
file_id: str,
api_key: str = None,
workspace: str = None,
**kwargs
) -> DashScopeAPIResponse
Delete uploaded file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_id
|
str
|
The file id want to delete. |
required |
api_key
|
str
|
The api key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
Delete result. |
Source code in dashscope/legacy_1x/files.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
Models
¶
Bases: ListMixin, GetMixin
get
classmethod
¶
get(
name: str, api_key: str = None, **kwargs
) -> DashScopeAPIResponse
Get the model information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The model name. |
required |
api_key
|
str
|
The api key. Defaults to None. |
None
|
**kwargs
|
Any
|
workspace (str): The dashscope workspace id. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The model information. |
Source code in dashscope/legacy_1x/models.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
list
classmethod
¶
list(
page=1, page_size=10, api_key: str = None, **kwargs
) -> DashScopeAPIResponse
List models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str
|
The api key |
None
|
page
|
int
|
Page number. Defaults to 1. |
1
|
page_size
|
int
|
Items per page. Defaults to 10. |
10
|
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The models. |
Source code in dashscope/legacy_1x/models.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
Fine-tuning & deployments (1.x)¶
FineTunes
¶
Bases: CreateMixin, CancelMixin, DeleteMixin, ListMixin, GetStatusMixin, StreamEventMixin, LogMixin
call
classmethod
¶
call(
model: str,
training_file_ids: Union[list, str],
validation_file_ids: Union[list, str] | None = None,
mode: str | None = None,
hyper_parameters: dict | None = {},
api_key: str = None,
workspace: str = None,
**kwargs: Any
) -> Any
Create fine-tune job
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The model to be fine-tuned |
required |
training_file_ids
|
(list, str)
|
Ids of the fine-tune training data, which can be pre-uploaded using the File API. |
required |
validation_file_ids
|
[list, str]
|
Ids of the fine-tune validating data, which can be pre-uploaded using the File API. |
None
|
mode
|
str
|
The fine-tune mode, sft or efficient_sft. |
None
|
hyper_parameters
|
dict
|
The fine-tune hyper parameters. Defaults to empty. |
{}
|
api_key
|
str
|
The api key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
FineTune |
Any
|
The request result. |
Source code in dashscope/legacy_1x/finetune/finetunes.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
cancel
classmethod
¶
cancel(
job_id: str,
api_key: str | None = None,
workspace: str | None = None,
**kwargs: Any
) -> Any
Cancel a running fine-tune job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
The fine-tune job id. |
required |
api_key
|
str
|
The api api_key, can be None, if None, will get by default rule(TODO: api key doc). |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
FineTune |
Any
|
The request result. |
Source code in dashscope/legacy_1x/finetune/finetunes.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
list
classmethod
¶
list(
page_no: int = 1,
page_size: int = 10,
api_key: str | None = None,
workspace: str | None = None,
**kwargs: Any
) -> Any
List fine-tune job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str
|
The api key |
None
|
page_no
|
int
|
Page number. Defaults to 1. |
1
|
page_size
|
int
|
Items per page. Defaults to 10. |
10
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
FineTune |
Any
|
The fine-tune jobs in the result. |
Source code in dashscope/legacy_1x/finetune/finetunes.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
get
classmethod
¶
get(
job_id: str,
api_key: str | None = None,
workspace: str | None = None,
**kwargs: Any
) -> Any
Get fine-tune job information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
The fine-tune job id |
required |
api_key
|
str
|
The api key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
FineTune |
Any
|
The job info |
Source code in dashscope/legacy_1x/finetune/finetunes.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
delete
classmethod
¶
delete(
job_id: str,
api_key: str | None = None,
workspace: str | None = None,
**kwargs: Any
) -> Any
Delete a fine-tune job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
The fine-tune job id. |
required |
api_key
|
str
|
The api key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
FineTune |
Any
|
The delete result. |
Source code in dashscope/legacy_1x/finetune/finetunes.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
stream_events
classmethod
¶
stream_events(
job_id: str,
api_key: str = None,
workspace: str = None,
**kwargs
) -> Iterator[FineTuneEvent]
Get fine-tune job events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
The fine-tune job id |
required |
api_key
|
str
|
the api key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
FineTune |
Iterator[FineTuneEvent]
|
The job log events. |
Source code in dashscope/legacy_1x/finetune/finetunes.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
logs
classmethod
¶
logs(
job_id: str,
*,
offset: int = 1,
line: int = 1000,
api_key: str = None,
workspace: str = None,
**kwargs
) -> FineTune
Get log of the job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
The job id(used for fine-tune) |
required |
offset
|
int
|
start log line. Defaults to 1. |
1
|
line
|
int
|
total line return. Defaults to 1000. |
1000
|
api_key
|
str
|
The api key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
FineTune |
FineTune
|
The response |
Source code in dashscope/legacy_1x/finetune/finetunes.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
wait
classmethod
¶
wait(
job_id: str,
api_key: str = None,
workspace: str = None,
**kwargs
)
Source code in dashscope/legacy_1x/finetune/finetunes.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
Deployments
¶
Bases: CreateMixin, DeleteMixin, ListMixin, GetMixin, StreamEventMixin, PutMixin
call
classmethod
¶
call(
model: str,
capacity: int,
version: str = None,
suffix: str | None = None,
plan: Optional[str] = None,
template_id: Optional[str] = None,
api_key: str | None = None,
workspace: str = None,
**kwargs: Any
) -> Any
Call to deployment a model service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The model name. |
required |
capacity
|
int
|
The model service capacity. |
required |
version
|
str
|
The model version, unnecessary for fine-tuned model. Defaults to None. |
None
|
suffix
|
str
|
The name suffix of the model deployment, If specified, the final model name will be model_suffix. Defaults to None. |
None
|
plan
|
str
|
The deployment plan required by the service: "ptu" (PTU reserved), "mu" (model unit) or "Lora" (LoRA deployment). Defaults to None. |
None
|
template_id
|
str
|
Template ID for deployment configuration. Defaults to None. |
None
|
api_key
|
str
|
The api-key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Deployment |
Any
|
description |
Source code in dashscope/legacy_1x/finetune/deployments.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
list
classmethod
¶
list(
page_no: int = 1,
page_size: int = 10,
api_key: str | None = None,
workspace: str | None = None,
**kwargs: Any
) -> Any
List deployments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str
|
The api api_key, if not present, will get by default rule(TODO: api key doc). Defaults to None. |
None
|
page_no
|
int
|
Page number. Defaults to 1. |
1
|
page_size
|
int
|
Items per page. Defaults to 10. |
10
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Deployment |
Any
|
The deployment list. |
Source code in dashscope/legacy_1x/finetune/deployments.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
get
classmethod
¶
get(
deployed_model: str,
api_key: str | None = None,
workspace: str | None = None,
**kwargs: Any
) -> Any
Get model deployment information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deployed_model
|
str
|
The deployment_id. |
required |
api_key
|
str
|
The api key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Deployment |
Any
|
The deployment information. |
Source code in dashscope/legacy_1x/finetune/deployments.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
delete
classmethod
¶
delete(
deployed_model: str,
api_key: str | None = None,
workspace: str | None = None,
**kwargs: Any
) -> Any
Delete model deployment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deployed_model
|
str
|
The deployment id. |
required |
api_key
|
str
|
The api key. Defaults to None. |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Deployment |
Any
|
The delete result. |
Source code in dashscope/legacy_1x/finetune/deployments.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
scale
classmethod
¶
scale(
deployed_model: str,
capacity: int,
api_key: str | None = None,
workspace: str | None = None,
**kwargs: Any
) -> Any
Scaling model deployment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deployed_model
|
str
|
The deployed model id. |
required |
capacity
|
int
|
The target service capacity. |
required |
api_key
|
str
|
The api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Deployment |
Any
|
The delete result. |
Source code in dashscope/legacy_1x/finetune/deployments.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
Tokenizers¶
Tokenization
¶
Bases: BaseApi
Models
¶
List of models currently supported
call
classmethod
¶
call(
model: str,
input: Any = None,
prompt: Any = None,
history: list = None,
api_key: str = None,
messages: List[Message] = None,
workspace: str = None,
**kwargs: Any
) -> DashScopeAPIResponse
Call tokenization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The requested model, such as qwen-v1 |
required |
input
|
Any
|
(Any): The model input body. |
None
|
prompt
|
Any
|
The input prompt, for qwen serial model. |
None
|
history
|
list
|
The user provided history, deprecated, use messages instead. examples: [{'user':'The weather is fine today.', 'bot': 'Suitable for outings'}]. Defaults to None. |
None
|
api_key
|
str
|
The api api_key, can be None, if None, will get by default rule(TODO: api key doc). |
None
|
messages
|
list
|
The generation messages. examples: [{'role': 'user', 'content': 'The weather is fine today.'}, {'role': 'assistant', 'content': 'Suitable for outings'}] |
None
|
workspace
|
str
|
The dashscope workspace id. |
None
|
**kwargs
|
Any
|
see model input. |
{}
|
Raises:
| Type | Description |
|---|---|
InputRequired
|
input is required. |
ModelRequired
|
model is required. |
Returns:
| Name | Type | Description |
|---|---|---|
DashScopeAPIResponse |
DashScopeAPIResponse
|
The tokenizer output. |
Source code in dashscope/legacy_1x/tokenizers/tokenization.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
Tokenizer
¶
Tokenizer()
Base tokenizer interface for local tokenizers.
Source code in dashscope/legacy_1x/tokenizers/tokenizer_base.py
10 11 | |
encode
¶
encode(text: str, **kwargs: Any) -> List[int]
Encode input text string to token ids.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The string to be encoded. |
required |
Returns:
| Type | Description |
|---|---|
List[int]
|
List[int]: The token ids. |
Source code in dashscope/legacy_1x/tokenizers/tokenizer_base.py
13 14 15 16 17 18 19 20 21 | |
decode
¶
decode(token_ids: List[int], **kwargs: Any) -> str
Decode token ids to string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_ids
|
List[int]
|
The input token ids. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The string of the token ids. |
Source code in dashscope/legacy_1x/tokenizers/tokenizer_base.py
23 24 25 26 27 28 29 30 31 | |
get_tokenizer
¶
get_tokenizer(model: str) -> Tokenizer
Get a tokenizer based on model name.
The vocab file is downloaded on first use from ModelScope into
~/.cache/dashscope/tokenizers.
Set DASHSCOPE_QWEN_VOCAB to a local file path for offline use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The model name. |
required |
Raises:
| Type | Description |
|---|---|
UnsupportedModel
|
Not support model |
Returns:
| Name | Type | Description |
|---|---|---|
Tokenizer |
Tokenizer
|
The |
Source code in dashscope/legacy_1x/tokenizers/tokenizer.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
list_tokenizers
¶
list_tokenizers() -> List[str]
List support models
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: The model list. |
Source code in dashscope/legacy_1x/tokenizers/tokenizer.py
109 110 111 112 113 114 115 | |
Assistants & Threads (deprecated)¶
The Assistants API is deprecated; accessing these names emits a
DeprecationWarning.
Assistants
¶
Bases: CreateMixin, CancelMixin, DeleteMixin, ListObjectMixin, GetStatusMixin, UpdateMixin
.. deprecated:: The Assistants API is deprecated and will be removed in a future release. Please migrate to the Responses API. See https://help.aliyun.com/zh/model-studio/ synchronous-call-api-reference for migration details.
call
classmethod
¶
call(
*,
model: str,
name: str = None,
description: str = None,
instructions: str = None,
tools: Optional[List[Dict]] = None,
file_ids: Optional[List[str]] = [],
metadata: Dict = None,
workspace: str = None,
api_key: str = None,
**kwargs
) -> Assistant
Create Assistant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The model to use. |
required |
name
|
str
|
The assistant name. Defaults to None. |
None
|
description
|
str
|
The assistant description. Defaults to None. |
None
|
instructions
|
str
|
The system instructions this assistant uses. Defaults to None. |
None
|
tools
|
Optional[List[Dict]]
|
List of tools to use. Defaults to []. |
None
|
file_ids
|
Optional[List[str]]
|
: The files to use. Defaults to []. |
[]
|
metadata
|
Dict
|
Custom key-value pairs associate with assistant. Defaults to None. |
None
|
workspace
|
str
|
The DashScope workspace id. Defaults to None. |
None
|
api_key
|
str
|
The DashScope api key. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
ModelRequired
|
The model is required. |
Returns:
| Name | Type | Description |
|---|---|---|
Assistant |
Assistant
|
The |
Source code in dashscope/legacy_1x/assistants/assistants.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
create
classmethod
¶
create(
*,
model: str,
name: str = None,
description: str = None,
instructions: str = None,
tools: Optional[List[Dict]] = None,
file_ids: Optional[List[str]] = [],
metadata: Dict = None,
workspace: str = None,
api_key: str = None,
top_p: Optional[float] = None,
top_k: Optional[int] = None,
temperature: Optional[float] = None,
max_tokens: Optional[int] = None,
**kwargs
) -> Assistant
Create Assistant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The model to use. |
required |
name
|
str
|
The assistant name. Defaults to None. |
None
|
description
|
str
|
The assistant description. Defaults to None. |
None
|
instructions
|
str
|
The system instructions this assistant uses. Defaults to None. |
None
|
tools
|
Optional[List[Dict]]
|
List of tools to use. Defaults to []. |
None
|
file_ids
|
Optional[List[str]]
|
: The files to use. Defaults to []. |
[]
|
metadata
|
Dict
|
Custom key-value pairs associate with assistant. Defaults to None. |
None
|
workspace
|
str
|
The DashScope workspace id. Defaults to None. |
None
|
api_key
|
str
|
The DashScope api key. Defaults to None. |
None
|
top_p
|
float
|
top_p parameter for model. Defaults to None. |
None
|
top_k
|
int
|
top_p parameter for model. Defaults to None. |
None
|
temperature
|
float
|
temperature parameter for model. Defaults to None. |
None
|
max_tokens
|
int
|
max_tokens parameter for model. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
ModelRequired
|
The model is required. |
Returns:
| Name | Type | Description |
|---|---|---|
Assistant |
Assistant
|
The |
Source code in dashscope/legacy_1x/assistants/assistants.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
retrieve
classmethod
¶
retrieve(
assistant_id: str,
*,
workspace: str = None,
api_key: str = None,
**kwargs
) -> Assistant
Get the Assistant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
assistant_id
|
str
|
The assistant id. |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
api_key
|
str
|
The api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Assistant |
Assistant
|
The |
Source code in dashscope/legacy_1x/assistants/assistants.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
get
classmethod
¶
get(
assistant_id: str,
*,
workspace: str = None,
api_key: str = None,
**kwargs
) -> Assistant
Get the Assistant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
assistant_id
|
str
|
The assistant id. |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
api_key
|
str
|
The api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Assistant |
Assistant
|
The |
Source code in dashscope/legacy_1x/assistants/assistants.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
list
classmethod
¶
list(
*,
limit: int = None,
order: str = None,
after: str = None,
before: str = None,
workspace: str = None,
api_key: str = None,
**kwargs
) -> AssistantList
List assistants
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
How many assistant to retrieve. Defaults to None. |
None
|
order
|
str
|
Sort order by created_at. Defaults to None. |
None
|
after
|
str
|
Assistant id after. Defaults to None. |
None
|
before
|
str
|
Assistant id before. Defaults to None. |
None
|
workspace
|
str
|
The DashScope workspace id. Defaults to None. |
None
|
api_key
|
str
|
Your DashScope api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
AssistantList |
AssistantList
|
The list of assistants. |
Source code in dashscope/legacy_1x/assistants/assistants.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
update
classmethod
¶
update(
assistant_id: str,
*,
model: str = None,
name: str = None,
description: str = None,
instructions: str = None,
tools: Optional[List[Dict]] = None,
file_ids: Optional[List[str]] = [],
metadata: Dict = None,
workspace: str = None,
api_key: str = None,
top_p: Optional[float] = None,
top_k: Optional[int] = None,
temperature: Optional[float] = None,
max_tokens: Optional[int] = None,
**kwargs
) -> Assistant
Update an exist assistants
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
assistant_id
|
str
|
The target assistant id. |
required |
model
|
str
|
The model to use. |
None
|
name
|
str
|
The assistant name. Defaults to None. |
None
|
description
|
str
|
The assistant description . Defaults to None. |
None
|
instructions
|
str
|
The system instructions this assistant uses.. Defaults to None. # noqa: E501 # pylint: disable=line-too-long |
None
|
tools
|
Optional[str]
|
List of tools to use.. Defaults to []. # noqa: E501 |
None
|
file_ids
|
Optional[str]
|
The files to use in assistants.. Defaults to []. # noqa: E501 # pylint: disable=line-too-long |
[]
|
metadata
|
Dict
|
Custom key-value pairs associate with assistant. Defaults to None. |
None
|
workspace
|
str
|
The DashScope workspace id. |
None
|
api_key
|
str
|
The DashScope workspace id. Defaults to None. |
None
|
top_p
|
float
|
top_p parameter for model. Defaults to None. |
None
|
top_k
|
int
|
top_p parameter for model. Defaults to None. |
None
|
temperature
|
float
|
temperature parameter for model. Defaults to None. |
None
|
max_tokens
|
int
|
max_tokens parameter for model. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Assistant |
Assistant
|
The updated assistant. |
Source code in dashscope/legacy_1x/assistants/assistants.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | |
delete
classmethod
¶
delete(
assistant_id: str,
*,
workspace: str = None,
api_key: str = None,
**kwargs
) -> DeleteResponse
Delete uploaded file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
assistant_id
|
str
|
The assistant id want to delete. |
required |
workspace
|
str
|
The DashScope workspace id. |
None
|
api_key
|
str
|
The api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
AssistantsDeleteResponse |
DeleteResponse
|
Delete result. |
Source code in dashscope/legacy_1x/assistants/assistants.py
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |
Assistant
dataclass
¶
Assistant(**kwargs)
Bases: BaseObjectMixin
Source code in dashscope/legacy_1x/assistants/assistant_types.py
135 136 137 | |
status_code
instance-attribute
¶
status_code: int
The call response status_code, 200 indicate create success.
created_at
instance-attribute
¶
created_at: int
The Unix timestamp (in seconds) for when the assistant was created.
tools
instance-attribute
¶
tools: List[Tool] = convert_tools_dict_to_objects(
kwargs.pop("tools", [])
)
Threads
¶
Bases: CreateMixin, DeleteMixin, GetStatusMixin, UpdateMixin
.. deprecated:: The Threads API is deprecated and will be removed in a future release. Please migrate to the Responses API. See https://help.aliyun.com/zh/model-studio/ synchronous-call-api-reference for migration details.
call
classmethod
¶
call(
*,
messages: List[Dict] = None,
metadata: Dict = None,
workspace: str = None,
api_key: str = None,
**kwargs
) -> Thread
Create a thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
List[Dict]
|
List of messages to start thread. Defaults to None. |
None
|
metadata
|
Dict
|
The key-value information associate with thread. Defaults to None. |
None
|
workspace
|
str
|
The DashScope workspace id. Defaults to None. |
None
|
api_key
|
str
|
Your DashScope api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Thread |
Thread
|
The thread object. |
Source code in dashscope/legacy_1x/threads/threads.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
create
classmethod
¶
create(
*,
messages: List[Dict] = None,
metadata: Dict = None,
workspace: str = None,
api_key: str = None,
**kwargs
) -> Thread
Create a thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
List[Dict]
|
List of messages to start thread. Defaults to None. |
None
|
metadata
|
Dict
|
The key-value information associate with thread. Defaults to None. |
None
|
workspace
|
str
|
The DashScope workspace id. Defaults to None. |
None
|
api_key
|
str
|
Your DashScope api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Thread |
Thread
|
The thread object. |
Source code in dashscope/legacy_1x/threads/threads.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
get
classmethod
¶
get(
thread_id: str,
*,
workspace: str = None,
api_key: str = None,
**kwargs
) -> Thread
Retrieve the thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The target thread. |
required |
workspace
|
str
|
The DashScope workspace id. Defaults to None. |
None
|
api_key
|
str
|
Your DashScope api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Thread |
Thread
|
The |
Source code in dashscope/legacy_1x/threads/threads.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
retrieve
classmethod
¶
retrieve(
thread_id: str,
*,
workspace: str = None,
api_key: str = None,
**kwargs
) -> Thread
Retrieve the thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The target thread. |
required |
workspace
|
str
|
The DashScope workspace id. Defaults to None. |
None
|
api_key
|
str
|
Your DashScope api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Thread |
Thread
|
The |
Source code in dashscope/legacy_1x/threads/threads.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
update
classmethod
¶
update(
thread_id: str,
*,
metadata: Dict = None,
workspace: str = None,
api_key: str = None,
**kwargs
) -> Thread
Update thread information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The thread id. |
required |
metadata
|
Dict
|
The thread key-value information. Defaults to None. |
None
|
workspace
|
str
|
The DashScope workspace id. Defaults to None. |
None
|
api_key
|
str
|
Your DashScope api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Thread |
Thread
|
The |
Source code in dashscope/legacy_1x/threads/threads.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
delete
classmethod
¶
delete(
thread_id,
*,
workspace: str = None,
api_key: str = None,
**kwargs
) -> DeleteResponse
Delete thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The thread id to delete. |
required |
workspace
|
str
|
The DashScope workspace id. Defaults to None. |
None
|
api_key
|
str
|
Your DashScope api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
AssistantsDeleteResponse |
DeleteResponse
|
The deleted information. |
Source code in dashscope/legacy_1x/threads/threads.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
create_and_run
classmethod
¶
create_and_run(
*,
assistant_id: str,
thread: Optional[Dict] = None,
model: Optional[str] = None,
instructions: Optional[str] = None,
additional_instructions: Optional[str] = None,
tools: Optional[List[Dict]] = None,
metadata: Optional[Dict] = None,
workspace: str = None,
api_key: str = None,
**kwargs
) -> Run
Source code in dashscope/legacy_1x/threads/threads.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
Thread
dataclass
¶
Thread(**kwargs)
Bases: BaseObjectMixin
Source code in dashscope/legacy_1x/threads/thread_types.py
229 230 | |
ThreadMessage
dataclass
¶
ThreadMessage(**kwargs)
Bases: BaseObjectMixin
Source code in dashscope/legacy_1x/threads/thread_types.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
Messages
¶
Bases: CreateMixin, ListObjectMixin, GetStatusMixin, UpdateMixin
.. deprecated:: The Messages API (Assistants API) is deprecated and will be removed in a future release. Please migrate to the Responses API. See https://help.aliyun.com/zh/model-studio/ synchronous-call-api-reference for migration details.
call
classmethod
¶
call(
thread_id: str,
*,
content: str,
role: str = "user",
file_ids: List[str] = [],
metadata: Optional[object] = None,
workspace: str = None,
api_key: str = None,
**kwargs
) -> ThreadMessage
Create message of thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The thread id. |
required |
content
|
str
|
The message content. |
required |
role
|
str
|
The message role. Defaults to 'user'. |
'user'
|
file_ids
|
List[str]
|
The file_ids include in message. Defaults to []. |
[]
|
metadata
|
Optional[object]
|
The custom key/value pairs. Defaults to None. |
None
|
workspace
|
str
|
The DashScope workspace id. Defaults to None. |
None
|
api_key
|
str
|
The DashScope api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ThreadMessage |
ThreadMessage
|
The |
Source code in dashscope/legacy_1x/threads/messages/messages.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
create
classmethod
¶
create(
thread_id: str,
*,
content: str,
role: str = "user",
file_ids: List[str] = [],
metadata: Optional[object] = None,
workspace: str = None,
api_key: str = None,
**kwargs
) -> ThreadMessage
Create message of thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The thread id. |
required |
content
|
str
|
The message content. |
required |
role
|
str
|
The message role. Defaults to 'user'. |
'user'
|
file_ids
|
List[str]
|
The file_ids include in message. Defaults to []. |
[]
|
metadata
|
Optional[object]
|
The custom key/value pairs. Defaults to None. |
None
|
workspace
|
str
|
The DashScope workspace id. Defaults to None. |
None
|
api_key
|
str
|
The DashScope api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ThreadMessage |
ThreadMessage
|
The |
Source code in dashscope/legacy_1x/threads/messages/messages.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
retrieve
classmethod
¶
retrieve(
message_id: str,
*,
thread_id: str,
workspace: str = None,
api_key: str = None,
**kwargs
) -> ThreadMessage
Get the ThreadMessage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The thread id. |
required |
message_id
|
str
|
The message id. |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
api_key
|
str
|
The api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ThreadMessage |
ThreadMessage
|
The |
Source code in dashscope/legacy_1x/threads/messages/messages.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
get
classmethod
¶
get(
message_id: str,
*,
thread_id: str,
workspace: str = None,
api_key: str = None,
**kwargs
) -> ThreadMessage
Get the ThreadMessage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The thread id. |
required |
message_id
|
str
|
The message id. |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
api_key
|
str
|
The api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ThreadMessage |
ThreadMessage
|
The |
Source code in dashscope/legacy_1x/threads/messages/messages.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
list
classmethod
¶
list(
thread_id: str,
*,
limit: int = None,
order: str = None,
after: str = None,
before: str = None,
workspace: str = None,
api_key: str = None,
**kwargs
) -> ThreadMessageList
List message of the thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The thread id. |
required |
limit
|
int
|
How many assistant to retrieve. Defaults to None. |
None
|
order
|
str
|
Sort order by created_at. Defaults to None. |
None
|
after
|
str
|
Assistant id after. Defaults to None. |
None
|
before
|
str
|
Assistant id before. Defaults to None. |
None
|
workspace
|
str
|
The DashScope workspace id. Defaults to None. |
None
|
api_key
|
str
|
Your DashScope api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ThreadMessageList |
ThreadMessageList
|
The |
Source code in dashscope/legacy_1x/threads/messages/messages.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
update
classmethod
¶
update(
message_id: str,
*,
thread_id: str,
metadata: Dict = None,
workspace: str = None,
api_key: str = None,
**kwargs
) -> ThreadMessage
Update an message of the thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The thread id. |
required |
message_id
|
str
|
The message id. |
required |
metadata
|
Optional[object]
|
The custom key/value pairs. Defaults to None. |
None
|
workspace
|
str
|
The DashScope workspace id. Defaults to None. |
None
|
api_key
|
str
|
The DashScope api key. Defaults to None. |
None
|
**kwargs
|
Any
|
content (str): The message content. role (str, optional): The message role. Defaults to 'user'. file_ids (List[str], optional): The file_ids include in message. Defaults to []. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
ThreadMessage |
ThreadMessage
|
The |
Source code in dashscope/legacy_1x/threads/messages/messages.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
Runs
¶
Bases: CreateMixin, CancelMixin, ListObjectMixin, GetStatusMixin, UpdateMixin
.. deprecated:: The Runs API (Assistants API) is deprecated and will be removed in a future release. Please migrate to the Responses API. See https://help.aliyun.com/zh/model-studio/ synchronous-call-api-reference for migration details.
create_thread_and_run
classmethod
¶
create_thread_and_run(
*,
assistant_id: str,
thread: Optional[Dict] = None,
model: Optional[str] = None,
instructions: Optional[str] = None,
additional_instructions: Optional[str] = None,
tools: Optional[List[Dict]] = None,
stream: Optional[bool] = False,
metadata: Optional[Dict] = None,
workspace: str = None,
extra_body: Optional[Dict] = None,
api_key: str = None,
**kwargs
) -> Run
Create a thread and run it with an assistant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
assistant_id
|
str
|
The assistant id to run. |
required |
thread
|
Optional[Dict]
|
The thread to create. |
None
|
model
|
Optional[str]
|
The model to use. |
None
|
instructions
|
Optional[str]
|
The instructions. |
None
|
additional_instructions
|
Optional[str]
|
Additional instructions. |
None
|
tools
|
Optional[List[Dict]]
|
The tools to use. |
None
|
stream
|
Optional[bool]
|
Whether to stream. Defaults to False. |
False
|
metadata
|
Optional[Dict]
|
The metadata. |
None
|
workspace
|
str
|
The workspace id. |
None
|
extra_body
|
Optional[Dict]
|
Extra body parameters. |
None
|
api_key
|
str
|
The api key. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Run |
Run
|
The run object. |
Source code in dashscope/legacy_1x/threads/runs/runs.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
create
classmethod
¶
create(
thread_id: str,
*,
assistant_id: str,
model: Optional[str] = None,
instructions: Optional[str] = None,
additional_instructions: Optional[str] = None,
tools: Optional[List[Dict]] = None,
metadata: Optional[Dict] = None,
stream: Optional[bool] = False,
workspace: str = None,
extra_body: Optional[Dict] = None,
api_key: str = None,
top_p: Optional[float] = None,
top_k: Optional[int] = None,
temperature: Optional[float] = None,
max_tokens: Optional[int] = None,
**kwargs
) -> Run
Create a run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The thread to run. |
required |
assistant_id
|
str
|
The assistant id to run. |
required |
model
|
str
|
The model to use. |
None
|
instructions
|
str
|
The system instructions this assistant uses. Defaults to None. |
None
|
additional_instructions
|
Optional[str]
|
Appends additional instructions at the end of the instructions for the run. This is useful for modifying the behavior on a per-run basis without overriding other instructions.. Defaults to None. |
None
|
tools
|
Optional[str]
|
List of tools to use.. Defaults to []. # noqa: E501 |
None
|
metadata
|
Dict
|
Custom key-value pairs associate with run. Defaults to None. |
None
|
workspace
|
str
|
The DashScope workspace id. |
None
|
api_key
|
str
|
The DashScope workspace id. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
InputRequired
|
thread and assistant is required. |
Returns:
| Name | Type | Description |
|---|---|---|
Run |
Run
|
The |
Source code in dashscope/legacy_1x/threads/runs/runs.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
convert_stream_object
classmethod
¶
convert_stream_object(event, item)
Source code in dashscope/legacy_1x/threads/runs/runs.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
call
classmethod
¶
call(
thread_id: str,
*,
assistant_id: str,
model: Optional[str] = None,
instructions: Optional[str] = None,
additional_instructions: Optional[str] = None,
tools: Optional[List[Dict]] = None,
stream: Optional[bool] = False,
metadata: Optional[Dict] = None,
workspace: str = None,
extra_body: Optional[Dict] = None,
api_key: str = None,
top_p: Optional[float] = None,
top_k: Optional[int] = None,
temperature: Optional[float] = None,
max_tokens: Optional[int] = None,
**kwargs
) -> Run
Create a run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The thread to run. |
required |
assistant_id
|
str
|
The assistant id to run. |
required |
model
|
str
|
The model to use. |
None
|
instructions
|
str
|
The system instructions this assistant uses. Defaults to None. |
None
|
additional_instructions
|
Optional[str]
|
Appends additional instructions at the end of the instructions for the run. This is useful for modifying the behavior on a per-run basis without overriding other instructions.. Defaults to None. |
None
|
tools
|
Optional[str]
|
List of tools to use.. Defaults to []. # noqa: E501 |
None
|
metadata
|
Dict
|
Custom key-value pairs associate with run. Defaults to None. |
None
|
workspace
|
str
|
The DashScope workspace id. |
None
|
api_key
|
str
|
The DashScope workspace id. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
InputRequired
|
thread and assistant is required. |
Returns:
| Name | Type | Description |
|---|---|---|
Run |
Run
|
The |
Source code in dashscope/legacy_1x/threads/runs/runs.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
list
classmethod
¶
list(
thread_id: str,
*,
limit: int = None,
order: str = None,
after: str = None,
before: str = None,
workspace: str = None,
api_key: str = None,
**kwargs
) -> RunList
List Run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The thread id. |
required |
limit
|
int
|
How many assistant to retrieve. Defaults to None. |
None
|
order
|
str
|
Sort order by created_at. Defaults to None. |
None
|
after
|
str
|
Assistant id after. Defaults to None. |
None
|
before
|
str
|
Assistant id before. Defaults to None. |
None
|
workspace
|
str
|
The DashScope workspace id. Defaults to None. |
None
|
api_key
|
str
|
Your DashScope api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
RunList |
RunList
|
The list of runs. |
Source code in dashscope/legacy_1x/threads/runs/runs.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
retrieve
classmethod
¶
retrieve(
run_id: str,
*,
thread_id: str,
workspace: str = None,
api_key: str = None,
**kwargs
) -> Run
Retrieve the Run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The thread id. |
required |
run_id
|
str
|
The run id. |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
api_key
|
str
|
The api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Run |
Run
|
The |
Source code in dashscope/legacy_1x/threads/runs/runs.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
get
classmethod
¶
get(
run_id: str,
*,
thread_id: str,
workspace: str = None,
api_key: str = None,
**kwargs
) -> Run
Retrieve the Run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The thread id. |
required |
run_id
|
str
|
The run id. |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
api_key
|
str
|
The api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Run |
Run
|
The |
Source code in dashscope/legacy_1x/threads/runs/runs.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | |
submit_tool_outputs
classmethod
¶
submit_tool_outputs(
run_id: str,
*,
thread_id: str,
tool_outputs: List[Dict],
stream: Optional[bool] = False,
workspace: str = None,
extra_body: Optional[Dict] = None,
api_key: str = None,
**kwargs
) -> Run
Submit tool outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The thread id. |
required |
run_id
|
str
|
The run id. |
required |
tool_outputs
|
List[Dict]
|
The tool outputs. |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
api_key
|
str
|
The api key. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
InputRequired
|
The tool output thread id run id are required. |
Returns:
| Name | Type | Description |
|---|---|---|
Run |
Run
|
The 'Run`. |
Source code in dashscope/legacy_1x/threads/runs/runs.py
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | |
wait
classmethod
¶
wait(
run_id: str,
*,
thread_id: str,
timeout_seconds: float = float("inf"),
workspace: str = None,
api_key: str = None,
**kwargs
) -> Run
Wait for run to complete.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The thread id. |
required |
run_id
|
str
|
The run id. |
required |
timeout_seconds
|
int
|
The timeout seconds. Defaults inf. |
float('inf')
|
workspace
|
str
|
The dashscope workspace id. |
None
|
api_key
|
str
|
The api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Run |
Run
|
The run final status. |
Source code in dashscope/legacy_1x/threads/runs/runs.py
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 | |
update
classmethod
¶
update(
run_id: str,
*,
thread_id: str,
metadata: Optional[Dict] = None,
workspace: str = None,
api_key: str = None,
**kwargs
) -> Run
Create a run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The thread of the run id to be updated. |
required |
run_id
|
str
|
The run id to update. |
required |
metadata
|
Dict
|
Custom key-value pairs associate with run. Defaults to None. |
None
|
workspace
|
str
|
The DashScope workspace id. |
None
|
api_key
|
str
|
The DashScope workspace id. Defaults to None. |
None
|
**kwargs
|
Any
|
model (str): The model to use. |
{}
|
Raises:
| Type | Description |
|---|---|
InputRequired
|
thread id and run is required. |
Returns:
| Name | Type | Description |
|---|---|---|
Run |
Run
|
The |
Source code in dashscope/legacy_1x/threads/runs/runs.py
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | |
cancel
classmethod
¶
cancel(
run_id: str,
*,
thread_id: str,
workspace: str = None,
api_key: str = None,
**kwargs
) -> Run
Cancel the Run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The thread id. |
required |
run_id
|
str
|
The run id. |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
api_key
|
str
|
The api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Run |
Run
|
The |
Source code in dashscope/legacy_1x/threads/runs/runs.py
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 | |
Run
dataclass
¶
Run(**kwargs)
Bases: BaseObjectMixin
Source code in dashscope/legacy_1x/threads/thread_types.py
335 336 337 338 339 340 341 342 343 | |
required_action
class-attribute
instance-attribute
¶
required_action: Optional[RequiredAction] = None
status
instance-attribute
¶
status: Literal[
"queued",
"in_progress",
"requires_action",
"cancelling",
"cancelled",
"failed",
"completed",
"expired",
]
tools
instance-attribute
¶
tools: List[Tool] = convert_tools_dict_to_objects(
kwargs.pop("tools", [])
)
Steps
¶
Bases: ListObjectMixin, GetStatusMixin
.. deprecated:: The Steps API (Assistants API) is deprecated and will be removed in a future release. Please migrate to the Responses API. See https://help.aliyun.com/zh/model-studio/ synchronous-call-api-reference for migration details.
list
classmethod
¶
list(
run_id: str,
*,
thread_id: str,
limit: int = None,
order: str = None,
after: str = None,
before: str = None,
workspace: str = None,
api_key: str = None,
**kwargs
) -> RunStepList
List RunStep of Run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The thread id. |
required |
run_id
|
str
|
The run id. |
required |
limit
|
int
|
How many assistant to retrieve. Defaults to None. |
None
|
order
|
str
|
Sort order by created_at. Defaults to None. |
None
|
after
|
str
|
Assistant id after. Defaults to None. |
None
|
before
|
str
|
Assistant id before. Defaults to None. |
None
|
workspace
|
str
|
The DashScope workspace id. Defaults to None. |
None
|
api_key
|
str
|
Your DashScope api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
RunList |
RunStepList
|
The list of runs. |
Source code in dashscope/legacy_1x/threads/runs/steps.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
retrieve
classmethod
¶
retrieve(
step_id: str,
*,
thread_id: str,
run_id: str,
workspace: str = None,
api_key: str = None,
**kwargs
) -> RunStep
Retrieve the RunStep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The thread id. |
required |
run_id
|
str
|
The run id. |
required |
step_id
|
str
|
The step id. |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
api_key
|
str
|
The api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
RunStep |
RunStep
|
The |
Source code in dashscope/legacy_1x/threads/runs/steps.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
get
classmethod
¶
get(
step_id: str,
*,
thread_id: str,
run_id: str,
workspace: str = None,
api_key: str = None,
**kwargs
) -> RunStep
Retrieve the RunStep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The thread id. |
required |
run_id
|
str
|
The run id. |
required |
step_id
|
str
|
The step id. |
required |
workspace
|
str
|
The dashscope workspace id. |
None
|
api_key
|
str
|
The api key. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
RunStep |
RunStep
|
The |
Source code in dashscope/legacy_1x/threads/runs/steps.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
RunStep
dataclass
¶
RunStep(**kwargs)
Bases: BaseObjectMixin
Source code in dashscope/legacy_1x/threads/thread_types.py
668 669 670 671 672 673 674 675 676 677 678 679 680 | |
id
instance-attribute
¶
id: str
The identifier of the run step, which can be referenced in API endpoints.
assistant_id
instance-attribute
¶
assistant_id: str
The ID of the assistant associated with the run step.
cancelled_at
class-attribute
instance-attribute
¶
cancelled_at: Optional[int] = None
The Unix timestamp (in seconds) for when the run step was cancelled.
completed_at
class-attribute
instance-attribute
¶
completed_at: Optional[int] = None
The Unix timestamp (in seconds) for when the run step completed.
created_at
instance-attribute
¶
created_at: int
The Unix timestamp (in seconds) for when the run step was created.
expired_at
class-attribute
instance-attribute
¶
expired_at: Optional[int] = None
The Unix timestamp (in seconds) for when the run step expired.
A step is considered expired if the parent run is expired.
failed_at
class-attribute
instance-attribute
¶
failed_at: Optional[int] = None
The Unix timestamp (in seconds) for when the run step failed.
last_error
class-attribute
instance-attribute
¶
last_error: Optional[LastError] = None
The last error associated with this run step.
Will be null if there are no errors.
metadata
class-attribute
instance-attribute
¶
metadata: Optional[object] = None
Set of 16 key-value pairs that can be attached to an object.
This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be # noqa: E501 a maxium of 512 characters long.
object
instance-attribute
¶
object: Literal['thread.run.step']
The object type, which is always thread.run.step.
run_id
instance-attribute
¶
run_id: str
The ID of the run that # noqa: E501 this run step is a part of.
status
instance-attribute
¶
status: Literal[
"in_progress",
"cancelled",
"failed",
"completed",
"expired",
]
The status of the run step, which can be either in_progress, cancelled,
failed, completed, or expired.
type
instance-attribute
¶
type: Literal['message_creation', 'tool_calls']
The type of run step, which can be either message_creation or tool_calls.
step_details
instance-attribute
¶
step_details: StepDetails = (
convert_step_details_dict_to_objects(
kwargs.pop("step_details", {})
)
)
The details of the run step.
Shared session helpers¶
close_shared_sync_session
¶
close_shared_sync_session() -> None
Close the shared synchronous session and its pooled connections.
Long-running applications may call this to bound the lifetime of the SDK-managed connection pool (e.g. periodically, or after a transport failure). A fresh session is created lazily on the next request.
Source code in dashscope/legacy_1x/api_entities/http_request.py
130 131 132 133 134 135 136 137 138 139 140 141 142 | |
close_shared_aio_session
async
¶
close_shared_aio_session() -> None
Close the shared session for the current event loop.
Source code in dashscope/legacy_1x/api_entities/aio_session.py
102 103 104 105 106 107 108 | |