说明 本文档仅适用于“中国内地(北京)”地域。如需使用模型,需使用“中国内地(北京)”地域的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到环境变量。如果通过OpenAI SDK或DashScope SDK进行调用,还需要安装SDK。
OpenAI兼容Pythonfrom openai import OpenAI
import os
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"), # 请勿在代码中硬编码凭证,应始终使用环境变量或密钥管理服务
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)curlcurl --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 $"
}
]
}'DashScopePythonfrom 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()
Javaimport 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());
}
}
}
curlcurl --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{}区块中。
常见问题如何利用通义千问数学模型解答图片中的数学问题?
通义千问数学模型暂不支持图片识别功能。
如果图片中是简单的数学问题,可以使用通义千问VL、QVQ 模型进行解答。
如果图片中包含复杂的数学问题,可以先使用通义千问VL、QVQ 模型提取图片中的文字,再使用通义千问数学模型解答问题。
关于通义千问数学模型的输入与输出参数,请参考通义千问 API 参考。
在哪里可以查到错误码的详细信息?
如果模型调用失败并返回报错信息,请参见错误信息进行解决。