通义千问数学模型是专门用于数学解题的语言模型,致力于解决复杂、具有挑战性的数学问题。
商业版 模型名称 版本 上下文长度 最大输入 最大输出 输入成本 输出成本 免费额度 (Token数) (每千Token) qwen-math-plus 稳定版 4,096 3,072 3,072 0.004元 0.012元 各100万Token 有效期:百炼开通后180天内 qwen-math-plus-latest 最新版 qwen-math-plus-2024-09-19 快照版 qwen-math-plus-2024-08-16 qwen-math-turbo 稳定版 0.002元 0.006元 qwen-math-turbo-latest 最新版 qwen-math-turbo-2024-09-19 快照版 开源版 模型名称 上下文长度 最大输入 最大输出 输入成本 输出成本 免费额度 (Token数) (每千Token) qwen2.5-math-72b-instruct 4,096 3,072 3,072 0.004元 0.012元 各100万Token 有效期:百炼开通后180天内 qwen2.5-math-7b-instruct 0.001元 0.002元 qwen2.5-math-1.5b-instruct 限时免费体验 qwen2-math-72b-instruct 0.004元 0.012元 各100万Token 有效期:百炼开通后180天内 qwen2-math-7b-instruct 0.001元 0.002元 qwen2-math-1.5b-instruct 限时免费体验 关于模型的限流条件,请参见限流。 您需要已获取API Key并配置API Key到环境变量。如果通过OpenAI SDK或DashScope SDK进行调用,还需要安装SDK。 通义千问数学模型擅长解决英文数学类问题,在您的输入问题中请使用LaTex表示数学符号或公式,如: 此处以一元一次方程为例,向您展示通过OpenAI或者DashScope的方式体验通义千问数学模型在数学问题上的能力。 OpenAI兼容 DashScope 您可以通过OpenAI SDK或OpenAI兼容的HTTP方式调用通义千问数学模型。 Python curl 如果您希望通义千问数学模型能够严格地以指定前缀为基础来生成文本,可以使用Partial Mode。您输入的messages数组中最后一个message需要为assistant message,并且符合以下格式: 当前支持的数学模型为qwen-math-plus、qwen-math-plus-latest、qwen-math-plus-0919、qwen-math-turbo、qwen-math-turbo-latest、qwen-math-turbo-0919与qwen2.5-math系列模型。 OpenAI兼容 DashScope Python curl 如何利用通义千问数学模型解答图片中的数学问题? 通义千问数学模型暂不支持图片识别功能。 关于通义千问数学模型的输入与输出参数,请参考文本生成-通义千问。 如果模型调用失败并返回报错信息,请参见错误信息进行解决。模型概览
当前等同qwen-math-plus-2024-09-19
始终等同最新快照版
又称qwen-math-plus-0919
又称qwen-math-plus-0816
当前等同qwen-math-turbo-2024-09-19
始终等同最新快照版
又称qwen-math-turbo-0919
qwen-math-plus-latest、qwen-math-plus-0919、qwen-math-turbo、qwen-math-turbo-latest、qwen-math-turbo-0919、qwen2.5-math模型的默认System Message为"Please reason step by step, and put your final answer within \\\\boxed{}."。
示例代码
$x$ 表示数学符号
$4x+5 = 6x+7$ 表示数学公式
示例代码
from openai import OpenAIimport osdef get_response():
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"), # 如果您没有配置环境变量,请在此处用您的API Key进行替换
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1", # 填写DashScope服务的base_url
)
completion = client.chat.completions.create(
model="qwen2-math-72b-instruct",
messages=[
{'role': 'system', 'content': 'You are a helpful assistant.'},
{'role': 'user', 'content': 'Find the value of $x$ that satisfies the equation $4x+5 = 6x+7$.'}]
) print(completion.model_dump_json())if __name__ == '__main__':
get_response()
返回结果
{
"id": "chatcmpl-3ddf85f7-71c1-9fef-9c95-22671565895a",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"logprobs": null,
"message": {
"content": "To solve the equation \\(4x + 5 = 6x + 7\\), we will follow a step-by-step approach to isolate the variable \\(x\\).\n\n1. **Start with the given equation:**\n \\[\n 4x + 5 = 6x + 7\n \\]\n\n2. **Subtract \\(4x\\) from both sides to eliminate \\(x\\) from the left side:**\n \\[\n 4x + 5 - 4x = 6x + 7 - 4x\n \\]\n Simplifying both sides, we get:\n \\[\n 5 = 2x + 7\n \\]\n\n3. **Subtract 7 from both sides to isolate the term with \\(x\\) on the right side:**\n \\[\n 5 - 7 = 2x + 7 - 7\n \\]\n Simplifying both sides, we get:\n \\[\n -2 = 2x\n \\]\n\n4. **Divide both sides by 2 to solve for \\(x\\):**\n \\[\n \\frac{-2}{2} = \\frac{2x}{2}\n \\]\n Simplifying both sides, we get:\n \\[\n -1 = x\n \\]\n\n5. **Write the final answer:**\n \\[\n \\boxed{-1}\n \\]\n\nThus, the value of \\(x\\) that satisfies the equation \\(4x + 5 = 6x + 7\\) is \\(\\boxed{-1}\\).",
"refusal": null,
"role": "assistant",
"function_call": null,
"tool_calls": null
}
}
],
"created": 1724068397,
"model": "qwen2-math-72b-instruct",
"object": "chat.completion",
"service_tier": null,
"system_fingerprint": null,
"usage": {
"completion_tokens": 331,
"prompt_tokens": 42,
"total_tokens": 373
}}
Partial Mode
{
"role": "assistant",
"content": "您指定的前缀",
"partial": true}
示例代码
import osfrom openai import OpenAI
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"), # 如果您没有配置环境变量,请在此处用您的API Key进行替换
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1", # 填写DashScope服务的base_url)
completion = client.chat.completions.create(
model="qwen-math-plus",
messages=[{ "role": "user", "content": "请按照应用题的格式解答问题。“斐波那契数列前10位是多少”"
},
{ "role": "assistant", "content": "解:", "partial": True
}]
)print(completion.choices[0].message.content)
返回结果
斐波那契数列的定义是:数列的前两个数是0和1,之后的每个数是前两个数的和。根据这个定义,我们可以写出数列的前10位。
1. 第1位:0
2. 第2位:1
3. 第3位:0 + 1 = 1
4. 第4位:1 + 1 = 2
5. 第5位:1 + 2 = 3
6. 第6位:2 + 3 = 5
7. 第7位:3 + 5 = 8
8. 第8位:5 + 8 = 13
9. 第9位:8 + 13 = 21
10. 第10位:13 + 21 = 34
因此,斐波那契数列的前10位是:0, 1, 1, 2, 3, 5, 8, 13, 21, 34。
\boxed{0, 1, 1, 2, 3, 5, 8, 13, 21, 34}
常见问题
API参考
错误码