POST
/api/v1/services/aigc/text-generation/generation
复制
import os
import dashscope
dashscope.base_http_api_url = 'https://dashscope.aliyuncs.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
}
}鉴权
string
header
必填
千问 AI 平台 API Key。详见获取 API Key。
请求体
application/jsonenum<string>
必填
模型名称。
可选值:qwen-mt-plus,qwen-mt-turbo,qwen-mt-flash,qwen-mt-lite
示例:qwen-mt-plus
object
必填
object
翻译请求的可选参数。
显示子属性
显示子属性
integer
最大生成 Token 数。若输出超过此限制,则截断。默认值为模型的最大输出长度。
integer
用于结果可复现的随机数种子。范围:[0, 2^31-1]。
number
默认值0.65
控制输出多样性的采样温度。值越高,文本越多样。范围:[0, 2)。temperature 和 top_p 只需设置其一。
number
默认值0.8
核采样概率阈值。值越高,文本越多样。范围:(0, 1.0]。temperature 和 top_p 只需设置其一。
integer
默认值1
采样候选 Token 集大小。值越大,随机性越强。若为 None 或大于 100,则仅 top_p 生效。必须 >= 0。
number
默认值1
重复序列惩罚系数。值越高,重复越少。1.0 表示不惩罚。必须 > 0。
object
翻译专用参数。
显示子属性
显示子属性
object[]
object[]
string
描述文本主题领域或风格的领域提示。必须使用英文。示例:"The sentence is from Ali Cloud IT domain. It mainly involves computer-related software development and usage methods."
示例:The sentence is from Ali Cloud IT domain. It mainly involves computer-related software development and usage methods, including many terms related to computer software and hardware. Pay attention to professional troubleshooting terminologies and sentence patterns when translating. Translate into this IT domain style.
响应
200-application/json
integer
请求状态码。200 表示成功。Java SDK 不返回此参数,失败时抛出异常。
string
请求的唯一标识符。在 Java SDK 中为 requestId。
string
错误码。成功时为空字符串。仅 Python SDK 返回此参数。
string
错误信息。成功时为空字符串。仅 Python SDK 返回此参数。
object