跳转到主要内容
Qwen-MT

Qwen-MT 翻译模型

通过 OpenAI 兼容接口调用 Qwen-MT 翻译模型。

POST
/compatible-mode/v1/chat/completions
import os
from openai import OpenAI

client = OpenAI(
  # 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"),
  base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
messages = [
  {
    "role": "user",
    "content": "No me reí después de ver este video"
  }
]
translation_options = {
  "source_lang": "auto",
  "target_lang": "English"
}

completion = client.chat.completions.create(
  model="qwen-mt-plus",
  messages=messages,
  extra_body={
    "translation_options": translation_options
  }
)
print(completion.choices[0].message.content)
{
  "id": "chatcmpl-999a5d8a-f646-4039-968a-167743ae0f22",
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "logprobs": null,
      "message": {
        "content": "I didn't laugh after watching this video.",
        "refusal": null,
        "role": "assistant",
        "annotations": null,
        "audio": null,
        "function_call": null,
        "tool_calls": null
      }
    }
  ],
  "created": 1762346157,
  "model": "qwen-mt-plus",
  "object": "chat.completion",
  "service_tier": null,
  "system_fingerprint": null,
  "usage": {
    "completion_tokens": 9,
    "prompt_tokens": 53,
    "total_tokens": 62,
    "completion_tokens_details": null,
    "prompt_tokens_details": null
  }
}

鉴权

string
header
必填

千问云 API Key。详见获取 API Key

请求体

application/json
enum<string>
必填

模型名称。

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

提供待翻译文本的消息数组。仅支持 user 消息。

object
必填

翻译专用参数。

boolean
默认值false

是否以流式模式返回响应。为 true 时,以服务器发送事件(SSE)数据块形式返回响应。qwen-mt-flashqwen-mt-lite 返回增量输出;qwen-mt-plusqwen-mt-turbo 返回非增量输出(每个数据块包含截至当前已生成的完整内容)。

object

流式输出配置。仅在 streamtrue 时生效。

integer

最大生成 Token 数。若输出超过此限制,则截断。默认值为模型的最大输出长度。

integer

用于结果可复现的随机数种子。范围:[0, 2^31-1]。

number
默认值0.65

控制输出多样性的采样温度。值越高,文本越多样。范围:[0, 2)。temperaturetop_p 只需设置其一。

number
默认值0.8

核采样概率阈值。值越高,文本越多样。范围:(0, 1.0]。temperaturetop_p 只需设置其一。

integer
默认值1

采样候选 Token 集大小。值越大,随机性越强。若为 None 或大于 100,则仅 top_p 生效。必须 >= 0。非标准参数:在 Python SDK 中需通过 extra_body 传入。

number
默认值1

重复序列惩罚系数。值越高,重复越少。1.0 表示不惩罚。必须 > 0。非标准参数:在 Python SDK 中需通过 extra_body 传入。

响应

200-application/json
string

请求唯一标识符。

object[]

模型生成的内容。

integer

请求创建时的 UNIX 时间戳。

string

本次请求使用的模型。

string

固定为 chat.completion

string | null

当前固定为 null

string | null

当前固定为 null

object

Token 用量信息。