阿里雲百鍊提供的 Qwen-Math 系列模型具備強大的數學推理和計算能力,模型提供詳細的解題步驟,便於理解和驗證。
本文檔僅適用於“中國大陸(北京)”地區。如需使用模型,需使用“中國大陸(北京)”地區的API Key。
模型與價格
商業版
模型名稱 | 輸入價格 | 輸出價格 | 上下文長度 | 最大輸入 | 最大輸出 | 免費額度 |
(每百萬Token) | (Token數) | |||||
qwen-math-plus | $0.574 | $1.721 | 4,096 | 3,072 | 3,072 | 無免費額度 |
qwen-math-turbo | $0.287 | $0.861 | ||||
qwen-math-xxx與快照版本的以上參數完全相同。(如qwen-math-xxx-latest和qwen-math-xxx-YYYY-MM-DD)
模型能力:qwen-math-xxx=qwen-math-xxx-latest=qwen-math-xxx-2024-09-19
開源版
模型名稱 | 輸入價格 | 輸出價格 | 上下文長度 | 最大輸入 | 最大輸出 | 免費額度 |
(每百萬Token) | (Token數) | |||||
qwen2.5-math-72b-instruct | $0.574 | $1.721 | 4,096 | 3,072 | 3,072 | 無免費額度 |
qwen2.5-math-7b-instruct | $0.144 | $0.287 | ||||
qwen2.5-math-1.5b-instruct | 限時免費 | 限時免費 | ||||
關於模型的限流條件,請參見限流。
快速開始
您需要已準備工作:擷取與配置 API Key並配置API Key到環境變數(準備下線,併入配置 API Key)。如果通過OpenAI SDK或DashScope SDK進行調用,還需要安裝SDK。
OpenAI相容
Python
from openai import OpenAI
import os
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"), # 請勿在代碼中寫入程式碼憑證,應始終使用環境變數或Key Management Service
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="qwen-math-plus",
messages=[{'role': 'user', 'content': 'Derive a universal solution for the quadratic equation $ Ax^2+Bx+C=0 $'}])
print(completion.choices[0].message.content)curl
curl --location "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions" \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "qwen-math-plus",
"messages": [
{
"role": "user",
"content": "Derive a universal solution for the quadratic equation $ Ax^2+Bx+C=0 $"
}
]
}'DashScope
Python
from http import HTTPStatus
import dashscope
def call_with_messages():
messages = [
{'role': 'user', 'content': 'Derive a universal solution for the quadratic equation $ Ax^2+Bx+C=0 $'}]
response = dashscope.Generation.call(
model='qwen-math-plus',
messages=messages,
# 設定result_format為message格式
result_format='message',
)
if response.status_code == HTTPStatus.OK:
print(response)
else:
print('Request id: %s, Status code: %s, error code: %s, error message: %s' % (
response.request_id, response.status_code,
response.code, response.message
))
if __name__ == '__main__':
call_with_messages()
Java
import java.util.Arrays;
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
public class Main {
public static void callWithMessage()
throws NoApiKeyException, ApiException, InputRequiredException {
Generation gen = new Generation();
Message userMsg = Message.builder().role(Role.USER.getValue()).content("Derive a universal solution for the quadratic equation $ Ax^2+Bx+C=0 $").build();
GenerationParam param =GenerationParam.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.model("qwen-math-plus")
.messages(Arrays.asList(userMsg))
.resultFormat(GenerationParam.ResultFormat.MESSAGE)
.build();
GenerationResult result = gen.call(param);
System.out.println(result);
}
public static void main(String[] args){
try {
callWithMessage();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
}
}
curl
curl --location "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation" \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "qwen-math-plus",
"input":{
"messages":[
{
"role": "user",
"content": "Derive a universal solution for the quadratic equation $ Ax^2+Bx+C=0 $"
}
]
},
"parameters": {
"result_format": "message"
}
}'也可以前往百鍊控制台體驗模型。
使用建議
使用英文+ LaTeX:Qwen-Math 模型專精於英文數學問題,輸入時建議使用 LaTeX 表示數學符號或公式。
規範內容輸出:首碼續寫入模式(Partial Mode)可提供精確控制能力,確保模型輸出的內容緊密銜接提供的首碼,提升產生結果的準確性與可控性。
模型預設設定
temperature=0,無須調節。便捷提取結果:Qwen-Math 模型預設將把最終結果輸出在
\boxed{}區塊中。
常見問題
如何利用通義千問數學模型解答圖片中的數學問題? |
通義千問數學模型暫不支援圖片識別功能。 關於通義千問數學模型的輸入與輸出參數,請參考通義千問 API 參考。 |
在哪裡可以查到錯誤碼的詳細資料? |
如果模型調用失敗並返回報錯資訊,請參見錯誤資訊進行解決。 |