Qwen-MT API參考
本文介紹通過OpenAI相容介面 或 DashScopeAPI 調用 Qwen-MT 模型的輸入與輸出參數。
相關文檔: 翻譯能力(Qwen-MT)
OpenAI 相容
北京地區
SDK 調用配置的base_url為:https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1
HTTP 要求地址:POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions
新加坡地區
SDK 調用配置的base_url為:https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1
HTTP 要求地址:POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions
美國(維吉尼亞)地區
SDK 調用配置的base_url:https://dashscope-us.aliyuncs.com/compatible-mode/v1
HTTP 要求地址:POST https://dashscope-us.aliyuncs.com/compatible-mode/v1/chat/completions
新加坡地區
SDK 調用配置的base_url為:https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1
HTTP 要求地址:POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions
美國(維吉尼亞)地區
SDK 調用配置的base_url:https://dashscope-us.aliyuncs.com/compatible-mode/v1
HTTP 要求地址:POST https://dashscope-us.aliyuncs.com/compatible-mode/v1/chat/completions
北京地區
SDK 調用配置的base_url為:https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1
HTTP 要求地址:POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions
百鍊為華北2(北京)、新加坡、中國香港地區推出了業務空間專屬網域名稱,能夠為推理請求提供卓越的效能和更高的穩定性,建議遷移至新網域名稱:
-
華北2(北京)地區:從
https://dashscope.aliyuncs.com遷移至https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com -
新加坡地區:從
https://dashscope-intl.aliyuncs.com遷移至https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com -
中國香港地區:從
https://cn-hongkong.dashscope.aliyuncs.com遷移至https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com
其中 {WorkspaceId} 為您的業務空間 ID,可在百鍊控制台的業務空間詳情頁面查看。現有網域名稱仍可正常使用。
您需要已 擷取API Key 並 配置API Key到環境變數 。若通過OpenAI SDK進行調用,需要 安裝SDK 。
請求體 |
基礎使用Python
Node.js
curl各地區的請求地址和API Key不同,以下是新加坡地區的請求地址。
術語幹預Python
Node.js
curl各地區的請求地址和API Key不同,以下是新加坡地區的請求地址。
翻譯記憶Python
Node.js
curl各地區的請求地址和API Key不同,以下是新加坡地區的請求地址。
領域提示Python
Node.js
curl各地區的請求地址和API Key不同,以下是新加坡地區的請求地址。
|
|
model 模型名稱。支援的模型:qwen-mt-plus、qwen-mt-flash、qwen-mt-lite、qwen-mt-turbo。 |
|
|
messages 訊息數組,用於向大模型傳遞上下文。僅支援傳入 User Message。 |
|
|
stream 是否以流式方式輸出回複。 可選值:
說明
當前僅qwen-mt-flash、qwen-mt-lite模型支援以增量形式返回資料,每次返回僅包含新產生的內容。qwen-mt-plus和qwen-mt-turbo模型以非增量形式返回資料,每次返回當前已經產生的整個序列,暫時無法修改。如: I I didn I didn't I didn't laugh I didn't laugh after ... |
|
|
stream_options 流式輸出的配置項,僅在 |
|
|
max_tokens 用於限制模型輸出的最大 Token 數。若產生內容超過此值,響應將被截斷。 預設值與最大值均為模型的最大輸出長度,請參見模型選型。 |
|
|
seed 隨機數種子。用於確保在相同輸入和參數下產生結果可複現。若調用時傳入相同的 取值範圍: |
|
|
temperature 採樣溫度,控制模型產生文本的多樣性。 temperature越高,產生的文本更多樣,反之,產生的文本更確定。 取值範圍: [0, 2) temperature與top_p均可以控制產生文本的多樣性,建議只設定其中一個值。 |
|
|
top_p 核採樣的機率閾值,控制模型產生文本的多樣性。 top_p越高,產生的文本更多樣。反之,產生的文本更確定。 取值範圍:(0,1.0] temperature與top_p均可以控制產生文本的多樣性,建議只設定其中一個值。 |
|
|
top_k 產生過程中採樣候選集的大小。例如,取值為50時,僅將單次產生中得分最高的50個Token組成隨機採樣的候選集。取值越大,產生的隨機性越高;取值越小,產生的確定性越高。取值為None或當top_k大於100時,表示不啟用top_k策略,此時僅有top_p策略生效。 取值需要大於或等於0。 該參數非OpenAI標準參數。通過 Python SDK調用時,請放入 extra_body 對象中,配置方式為: |
|
|
repetition_penalty 模型產生時連續序列中的重複度。提高repetition_penalty時可以降低模型產生的重複度,1.0表示不做懲罰。沒有嚴格的取值範圍,只要大於0即可。 該參數非OpenAI標準參數。通過 Python SDK調用時,請放入 extra_body 對象中,配置方式為: |
|
|
translation_options 需配置的翻譯參數。 該參數非OpenAI標準參數。通過 Python SDK調用時,請放入 extra_body 對象中,配置方式為: |
chat響應對象(非流式輸出) |
|
|
id 本次請求的唯一識別碼。 |
|
|
choices 模型產生內容的數組。 |
|
|
created 本次請求被建立時的時間戳記。 |
|
|
model 本次請求使用的模型。 |
|
|
object 始終為 |
|
|
service_tier 該參數當前固定為 |
|
|
system_fingerprint 該參數當前固定為 |
|
|
usage 本次請求的 Token 消耗資訊。 |
chat響應chunk對象(流式輸出) |
增量輸出
非增量輸出
|
|
id 本次調用的唯一識別碼。每個chunk對象有相同的 id。 |
|
|
choices 模型產生內容的數組。若設定 |
|
|
created 本次請求被建立時的時間戳記。每個chunk有相同的時間戳記。 |
|
|
model 本次請求使用的模型。 |
|
|
object 始終為 |
|
|
service_tier 該參數當前固定為 |
|
|
system_fingerprint 該參數當前固定為 |
|
|
usage 本次請求消耗的Token。只在 |
DashScope
北京地區
HTTP 要求地址:POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation
SDK 調用無需配置 base_url,其預設值為https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1。
新加坡地區
HTTP 要求地址:POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation
SDK調用配置的base_url:
Python代碼
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
Java代碼
-
方式一:
import com.alibaba.dashscope.protocol.Protocol; Generation gen = new Generation(Protocol.HTTP.getValue(), "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1"); -
方式二:
import com.alibaba.dashscope.utils.Constants; Constants.baseHttpApiUrl="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
美國(維吉尼亞)地區
HTTP 要求地址:POST https://dashscope-us.aliyuncs.com/api/v1/services/aigc/text-generation/generation
SDK調用配置的base_url:
Python代碼
dashscope.base_http_api_url = 'https://dashscope-us.aliyuncs.com/api/v1'
Java代碼
-
方式一:
import com.alibaba.dashscope.protocol.Protocol; Generation gen = new Generation(Protocol.HTTP.getValue(), "https://dashscope-us.aliyuncs.com/api/v1"); -
方式二:
import com.alibaba.dashscope.utils.Constants; Constants.baseHttpApiUrl="https://dashscope-us.aliyuncs.com/api/v1";
新加坡地區
HTTP 要求地址:POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation
SDK調用配置的base_url:
Python代碼
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
Java代碼
-
方式一:
import com.alibaba.dashscope.protocol.Protocol; Generation gen = new Generation(Protocol.HTTP.getValue(), "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1"); -
方式二:
import com.alibaba.dashscope.utils.Constants; Constants.baseHttpApiUrl="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
美國(維吉尼亞)地區
HTTP 要求地址:POST https://dashscope-us.aliyuncs.com/api/v1/services/aigc/text-generation/generation
SDK調用配置的base_url:
Python代碼
dashscope.base_http_api_url = 'https://dashscope-us.aliyuncs.com/api/v1'
Java代碼
-
方式一:
import com.alibaba.dashscope.protocol.Protocol; Generation gen = new Generation(Protocol.HTTP.getValue(), "https://dashscope-us.aliyuncs.com/api/v1"); -
方式二:
import com.alibaba.dashscope.utils.Constants; Constants.baseHttpApiUrl="https://dashscope-us.aliyuncs.com/api/v1";
北京地區
HTTP 要求地址:POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation
SDK 調用無需配置 base_url,其預設值為https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1。
您需要已 擷取API Key 並 配置API Key到環境變數 。若通過DashScope SDK進行調用,需要 安裝DashScope SDK 。
請求體 |
基礎使用Python
Java
curl各地區的請求地址和API Key不同,以下是新加坡地區的請求地址。
術語幹預Python
Java
curl各地區的請求地址和API Key不同,以下是新加坡地區的請求地址。
翻譯記憶Python
Java
curl各地區的請求地址和API Key不同,以下是新加坡地區的請求地址。
領域提示Python
Java
curl各地區的請求地址和API Key不同,以下是新加坡地區的請求地址。
|
|
model 模型名稱。支援的模型:qwen-mt-plus、qwen-mt-flash、qwen-mt-lite、qwen-mt-turbo。 |
|
|
messages 訊息數組,用於向大模型傳遞上下文。僅支援傳入 User Message。 |
|
|
max_tokens 用於限制模型輸出的最大 Token 數。若產生內容超過此值,響應將被截斷。 預設值與最大值均為模型的最大輸出長度,請參見模型選型。 Java SDK中為maxTokens。通過HTTP調用時,請將 max_tokens 放入 parameters 對象中。 |
|
|
seed 隨機數種子。用於確保在相同輸入和參數下產生結果可複現。若調用時傳入相同的 取值範圍: 通過HTTP調用時,請將 seed 放入 parameters 對象中。 |
|
|
temperature 採樣溫度,控制模型產生文本的多樣性。 temperature越高,產生的文本更多樣,反之,產生的文本更確定。 取值範圍: [0, 2) temperature與top_p均可以控制產生文本的多樣性,建議只設定其中一個值。 通過HTTP調用時,請將 temperature 放入 parameters 對象中。 |
|
|
top_p 核採樣的機率閾值,控制模型產生文本的多樣性。 top_p越高,產生的文本更多樣。反之,產生的文本更確定。 取值範圍:(0,1.0] temperature與top_p均可以控制產生文本的多樣性,建議只設定其中一個值。 Java SDK中為topP。通過HTTP調用時,請將 top_p 放入 parameters 對象中。 |
|
|
repetition_penalty 模型產生時連續序列中的重複度。提高repetition_penalty時可以降低模型產生的重複度,1.0表示不做懲罰。沒有嚴格的取值範圍,只要大於0即可。 Java SDK中為repetitionPenalty。通過HTTP調用時,請將 repetition_penalty 放入 parameters 對象中。 |
|
|
top_k 產生過程中採樣候選集的大小。例如,取值為50時,僅將單次產生中得分最高的50個Token組成隨機採樣的候選集。取值越大,產生的隨機性越高;取值越小,產生的確定性越高。取值為None或當top_k大於100時,表示不啟用top_k策略,此時僅有top_p策略生效。 取值需要大於或等於0。 Java SDK中為topK。通過HTTP調用時,請將 top_k 放入 parameters 對象中。 |
|
|
stream 是否以流式方式輸出回複。 可選值:
說明
當前僅qwen-mt-flash、qwen-mt-lite模型支援以增量形式返回資料,每次返回僅包含新產生的內容。qwen-mt-plus和qwen-mt-turbo模型以非增量形式返回資料,每次返回當前已經產生的整個序列,暫時無法修改。如: I I didn I didn't I didn't laugh I didn't laugh after ... 該參數僅支援Python SDK。通過Java SDK實現流式輸出請通過 |
|
|
translation_options 需配置的翻譯參數。 Java SDK中為
|
chat響應對象(流式與非流式輸出格式一致) |
|
|
status_code 本次請求的狀態代碼。200 表示請求成功,否則表示請求失敗。 Java SDK不會返回該參數。調用失敗會拋出異常,異常資訊為status_code和message的內容。 |
|
|
request_id 本次調用的唯一識別碼。 Java SDK返回參數為requestId。 |
|
|
code 錯誤碼,調用成功時為空白值。 只有Python SDK返回該參數。 |
|
|
output 調用結果資訊。 |
|
|
usage 本次請求使用的Token資訊。 |
錯誤碼
如果模型調用失敗並返回報錯資訊,請參見錯誤碼進行解決。
.aliyun-docs-content .one-codeblocks pre {
max-height: calc(80vh - 136px) !important;
height: auto;
}
.tab-item {
font-size: 12px !important; / 你可以根據需要調整字型大小 /
padding: 0px 5px !important;
}
.expandable-content {
border-left: none !important;
border-right: none !important;
border-bottom: none !important;
}