import os
import dashscope
# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
dashscope.base_http_api_url = 'https://ap-southeast-1.maas.qwencloudapi.com/api/v1'
messages = [
{
"role": "user",
"content": "No me reí después de ver este video"
}
]
translation_options = {
"source_lang": "auto",
"target_lang": "English",
}
response = dashscope.Generation.call(
# If you have not configured the environment variable, replace the following line with your API key: api_key="sk-xxx",
api_key=os.getenv('DASHSCOPE_API_KEY'),
model="qwen-mt-plus", # This example uses qwen-mt-plus. You can replace the model name as needed.
messages=messages,
result_format='message',
translation_options=translation_options
)
print(response.output.choices[0].message.content){
"status_code": 200,
"request_id": "9b4ec3b2-6d29-40a6-a08b-7e3c9a51c289",
"code": "",
"message": "",
"output": {
"text": null,
"finish_reason": "stop",
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": "I didn't laugh after watching this video."
}
}
],
"model_name": "qwen-mt-plus"
},
"usage": {
"input_tokens": 53,
"output_tokens": 9,
"total_tokens": 62
}
}Authorizations
QwenCloud API Key. Create one in the QwenCloud console.
Body
application/jsonThe model name.
Input data containing the messages to translate.
Show child attributes
Show child attributes
Optional parameters for the translation request.
Show child attributes
Show child attributes
Maximum number of tokens to generate. If the output exceeds this limit, it is truncated. Defaults to the model's maximum output length.
Random number seed for reproducible results. Range: [0, 2^31-1].
Sampling temperature controlling output diversity. Higher values produce more diverse text. Range: [0, 2). Only set one of temperature or top_p.
Nucleus sampling probability threshold. Higher values produce more diverse text. Range: (0, 1.0]. Only set one of temperature or top_p.
Size of the candidate token set for sampling. Larger values increase randomness. If None or greater than 100, only top_p applies. Must be >= 0.
Penalty for repeated sequences. Higher values reduce repetition. A value of 1.0 means no penalty. Must be > 0.
Translation-specific parameters.
Show child attributes
Show child attributes
The full English name of the source language (e.g., Spanish, Chinese, Japanese). Set to auto for automatic language detection. See Supported languages for the full list.
The full English name of the target language (e.g., English, Chinese, French). See Supported languages for the full list.
Term intervention entries. Each entry maps a source-language term to its desired target-language translation, ensuring consistent terminology.
Translation memory entries. Each entry pairs a source-language sentence with its reference translation, guiding the model with prior translations.
Show child attributes
Show child attributes
The statement in the source language.
The reference translation in the target language.
A domain prompt that describes the subject area or style of the text. Must be in English. Example: "The sentence is from Ali Cloud IT domain. It mainly involves computer-related software development and usage methods."
Response
Request status code. 200 indicates success. The Java SDK does not return this parameter; it throws an exception on failure.
Unique request identifier. In the Java SDK, this is requestId.
Error code. Empty string on success. Only the Python SDK returns this parameter.
Error message. Empty string on success. Only the Python SDK returns this parameter.
Output information from the model.
Show child attributes
Show child attributes
Currently fixed to null.
null during generation, stop when the model stopped naturally, length when the output limit was reached.
Output information from the model.
Name of the model used for this request.