数学能力(Qwen-Math)

阿里云百炼提供的 Qwen-Math 系列模型具备强大的数学推理和计算能力,模型提供详细的解题步骤,便于理解和验证。

说明
  • 推荐使用最新的 Qwen3 通用模型替代 Qwen-Math 模型,后者仍基于 Qwen2.5 模型。

  • 本文档仅适用于中国大陆版(北京地域),需使用中国(北京)地域的API Key

模型与价格

商业版

模型名称

输入价格

输出价格

上下文长度

最大输入

最大输出

免费额度

(注)

(每千Token)

(Token数)

qwen-math-plus

0.004

0.012

4,096

3,072

3,072

100Token

有效期:百炼开通后90天内

qwen-math-turbo

0.002

0.006

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.004

0.012

4,096

3,072

3,072

100Token

有效期:百炼开通后90天内

qwen2.5-math-7b-instruct

0.001

0.002

qwen2.5-math-1.5b-instruct

限时免费

限时免费

关于模型的限流条件,请参见限流

快速开始

您需要已获取API Key配置API Key到环境变量。如果通过OpenAI SDKDashScope SDK进行调用,还需要安装SDK

OpenAI兼容

Python

from 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)

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"
    }
}'
也可以前往百炼控制台体验模型。

使用建议

  1. 使用英文+ LaTeX:Qwen-Math 模型专精于英文数学问题,输入时建议使用 LaTeX 表示数学符号或公式。

  2. 规范内容输出:前缀续写模式(Partial Mode)可提供精确控制能力,确保模型输出的内容紧密衔接提供的前缀,提升生成结果的准确性与可控性。

  3. 模型默认设置temperature=0,无须调节。

  4. 便捷提取结果:Qwen-Math 模型默认将把最终结果输出在\boxed{}区块中。

    image

常见问题

如何利用通义千问数学模型解答图片中的数学问题?

通义千问数学模型暂不支持图片识别功能。

  • 如果图片中是简单的数学问题,可以使用通义千问VLQVQ 模型进行解答。

  • 如果图片中包含复杂的数学问题,可以先使用通义千问VLQVQ 模型提取图片中的文字,再使用通义千问数学模型解答问题。

关于通义千问数学模型的输入与输出参数,请参考通义千问 API 参考

在哪里可以查到错误码的详细信息?

如果模型调用失败并返回报错信息,请参见错误信息进行解决。