跳转到主要内容
Qwen-MT

Qwen-MT 翻译模型

通过 DashScope 原生 HTTP API 调用 Qwen-MT 翻译模型。

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/json
enum<string>
必填

模型名称。

qwen-mt-plus,qwen-mt-turbo,qwen-mt-flash,qwen-mt-lite
qwen-mt-plus
object
必填

包含待翻译消息的输入数据。

object

翻译请求的可选参数。

响应

200-application/json
integer

请求状态码。200 表示成功。Java SDK 不返回此参数,失败时抛出异常。

string

请求的唯一标识符。在 Java SDK 中为 requestId

string

错误码。成功时为空字符串。仅 Python SDK 返回此参数。

string

错误信息。成功时为空字符串。仅 Python SDK 返回此参数。

object

模型的输出信息。

object

Token 用量信息。