The Qwen-Math models from Model Studio offer powerful mathematical reasoning and computational capabilities. They provide detailed, step-by-step solutions that are easy to understand and verify.
This document applies only to the China (Beijing) region. To use the model, you must use an API key from the China (Beijing) region.
Models and pricing
Commercial Models
|
Model name |
Input price |
Output price |
Context window |
Max input |
Max output |
Free quota |
|
(per million tokens) |
(tokens) |
|||||
|
qwen-math-plus |
$0.574 |
$1.721 |
4,096 |
3,072 |
3,072 |
No free quota is available. |
|
qwen-math-turbo |
$0.287 |
$0.861 |
||||
For information about model rate limits, see rate limiting.
Quick start
Obtain an API key and export the API key as an environment variable. If you use the OpenAI SDK or DashScope SDK to make calls, install the SDK.
OpenAI compatible
Python
from openai import OpenAI
import os
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"), # For security, do not hard-code your API key. Use an environment variable or a secrets management service.
# China (Beijing) region. The URL varies depending on the region.
base_url="https://{WorkspaceId}.cn-beijing.maas.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://{WorkspaceId}.cn-beijing.maas.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
# China (Beijing) region. The URL varies depending on the region.
dashscope.base_http_api_url = 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1'
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,
# Set result_format to '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;
import com.alibaba.dashscope.utils.Constants;
public class Main {
public static void callWithMessage()
throws NoApiKeyException, ApiException, InputRequiredException {
// China (Beijing) region. The URL varies depending on the region.
Constants.baseHttpApiUrl="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1";
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://{WorkspaceId}.cn-beijing.maas.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"
}
}'
You can also go to the Model Studio console to try out the model.
Recommendations
-
Use English and LaTeX: The Qwen-Math model is designed for mathematical problems in English. Use LaTeX to represent mathematical symbols and formulas in your input.
-
Control content output: Partial mode provides precise control to ensure that the model's output closely follows the provided prefix. This improves the accuracy and control of the generated results.
-
The
temperatureparameter is set to0by default. Do not adjust this setting. -
Easily extract results: The Qwen-Math model outputs the final result in a
\boxed{}block by default.
Frequently asked questions
|
How to use the Qwen-Math model to solve math problems in images? |
|
The Qwen-Math model does not currently support image recognition.
For information about the input and output parameters of the Qwen-Math model, see the Qwen API Reference. |
|
Where can I find detailed information about error codes? |
|
If the model call fails and returns an error message, see Error codes for resolution. |