QwQ 模型具有强大的推理能力,模型会先输出思考过程,再输出回答内容。QwQ 模型当前仅支持通过流式输出方式调用。
本文介绍的 QwQ 模型使用方法不适用于 qwq-32b-preview,如果您使用 qwq-32b-preview 模型,请参考文本生成。
概述
相比于 Qwen-Max 等文本生成模型,QwQ 模型会“三思而后言”,在回复前先进行思考:
以上组件仅供您参考,并未真实发送请求。
QwQ 模型介绍
商业版模型
基于 Qwen2.5 模型训练的 QwQ 推理模型,通过强化学习大幅度提升了模型推理能力。模型数学代码等核心指标(AIME 24/25、LiveCodeBench)以及部分通用指标(IFEval、LiveBench等)达到DeepSeek-R1 满血版水平。相较于开源版,商业版具有最新的能力和改进。
模型名称 | 版本 | 上下文长度 | 最大输入 | 最大思维链长度 | 最大回复长度 | 输入成本 | 输出成本 | 免费额度 |
(Token数) | (每千Token) |
模型名称 | 版本 | 上下文长度 | 最大输入 | 最大思维链长度 | 最大回复长度 | 输入成本 | 输出成本 | 免费额度 |
(Token数) | (每千Token) | |||||||
qwq-plus 当前等同 qwq-plus-2025-03-05 | 稳定版 | 131,072 | 98,304 | 32,768 | 8,192 | 0.0016元 Batch调用:0.0008元 | 0.004元 Batch调用:0.002元 | 各100万 Token 有效期:百炼开通后180天内 |
qwq-plus-latest 始终等同最新快照版 | 最新版 | 0.0016元 | 0.004元 | |||||
qwq-plus-2025-03-05 又称qwq-plus-0305 | 快照版 |
开源版模型
基于 Qwen2.5-32B 模型训练的 QwQ 推理模型,于2025年3月6日发布。通过强化学习大幅度提升了模型推理能力。模型数学代码等核心指标(AIME 24/25、LiveCodeBench)以及部分通用指标(IFEval、LiveBench等)达到DeepSeek-R1 满血版水平,各指标均显著超过同样基于 Qwen2.5-32B 的 DeepSeek-R1-Distill-Qwen-32B。
并发限流请参考限流。
快速开始
API 使用前提:已获取API Key并完成配置API Key到环境变量。如果通过SDK调用,需要安装 OpenAI 或 DashScope SDK(DashScope Java SDK 版本需要不低于2.18.2)。
QwQ 模型当前仅支持通过流式输出方式调用。
如果您使用 DashScope 方式调用 QwQ 模型:
incremental_output
参数默认为true
,且不支持设置为false
,仅支持增量流式返回;response_format
参数默认为"message"
。
示例代码
from openai import OpenAI
import os
# 初始化OpenAI客户端
client = OpenAI(
# 如果没有配置环境变量,请用百炼API Key替换:api_key="sk-xxx"
api_key = os.getenv("DASHSCOPE_API_KEY"),
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"
)
reasoning_content = "" # 定义完整思考过程
answer_content = "" # 定义完整回复
is_answering = False # 判断是否结束思考过程并开始回复
# 创建聊天完成请求
completion = client.chat.completions.create(
model="qwq-32b", # 此处以 qwq-32b 为例,可按需更换模型名称
messages=[
{"role": "user", "content": "9.9和9.11谁大"}
],
# QwQ 模型仅支持流式输出方式调用
stream=True,
# 解除以下注释会在最后一个chunk返回Token使用量
# stream_options={
# "include_usage": True
# }
)
print("\n" + "=" * 20 + "思考过程" + "=" * 20 + "\n")
for chunk in completion:
# 如果chunk.choices为空,则打印usage
if not chunk.choices:
print("\nUsage:")
print(chunk.usage)
else:
delta = chunk.choices[0].delta
# 打印思考过程
if hasattr(delta, 'reasoning_content') and delta.reasoning_content != None:
print(delta.reasoning_content, end='', flush=True)
reasoning_content += delta.reasoning_content
else:
# 开始回复
if delta.content != "" and is_answering is False:
print("\n" + "=" * 20 + "完整回复" + "=" * 20 + "\n")
is_answering = True
# 打印回复过程
print(delta.content, end='', flush=True)
answer_content += delta.content
# print("=" * 20 + "完整思考过程" + "=" * 20 + "\n")
# print(reasoning_content)
# print("=" * 20 + "完整回复" + "=" * 20 + "\n")
# print(answer_content)
返回结果
====================思考过程====================
嗯,用户问的是9.9和9.11谁大。首先我要确定这两个数字的具体含义,因为有时候在不同的上下文中可能会有不同的解释。不过通常来说,这里的数字应该是指十进制的小数,也就是数学上的数值比较。
首先,我需要比较这两个小数的大小。9.9和9.11。先看整数部分,都是9,所以整数部分相同。接下来比较小数部分。小数点后的第一位,9.9的小数点后第一位是9,而9.11的小数点后第一位是1。这时候,9比1大,所以9.9的小数部分在第一位就已经更大了,那么整个数自然更大。不过,可能有人会疑惑,因为9.11的小数点后有两位,而9.9只有两位?或者说是不是应该补零来比较?
比如,9.9可以写成9.90,而9.11是9.11,这样比较的话,第二位小数的话,9.90的第二位是0,而9.11的是1,这时候第二位的话,0比1小。不过这时候第一位已经分出胜负了,第一位9比1大,所以不管后面的小数位如何,第一位已经决定了。因此,9.9比9.11大。
不过,也有可能用户在这里的写法有其他意思,比如9.9和9.11可能指的是日期,比如9月9日和9月11日,这样的话比较的话,9.11会更大,因为11日比9日晚。但通常数字比较的话,如果没有特别说明是日期的话,应该按数值来比较。不过用户的问题用的是“谁大”,也就是数值大小,而不是日期先后,所以应该还是数值比较。
再仔细检查一遍,9.9和9.11的数值比较:
9.9 = 9 + 0.9 = 9.900...
9.11 = 9 + 0.11 = 9.110...
比较的时候,先比较整数部分,都是9,相同。然后比较小数点后的第一位,0.9的十分位是9,而0.11的十分位是1,所以9.9的十分位更大,因此整个数更大。后面的百分位虽然9.11有1,但因为十分位已经分出高下了,所以不影响结果。
所以结论应该是9.9比9.11大。不过可能有人会因为小数点后的位数不同而产生混淆,比如认为9.11有两位小数,所以更精确或者数值更大,但其实不是的,数值的大小不取决于小数点后的位数,而是每一位的数值比较。
比如,比如比较1.5和1.499,虽然1.499有三位小数,但数值上还是小于1.5。同理,9.9虽然写成一位小数,但等价于9.90,所以比9.11大。
不过,也有可能用户在这里的写法有其他意思,比如货币单位?比如9.9元和9.11元,这时候同样是9.9元更多。或者其他的上下文,但如果没有特别说明的话,应该按数值比较。
所以最终结论是9.9比9.11大。不过,为了确保正确,再举个例子,比如用分数来比较:
9.9 = 99/10 = 9.9
9.11 = 911/100 = 9.11
将它们通分比较:
99/10 = 990/100
911/100 = 911/100
显然,990 > 911,所以9.9更大。
这样确认下来,答案应该是9.9更大。不过用户可能在输入时有笔误,或者有其他意图,但按照常规数学比较的话,结论应该是正确的。
====================完整回复====================
9.9比9.11大。以下是详细分析:
1. **整数部分比较**:
两个数的整数部分均为 **9**,因此整数部分相等。
2. **小数部分比较**:
- **第一位小数**:
9.9 的小数点后第一位是 **9**,而 9.11 的小数点后第一位是 **1**。
**9 > 1**,因此仅凭这一位即可判断 **9.9 > 9.11**。
- **后续小数位**(补充说明):
即使补零为相同位数(如 9.9 = 9.90),比较第二位小数时:
- 9.90 的第二位是 **0**,而 9.11 的第二位是 **1**。
但此时第一位小数已分出胜负,后续位数不影响最终结果。
3. **分数形式验证**:
- 9.9 = \( \frac{99}{10} = \frac{990}{100} \)
- 9.11 = \( \frac{911}{100} \)
显然,\( 990 > 911 \),因此 **9.9 > 9.11**。
**结论**:
在数值大小比较中,**9.9 大于 9.11**。
示例代码
import OpenAI from "openai";
import process from 'process';
// 初始化 openai 客户端
const openai = new OpenAI({
apiKey: process.env.DASHSCOPE_API_KEY, // 从环境变量读取
baseURL: 'https://dashscope.aliyuncs.com/compatible-mode/v1'
});
let reasoningContent = '';
let answerContent = '';
let isAnswering = false;
async function main() {
try {
const stream = await openai.chat.completions.create({
model: 'qwq-32b',
messages: [{ role: 'user', content: '9.9和9.11谁大' }],
// QwQ 模型仅支持流式输出方式调用
stream: true
});
console.log('\n' + '='.repeat(20) + '思考过程' + '='.repeat(20) + '\n');
for await (const chunk of stream) {
if (!chunk.choices?.length) {
console.log('\nUsage:');
console.log(chunk.usage);
continue;
}
const delta = chunk.choices[0].delta;
// 处理思考过程
if (delta.reasoning_content) {
process.stdout.write(delta.reasoning_content);
reasoningContent += delta.reasoning_content;
}
// 处理正式回复
else if (delta.content) {
if (!isAnswering) {
console.log('\n' + '='.repeat(20) + '完整回复' + '='.repeat(20) + '\n');
isAnswering = true;
}
process.stdout.write(delta.content);
answerContent += delta.content;
}
}
} catch (error) {
console.error('Error:', error);
}
}
main();
返回结果
====================思考过程====================
嗯,用户问的是9.9和9.11谁大。首先我要确定这两个数字的具体含义,因为有时候在不同的上下文中可能会有不同的解释。不过通常来说,这里的数字应该是指十进制的小数,也就是数学上的数值比较。
首先,我需要比较这两个小数的大小。9.9和9.11。先看整数部分,都是9,所以整数部分相同。接下来比较小数部分。小数点后的第一位,9.9的小数点后第一位是9,而9.11的小数点后第一位是1。这时候,9比1大,所以9.9的小数部分在第一位就已经更大了,那么整个数自然更大。不过,可能有人会疑惑,因为9.11的小数点后有两位,而9.9只有两位?或者说是不是应该补零来比较?
比如,9.9可以写成9.90,而9.11是9.11,这样比较的话,第二位小数的话,9.90的第二位是0,而9.11的是1,这时候第二位的话,0比1小。不过这时候第一位已经分出胜负了,第一位9比1大,所以不管后面的小数位如何,第一位已经决定了。因此,9.9比9.11大。
不过,也有可能用户在这里的写法有其他意思,比如9.9和9.11可能指的是日期,比如9月9日和9月11日,这样的话比较的话,9.11会更大,因为11日比9日晚。但通常数字比较的话,如果没有特别说明是日期的话,应该按数值来比较。不过用户的问题用的是“谁大”,也就是数值大小,而不是日期先后,所以应该还是数值比较。
再仔细检查一遍,9.9和9.11的数值比较:
9.9 = 9 + 0.9 = 9.900...
9.11 = 9 + 0.11 = 9.110...
比较的时候,先比较整数部分,都是9,相同。然后比较小数点后的第一位,0.9的十分位是9,而0.11的十分位是1,所以9.9的十分位更大,因此整个数更大。后面的百分位虽然9.11有1,但因为十分位已经分出高下了,所以不影响结果。
所以结论应该是9.9比9.11大。不过可能有人会因为小数点后的位数不同而产生混淆,比如认为9.11有两位小数,所以更精确或者数值更大,但其实不是的,数值的大小不取决于小数点后的位数,而是每一位的数值比较。
比如,比如比较1.5和1.499,虽然1.499有三位小数,但数值上还是小于1.5。同理,9.9虽然写成一位小数,但等价于9.90,所以比9.11大。
不过,也有可能用户在这里的写法有其他意思,比如货币单位?比如9.9元和9.11元,这时候同样是9.9元更多。或者其他的上下文,但如果没有特别说明的话,应该按数值比较。
所以最终结论是9.9比9.11大。不过,为了确保正确,再举个例子,比如用分数来比较:
9.9 = 99/10 = 9.9
9.11 = 911/100 = 9.11
将它们通分比较:
99/10 = 990/100
911/100 = 911/100
显然,990 > 911,所以9.9更大。
这样确认下来,答案应该是9.9更大。不过用户可能在输入时有笔误,或者有其他意图,但按照常规数学比较的话,结论应该是正确的。
====================完整回复====================
9.9比9.11大。以下是详细分析:
1. **整数部分比较**:
两个数的整数部分均为 **9**,因此整数部分相等。
2. **小数部分比较**:
- **第一位小数**:
9.9 的小数点后第一位是 **9**,而 9.11 的小数点后第一位是 **1**。
**9 > 1**,因此仅凭这一位即可判断 **9.9 > 9.11**。
- **后续小数位**(补充说明):
即使补零为相同位数(如 9.9 = 9.90),比较第二位小数时:
- 9.90 的第二位是 **0**,而 9.11 的第二位是 **1**。
但此时第一位小数已分出胜负,后续位数不影响最终结果。
3. **分数形式验证**:
- 9.9 = \( \frac{99}{10} = \frac{990}{100} \)
- 9.11 = \( \frac{911}{100} \)
显然,\( 990 > 911 \),因此 **9.9 > 9.11**。
**结论**:
在数值大小比较中,**9.9 大于 9.11**。
示例代码
curl -X POST https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwq-32b",
"messages": [
{
"role": "user",
"content": "9.9和9.11谁大"
}
],
"stream": true,
"stream_options": {
"include_usage": true
}
}'
返回结果
data: {"choices":[{"delta":{"content":null,"role":"assistant","reasoning_content":""},"index":0,"logprobs":null,"finish_reason":null}],"object":"chat.completion.chunk","usage":null,"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}
data: {"choices":[{"finish_reason":null,"delta":{"content":null,"reasoning_content":"嗯"},"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":","},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"用户"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}
......
data: {"choices":[{"delta":{"content":"需","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}
data: {"choices":[{"delta":{"content":"进一步","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}
data: {"choices":[{"delta":{"content":"确认","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}
data: {"choices":[{"delta":{"content":"规则","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}
data: {"choices":[{"delta":{"content":"。","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}
data: {"choices":[{"finish_reason":"stop","delta":{"content":"","reasoning_content":null},"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}
data: {"choices":[],"object":"chat.completion.chunk","usage":{"prompt_tokens":18,"completion_tokens":1015,"total_tokens":1033},"created":1741185359,"system_fingerprint":null,"model":"qwq-32b","id":"chatcmpl-6c2000e7-b744-9e61-bd03-fc4333d0e5d1"}
data: [DONE]
示例代码
import os
import dashscope
messages = [
{'role': 'user', 'content': '你是谁?'}
]
response = dashscope.Generation.call(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
api_key=os.getenv('DASHSCOPE_API_KEY'),
model="qwq-32b", # 此处以qwq-32b为例,可按需更换模型名称
messages=messages,
# QwQ 模型仅支持流式输出方式调用
stream=True,
)
# 定义完整思考过程
reasoning_content = ""
# 定义完整回复
answer_content = ""
# 判断是否结束思考过程并开始回复
is_answering = False
print("=" * 20 + "思考过程" + "=" * 20)
for chunk in response:
# 如果思考过程与回复皆为空,则忽略
if (chunk.output.choices[0].message.content == "" and
chunk.output.choices[0].message.reasoning_content == ""):
pass
else:
# 如果当前为思考过程
if (chunk.output.choices[0].message.reasoning_content != "" and
chunk.output.choices[0].message.content == ""):
print(chunk.output.choices[0].message.reasoning_content, end="",flush=True)
reasoning_content += chunk.output.choices[0].message.reasoning_content
# 如果当前为回复
elif chunk.output.choices[0].message.content != "":
if not is_answering:
print("\n" + "=" * 20 + "完整回复" + "=" * 20)
is_answering = True
print(chunk.output.choices[0].message.content, end="",flush=True)
answer_content += chunk.output.choices[0].message.content
# 如果您需要打印完整思考过程与完整回复,请将以下代码解除注释后运行
# print("=" * 20 + "完整思考过程" + "=" * 20 + "\n")
# print(f"{reasoning_content}")
# print("=" * 20 + "完整回复" + "=" * 20 + "\n")
# print(f"{answer_content}")
返回结果
====================思考过程====================
嗯,用户问“你是谁?”,我需要先确定他们想知道什么。可能他们刚接触我,想了解我的基本信息。首先,我应该介绍自己的身份,比如我是通义千问,阿里巴巴集团旗下的超大规模语言模型。然后,说明我的功能,比如回答问题、创作文字、编程等。还要提到我的特点,比如多语言支持和持续学习的能力。
接下来,用户可能想知道如何与我互动,所以需要给出使用建议,比如直接提问或给出任务。同时,要确保回答简洁明了,避免技术术语太多,让用户容易理解。另外,可能需要考虑用户的使用场景,比如是个人使用还是商业用途,但问题比较基础,暂时不需要深入。还要检查是否有遗漏的重要信息,比如我的训练数据截止时间或者更新情况,但用户可能不需要这么详细。最后,保持友好和开放的态度,鼓励用户进一步提问,这样能促进更深入的交流。
====================完整回复====================
你好!我是通义千问,阿里巴巴集团旗下的超大规模语言模型。我能够回答问题、创作文字,比如写故事、写公文、写邮件、写剧本、逻辑推理、编程等等,还能表达观点,玩游戏等。我熟练掌握多种语言,包括但不限于中文、英文、德语、法语、西班牙语等。
你可以直接告诉我你需要什么帮助,或者有任何问题想问我,我会尽力为你提供支持!有什么我可以帮到你的吗?
示例代码
// dashscope SDK的版本 >= 2.18.2
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
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 io.reactivex.Flowable;
import java.lang.System;
public class Main {
private static final Logger logger = LoggerFactory.getLogger(Main.class);
private static StringBuilder reasoningContent = new StringBuilder();
private static StringBuilder finalContent = new StringBuilder();
private static boolean isFirstPrint = true;
private static void handleGenerationResult(GenerationResult message) {
String reasoning = message.getOutput().getChoices().get(0).getMessage().getReasoningContent();
String content = message.getOutput().getChoices().get(0).getMessage().getContent();
if (!reasoning.isEmpty()) {
reasoningContent.append(reasoning);
if (isFirstPrint) {
System.out.println("====================思考过程====================");
isFirstPrint = false;
}
System.out.print(reasoning);
}
if (!content.isEmpty()) {
finalContent.append(content);
if (!isFirstPrint) {
System.out.println("\n====================完整回复====================");
isFirstPrint = true;
}
System.out.print(content);
}
}
private static GenerationParam buildGenerationParam(Message userMsg) {
return GenerationParam.builder()
// 若没有配置环境变量,请用百炼API Key将下行替换为:.apiKey("sk-xxx")
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
// 此处以 qwq-32b 为例,可按需更换模型名称
.model("qwq-32b")
.messages(Arrays.asList(userMsg))
.build();
}
public static void streamCallWithMessage(Generation gen, Message userMsg)
throws NoApiKeyException, ApiException, InputRequiredException {
GenerationParam param = buildGenerationParam(userMsg);
Flowable<GenerationResult> result = gen.streamCall(param);
result.blockingForEach(message -> handleGenerationResult(message));
}
public static void main(String[] args) {
try {
Generation gen = new Generation();
Message userMsg = Message.builder().role(Role.USER.getValue()).content("你是谁?").build();
streamCallWithMessage(gen, userMsg);
// 打印最终结果
// if (reasoningContent.length() > 0) {
// System.out.println("\n====================完整回复====================");
// System.out.println(finalContent.toString());
// }
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
logger.error("An exception occurred: {}", e.getMessage());
}
System.exit(0);
}
}
返回结果
====================思考过程====================
好的,用户问“你是谁?”,我需要根据之前的设定来回答。首先,我的角色是通义千问,阿里巴巴集团旗下的超大规模语言模型。要保持口语化,简洁易懂。
用户可能刚接触我,或者想确认我的身份。应该先直接回答我是谁,然后简要说明我的功能和用途,比如回答问题、创作文字、编程等。还要提到支持多语言,这样用户知道我可以处理不同语言的需求。
另外,根据指导方针,要保持拟人性,所以语气要友好,可能用表情符号增加亲切感。同时,可能需要引导用户进一步提问或使用我的功能,比如问他们需要什么帮助。
需要注意不要使用复杂术语,避免冗长。检查是否有遗漏的关键点,比如多语言支持和具体能力。确保回答符合所有要求,包括口语化和简洁。
====================完整回复====================
你好!我是通义千问,阿里巴巴集团旗下的超大规模语言模型。我能够回答问题、创作文字,比如写故事、写公文、写邮件、写剧本、逻辑推理、编程等等,还能表达观点,玩游戏等。我熟练掌握多种语言,包括但不限于中文、英文、德语、法语、西班牙语等。有什么需要我帮忙的吗?
示例代码
curl -X POST "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-DashScope-SSE: enable" \
-d '{
"model": "qwq-32b",
"input":{
"messages":[
{
"role": "user",
"content": "你是谁?"
}
]
}
}'
返回结果
id:1
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"嗯","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":14,"input_tokens":11,"output_tokens":3},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}
id:2
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":15,"input_tokens":11,"output_tokens":4},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}
id:3
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"用户","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":16,"input_tokens":11,"output_tokens":5},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}
id:4
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"问","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":17,"input_tokens":11,"output_tokens":6},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}
id:5
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"“","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":18,"input_tokens":11,"output_tokens":7},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}
......
id:358
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"帮助","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":373,"input_tokens":11,"output_tokens":362},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}
id:359
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":",","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":374,"input_tokens":11,"output_tokens":363},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}
id:360
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"欢迎","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":375,"input_tokens":11,"output_tokens":364},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}
id:361
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"随时","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":376,"input_tokens":11,"output_tokens":365},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}
id:362
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"告诉我","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":377,"input_tokens":11,"output_tokens":366},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}
id:363
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"!","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":378,"input_tokens":11,"output_tokens":367},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}
id:364
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"","role":"assistant"},"finish_reason":"stop"}]},"usage":{"total_tokens":378,"input_tokens":11,"output_tokens":367},"request_id":"25d58c29-c47b-9e8d-a0f1-d6c309ec58b1"}
多轮对话
QwQ 模型 API 默认不会记录您的历史对话信息。多轮对话功能可以让大模型“拥有记忆”,满足如追问、信息采集等需要连续交流的场景。您在使用 QwQ 模型时,会接收到reasoning_content
字段(思考过程)与content
(回复内容),您可以将content
字段通过{'role': 'assistant', 'content':拼接后的流式输出content}
添加到上下文,无需添加reasoning_content
字段。
您可以通过 OpenAI SDK 或 OpenAI 兼容的 HTTP 方式使用多轮对话功能。
示例代码
from openai import OpenAI
import os
# 初始化OpenAI客户端
client = OpenAI(
# 如果没有配置环境变量,请用百炼API Key替换:api_key="sk-xxx"
api_key = os.getenv("DASHSCOPE_API_KEY"),
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"
)
reasoning_content = "" # 定义完整思考过程
answer_content = "" # 定义完整回复
is_answering = False # 判断是否结束思考过程并开始回复
messages = []
conversation_idx = 1
while True:
print("="*20+f"第{conversation_idx}轮对话"+"="*20)
conversation_idx += 1
user_msg = {"role": "user", "content": input("请输入你的消息:")}
messages.append(user_msg)
# 创建聊天完成请求
completion = client.chat.completions.create(
model="qwq-32b", # 此处以 qwq-32b 为例,可按需更换模型名称
messages=messages,
# QwQ 模型仅支持流式输出方式调用
stream=True
)
print("\n" + "=" * 20 + "思考过程" + "=" * 20 + "\n")
for chunk in completion:
# 如果chunk.choices为空,则打印usage
if not chunk.choices:
print("\nUsage:")
print(chunk.usage)
else:
delta = chunk.choices[0].delta
# 打印思考过程
if hasattr(delta, 'reasoning_content') and delta.reasoning_content != None:
print(delta.reasoning_content, end='', flush=True)
reasoning_content += delta.reasoning_content
else:
# 开始回复
if delta.content != "" and is_answering is False:
print("\n" + "=" * 20 + "完整回复" + "=" * 20 + "\n")
is_answering = True
# 打印回复过程
print(delta.content, end='', flush=True)
answer_content += delta.content
messages.append({"role": "assistant", "content": answer_content})
print("\n")
# print("=" * 20 + "完整思考过程" + "=" * 20 + "\n")
# print(reasoning_content)
# print("=" * 20 + "完整回复" + "=" * 20 + "\n")
# print(answer_content)
示例代码
import OpenAI from "openai";
import process from 'process';
import readline from 'readline/promises';
// 初始化 readline 接口
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// 初始化 openai 客户端
const openai = new OpenAI({
apiKey: process.env.DASHSCOPE_API_KEY, // 从环境变量读取
baseURL: 'https://dashscope.aliyuncs.com/compatible-mode/v1'
});
let reasoningContent = '';
let answerContent = '';
let isAnswering = false;
let messages = [];
let conversationIdx = 1;
async function main() {
while (true) {
console.log("=".repeat(20) + `第${conversationIdx}轮对话` + "=".repeat(20));
conversationIdx++;
// 读取用户输入
const userInput = await rl.question("请输入你的消息:");
messages.push({ role: 'user', content: userInput });
// 重置状态
reasoningContent = '';
answerContent = '';
isAnswering = false;
try {
const stream = await openai.chat.completions.create({
model: 'qwq-32b',
messages: messages,
// QwQ 模型仅支持流式输出方式调用
stream: true
});
console.log("\n" + "=".repeat(20) + "思考过程" + "=".repeat(20) + "\n");
for await (const chunk of stream) {
if (!chunk.choices?.length) {
console.log('\nUsage:');
console.log(chunk.usage);
continue;
}
const delta = chunk.choices[0].delta;
// 处理思考过程
if (delta.reasoning_content) {
process.stdout.write(delta.reasoning_content);
reasoningContent += delta.reasoning_content;
}
// 处理正式回复
if (delta.content) {
if (!isAnswering) {
console.log('\n' + "=".repeat(20) + "完整回复" + "=".repeat(20) + "\n");
isAnswering = true;
}
process.stdout.write(delta.content);
answerContent += delta.content;
}
}
// 将完整回复加入消息历史
messages.push({ role: 'assistant', content: answerContent });
console.log("\n");
} catch (error) {
console.error('Error:', error);
}
}
}
// 启动程序
main().catch(console.error);
示例代码
curl -X POST https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwq-32b",
"messages": [
{
"role": "user",
"content": "你好"
},
{
"role": "assistant",
"content": "你好!很高兴见到你,有什么我可以帮忙的吗?"
},
{
"role": "user",
"content": "你是谁?"
}
],
"stream": true
}'
您可以通过 DashScope SDK 或 HTTP 方式使用多轮对话功能。
示例代码
import os
import dashscope
messages = []
conversation_idx = 1
while True:
print("=" * 20 + f"第{conversation_idx}轮对话" + "=" * 20)
conversation_idx += 1
user_msg = {"role": "user", "content": input("请输入你的消息:")}
messages.append(user_msg)
response = dashscope.Generation.call(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx",
api_key=os.getenv('DASHSCOPE_API_KEY'),
model="qwq-32b", # 此处以qwq-32b为例,可按需更换模型名称。
messages=messages,
# QwQ 模型仅支持流式输出方式调用
stream=True,
)
# 定义完整思考过程
reasoning_content = ""
# 定义完整回复
answer_content = ""
# 判断是否结束思考过程并开始回复
is_answering = False
print("=" * 20 + "思考过程" + "=" * 20)
for chunk in response:
# 如果思考过程与回复皆为空,则忽略
if (chunk.output.choices[0].message.content == "" and
chunk.output.choices[0].message.reasoning_content == ""):
pass
else:
# 如果当前为思考过程
if (chunk.output.choices[0].message.reasoning_content != "" and
chunk.output.choices[0].message.content == ""):
print(chunk.output.choices[0].message.reasoning_content, end="",flush=True)
reasoning_content += chunk.output.choices[0].message.reasoning_content
# 如果当前为回复
elif chunk.output.choices[0].message.content != "":
if not is_answering:
print("\n" + "=" * 20 + "完整回复" + "=" * 20)
is_answering = True
print(chunk.output.choices[0].message.content, end="",flush=True)
answer_content += chunk.output.choices[0].message.content
messages.append({"role": "assistant", "content": answer_content})
print("\n")
# 如果您需要打印完整思考过程与完整回复,请将以下代码解除注释后运行
# print("=" * 20 + "完整思考过程" + "=" * 20 + "\n")
# print(f"{reasoning_content}")
# print("=" * 20 + "完整回复" + "=" * 20 + "\n")
# print(f"{answer_content}")
示例代码
// dashscope SDK的版本 >= 2.18.2
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
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 io.reactivex.Flowable;
import java.lang.System;
import java.util.List;
public class Main {
private static final Logger logger = LoggerFactory.getLogger(Main.class);
private static StringBuilder reasoningContent = new StringBuilder();
private static StringBuilder finalContent = new StringBuilder();
private static boolean isFirstPrint = true;
private static void handleGenerationResult(GenerationResult message) {
String reasoning = message.getOutput().getChoices().get(0).getMessage().getReasoningContent();
String content = message.getOutput().getChoices().get(0).getMessage().getContent();
if (!reasoning.isEmpty()) {
reasoningContent.append(reasoning);
if (isFirstPrint) {
System.out.println("====================思考过程====================");
isFirstPrint = false;
}
System.out.print(reasoning);
}
if (!content.isEmpty()) {
finalContent.append(content);
if (!isFirstPrint) {
System.out.println("\n====================完整回复====================");
isFirstPrint = true;
}
System.out.print(content);
}
}
private static GenerationParam buildGenerationParam(List Msg) {
return GenerationParam.builder()
// 若没有配置环境变量,请用百炼API Key将下行替换为:.apiKey("sk-xxx")
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
// 此处以 qwq-32b 为例,可按需更换模型名称
.model("qwq-32b")
.messages(Msg)
.incrementalOutput(true)
.build();
}
public static void streamCallWithMessage(Generation gen, List Msg)
throws NoApiKeyException, ApiException, InputRequiredException {
GenerationParam param = buildGenerationParam(Msg);
Flowable<GenerationResult> result = gen.streamCall(param);
result.blockingForEach(message -> handleGenerationResult(message));
}
public static void main(String[] args) {
try {
Generation gen = new Generation();
Message userMsg1 = Message.builder()
.role(Role.USER.getValue())
.content("你好")
.build();
Message AssistantMsg = Message.builder()
.role(Role.ASSISTANT.getValue())
.content("你好!很高兴见到你,有什么我可以帮忙的吗?")
.build();
Message userMsg2 = Message.builder()
.role(Role.USER.getValue())
.content("你是谁")
.build();
List Msg = Arrays.asList(userMsg1,AssistantMsg,userMsg2);
streamCallWithMessage(gen, Msg);
// 打印最终结果
// if (reasoningContent.length() > 0) {
// System.out.println("\n====================完整回复====================");
// System.out.println(finalContent.toString());
// }
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
logger.error("An exception occurred: {}", e.getMessage());
}
System.exit(0);
}
}
示例代码
curl -X POST "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-DashScope-SSE: enable" \
-d '{
"model": "qwq-32b",
"input":{
"messages":[
{
"role": "user",
"content": "你好"
},
{
"role": "assistant",
"content": "你好!很高兴见到你,有什么我可以帮忙的吗?"
},
{
"role": "user",
"content": "你是谁?"
}
]
}
}'
Function Calling(工具调用)
QwQ 模型在回答需要实时信息的问题时效果不佳。您可以使用 Function Calling 功能,通过引入外部工具,使得 QwQ 模型可以与外部世界进行交互。
QwQ 模型会在思考完成后进行工具调用信息的输出,tool_choice
参数只支持设置为"auto"
(默认值,表示由模型自主选择工具)或"none"
(强制模型不选择工具)。
示例代码
import os
from openai import OpenAI
# 初始化OpenAI客户端,配置阿里云DashScope服务
client = OpenAI(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx",
api_key=os.getenv("DASHSCOPE_API_KEY"), # 从环境变量读取API密钥
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
# 定义可用工具列表
tools = [
# 工具1 获取当前时刻的时间
{
"type": "function",
"function": {
"name": "get_current_time",
"description": "当你想知道现在的时间时非常有用。",
"parameters": {} # 无需参数
}
},
# 工具2 获取指定城市的天气
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "当你想查询指定城市的天气时非常有用。",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "城市或县区,比如北京市、杭州市、余杭区等。"
}
},
"required": ["location"] # 必填参数
}
}
}
]
# 定义问题,请不要设置 System Message
messages = [{"role": "user", "content": input("请输入问题:")}]
completion = client.chat.completions.create(
model="qwq-plus", # 此处以qwq-plus为例,可更换为其它qwq模型
messages=messages,
tools=tools,
parallel_tool_calls=True,
stream=True,
# 解除注释后,可以获取到token消耗信息
# stream_options={
# "include_usage": True
# }
)
reasoning_content = "" # 定义完整思考过程
answer_content = "" # 定义完整回复
tool_info = [] # 存储工具调用信息
is_answering = False # 判断是否结束思考过程并开始回复
print("="*20+"思考过程"+"="*20)
for chunk in completion:
if not chunk.choices:
# 处理用量统计信息
print("\n"+"="*20+"Usage"+"="*20)
print(chunk.usage)
else:
delta = chunk.choices[0].delta
# 处理AI的思考过程(链式推理)
if hasattr(delta, 'reasoning_content') and delta.reasoning_content is not None:
reasoning_content += delta.reasoning_content
print(delta.reasoning_content,end="",flush=True) # 实时输出思考过程
# 处理最终回复内容
else:
if not is_answering: # 首次进入回复阶段时打印标题
is_answering = True
print("\n"+"="*20+"回复内容"+"="*20)
if delta.content is not None:
answer_content += delta.content
print(delta.content,end="",flush=True) # 流式输出回复内容
# 处理工具调用信息(支持并行工具调用)
if delta.tool_calls is not None:
for tool_call in delta.tool_calls:
index = tool_call.index # 工具调用索引,用于并行调用
# 动态扩展工具信息存储列表
while len(tool_info) <= index:
tool_info.append({})
# 收集工具调用ID(用于后续函数调用)
if tool_call.id:
tool_info[index]['id'] = tool_info[index].get('id', '') + tool_call.id
# 收集函数名称(用于后续路由到具体函数)
if tool_call.function and tool_call.function.name:
tool_info[index]['name'] = tool_info[index].get('name', '') + tool_call.function.name
# 收集函数参数(JSON字符串格式,需要后续解析)
if tool_call.function and tool_call.function.arguments:
tool_info[index]['arguments'] = tool_info[index].get('arguments', '') + tool_call.function.arguments
print(f"\n"+"="*19+"工具调用信息"+"="*19)
if not tool_info:
print("没有工具调用")
else:
print(tool_info)
返回结果
输入“四个直辖市的天气”,得到以下返回结果:
请输入问题:四个直辖市的天气
====================思考过程====================
好的,用户问的是四个直辖市的天气。首先,我需要明确中国的四个直辖市分别是哪几个。北京、上海、天津和重庆,对吧?所以用户需要这四个城市的天气情况。
接下来,我需要调用获取天气的函数get_current_weather,每个城市都要单独查询。不过这个函数每次只能查询一个地点,所以得分别调用四次。首先,我应该检查函数的参数是否需要其他信息,但根据描述,参数只需要location,类型是字符串,比如城市名。所以应该没问题。
然后,我需要确保每个城市的名称正确。比如北京应该用“北京市”,上海是“上海市”,天津是“天津市”,重庆的话可能是“重庆市”或者直接“重庆”,但为了统一,可能用全称更好。用户可能希望得到每个城市的当前天气,所以需要依次调用四次函数。
不过,用户可能希望一次性得到所有四个直辖市的天气,但根据工具的限制,可能需要多次调用。这时候可能需要分四次调用,然后把结果汇总。所以在回复里,我应该生成四个tool_call,每个对应一个城市。
另外,还要注意用户是否可能有其他意图,比如是否只需要今天的天气还是未来几天的?不过根据问题描述,函数是获取当前天气,所以应该没问题。不需要额外处理。
最后,确保每个tool_call的格式正确,参数正确,名称正确。然后按顺序生成四个调用,这样用户就能得到所有四个直辖市的天气数据了。
====================回复内容====================
===================工具调用信息===================
[{'id': 'call_0bfdb95b784e46fab218c0', 'name': 'get_current_weather', 'arguments': '{"location": "北京市"}'}, {'id': 'call_9631576c3ccd419f8d8bc7', 'name': 'get_current_weather', 'arguments': '{"location": "上海市"}'}, {'id': 'call_d862b1bfe8374d2d97f508', 'name': 'get_current_weather', 'arguments': '{"location": "天津市"}'}, {'id': 'call_7222cdcc3cd04c839f2427', 'name': 'get_current_weather', 'arguments': '{"location": "重庆市"}'}]
示例代码
import OpenAI from "openai";
import readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';
const openai = new OpenAI({
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: "https://dashscope.aliyuncs.com/compatible-mode/v1"
});
const tools = [
{
type: "function",
function: {
name: "get_current_time",
description: "当你想知道现在的时间时非常有用。",
parameters: {}
}
},
{
type: "function",
function: {
name: "get_current_weather",
description: "当你想查询指定城市的天气时非常有用。",
parameters: {
type: "object",
properties: {
location: {
type: "string",
description: "城市或县区,比如北京市、杭州市、余杭区等。"
}
},
required: ["location"]
}
}
}
];
async function main() {
const rl = readline.createInterface({ input, output });
const question = await rl.question("请输入您的问题:");
rl.close();
const messages = [{ role: "user", content: question }];
let reasoningContent = "";
let answerContent = "";
const toolInfo = [];
let isAnswering = false;
console.log("=".repeat(20) + "思考过程" + "=".repeat(20));
try {
const stream = await openai.chat.completions.create({
model: "qwq-plus",
messages,
tools,
stream: true,
parallel_tool_calls: true
});
for await (const chunk of stream) {
if (!chunk.choices?.length) {
console.log("\n" + "=".repeat(20) + "Usage" + "=".repeat(20));
console.log(chunk.usage);
continue;
}
const delta = chunk.choices[0]?.delta;
if (!delta) continue;
// 处理思考过程
if (delta.reasoning_content) {
reasoningContent += delta.reasoning_content;
process.stdout.write(delta.reasoning_content);
}
// 处理回复内容
else {
if (!isAnswering) {
isAnswering = true;
console.log("\n" + "=".repeat(20) + "回复内容" + "=".repeat(20));
}
if (delta.content) {
answerContent += delta.content;
process.stdout.write(delta.content);
}
// 处理工具调用
if (delta.tool_calls) {
for (const toolCall of delta.tool_calls) {
const index = toolCall.index;
// 确保数组长度足够
while (toolInfo.length <= index) {
toolInfo.push({});
}
// 更新工具ID
if (toolCall.id) {
toolInfo[index].id = (toolInfo[index].id || "") + toolCall.id;
}
// 更新函数名称
if (toolCall.function?.name) {
toolInfo[index].name = (toolInfo[index].name || "") + toolCall.function.name;
}
// 更新参数
if (toolCall.function?.arguments) {
toolInfo[index].arguments = (toolInfo[index].arguments || "") + toolCall.function.arguments;
}
}
}
}
}
console.log("\n" + "=".repeat(19) + "工具调用信息" + "=".repeat(19));
console.log(toolInfo.length ? toolInfo : "没有工具调用");
} catch (error) {
console.error("发生错误:", error);
}
}
main();
返回结果
输入“四个直辖市的天气”,得到以下返回结果:
请输入您的问题:四个直辖市的天气
====================思考过程====================
好的,用户问的是四个直辖市的天气。首先,我需要明确中国的四个直辖市分别是哪几个。北京、上海、天津和重庆,对吧?接下来,我需要为每个城市调用天气查询功能。
但是用户的问题可能需要我分别获取这四个城市的天气情况。每个城市都需要调用一次get_current_weather函数,参数是各自的城市名称。我需要确保参数正确,比如直辖市的全名,比如“北京市”、“上海市”、“天津市”和“重庆市”。
然后,我需要按照顺序依次调用这四个城市的天气接口。每个调用都需要单独的tool_call。用户可能希望得到每个城市的当前天气信息,所以需要确保每个调用都正确无误。可能需要注意每个城市的正确拼写和名称,避免出现错误。例如,重庆有时可能被简称为“重庆市”,所以参数里应该用全称。
现在,我需要生成四个tool_call,每个对应一个直辖市。检查每个参数是否正确,然后按顺序排列。这样用户就能得到四个直辖市的天气数据了。
====================回复内容====================
===================工具调用信息===================
[
{
id: 'call_21dc802e717f491298d1b2',
name: 'get_current_weather',
arguments: '{"location": "北京市"}'
},
{
id: 'call_2cd3be1d2f694c4eafd4e5',
name: 'get_current_weather',
arguments: '{"location": "上海市"}'
},
{
id: 'call_48cf3f78e02940bd9085e4',
name: 'get_current_weather',
arguments: '{"location": "天津市"}'
},
{
id: 'call_e230a2b4c64f4e658d223e',
name: 'get_current_weather',
arguments: '{"location": "重庆市"}'
}
]
示例代码
curl -X POST https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwq-plus",
"messages": [
{
"role": "user",
"content": "杭州天气怎么样"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_current_time",
"description": "当你想知道现在的时间时非常有用。",
"parameters": {}
}
},
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "当你想查询指定城市的天气时非常有用。",
"parameters": {
"type": "object",
"properties": {
"location":{
"type": "string",
"description": "城市或县区,比如北京市、杭州市、余杭区等。"
}
},
"required": ["location"]
}
}
}
],
"stream": true
}'
返回结果
data: {"choices":[{"delta":{"content":null,"reasoning_content":"好的,用户问","role":"assistant"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"的是杭州的天气怎么样"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"。我需要使用"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"get_current_weather这个"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"函数来获取信息"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"。首先,确认函数的"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"参数要求,里面"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"需要location参数,类型是"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"字符串,比如城市"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"或县区。"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"用户提到的是杭州市"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":",所以参数应该"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"填“杭州市”。然后检查"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"是否有其他可能的参数或"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"需要注意的地方,这里没有"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"其他参数。所以"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"正确的调用应该是调"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"用get_current_weather,参数"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"location设为“杭州市"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"”。不需要调用其他"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"函数,因为用户"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"只问了天气。"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"确认没有遗漏必要"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"参数,然后生成"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"对应的tool_call。"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":null,"tool_calls":[{"function":{"name":"get_current_weather","arguments":"{\"location\": \"杭州市"},"index":0,"id":"call_c7fe3e2aa1fc4b67a79995","type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"delta":{"tool_calls":[{"function":{"arguments":"\"}"},"index":0,"id":"","type":"function"}]},"index":0}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: {"choices":[{"finish_reason":"tool_calls","delta":{},"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742287815,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-423eb42c-57d8-90b8-a976-15d30c588792"}
data: [DONE]
示例代码
import os
import dashscope
tools = [
# 工具1 获取当前时刻的时间
{
"type": "function",
"function": {
"name": "get_current_time",
"description": "当你想知道现在的时间时非常有用。",
"parameters": {} # 因为获取当前时间无需输入参数,因此parameters为空字典
}
},
# 工具2 获取指定城市的天气
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "当你想查询指定城市的天气时非常有用。",
"parameters": {
"type": "object",
"properties": {
# 查询天气时需要提供位置,因此参数设置为location
"location": {
"type": "string",
"description": "城市或县区,比如北京市、杭州市、余杭区等。"
}
},
"required": ["location"]
}
}
}
]
# 定义问题
messages = [{"role": "user", "content": input("请输入问题:")}]
completion = dashscope.Generation.call(
model="qwq-plus", # 此处以qwq-plus为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
messages=messages,
tools=tools,
parallel_tool_calls=True,
stream=True
)
reasoning_content = ""
answer_content = ""
tool_info = []
is_answering = False
print("="*20+"思考过程"+"="*20)
for chunk in completion:
if chunk.status_code == 200:
msg = chunk.output.choices[0].message
# 处理思考过程
if 'reasoning_content' in msg and msg.reasoning_content:
reasoning_content += msg.reasoning_content
print(msg.reasoning_content, end="", flush=True)
# 处理回复内容
if 'content' in msg and msg.content:
if not is_answering:
is_answering = True
print("\n"+"="*20+"回复内容"+"="*20)
answer_content += msg.content
print(msg.content, end="", flush=True)
# 处理工具调用
if 'tool_calls' in msg and msg.tool_calls:
for tool_call in msg.tool_calls:
index = tool_call['index']
while len(tool_info) <= index:
tool_info.append({'id': '', 'name': '', 'arguments': ''}) # 初始化所有字段
# 增量更新工具ID
if 'id' in tool_call:
tool_info[index]['id'] += tool_call.get('id', '')
# 增量更新函数信息
if 'function' in tool_call:
func = tool_call['function']
# 增量更新函数名称
if 'name' in func:
tool_info[index]['name'] += func.get('name', '')
# 增量更新参数
if 'arguments' in func:
tool_info[index]['arguments'] += func.get('arguments', '')
print(f"\n"+"="*19+"工具调用信息"+"="*19)
if not tool_info:
print("没有工具调用")
else:
print(tool_info)
返回结果
输入“四个直辖市的天气”,得到以下返回结果:
请输入问题:四个直辖市的天气
====================思考过程====================
好的,用户问的是四个直辖市的天气。首先,我需要确认中国的四个直辖市分别是哪些。北京、上海、天津和重庆,对吧?接下来,用户需要每个城市的天气情况,所以我需要调用天气查询功能。
不过,问题来了,用户没有指定具体的城市名称,只是说四个直辖市。可能需要我明确每个直辖市的名称,然后分别查询。比如,北京、上海、天津、重庆这四个直辖市。我需要确保每个城市都正确无误。
然后,我要检查可用的工具,用户提供的函数是get_current_weather,参数是location。因此,我需要为每个直辖市调用这个函数,传入对应的城市名称作为参数。比如,第一次调用location是北京市,第二次是上海市,第三次是天津市,第四次是重庆市。
不过,可能需要注意,像重庆这样的直辖市,有时候可能需要更具体的区,但用户可能只需要市级的天气。所以直接使用直辖市名称应该没问题。接下来,我需要生成四个独立的函数调用,每个对应一个直辖市。这样用户就能得到四个城市的天气情况了。
最后,确保每个调用的参数正确,并且没有遗漏。这样用户的问题就能得到完整的回答了。
===================工具调用信息===================
[{'id': 'call_2f774ed97b0e4b24ab10ec', 'name': 'get_current_weather', 'arguments': '{"location": "北京市"}'}, {'id': 'call_dc3b05b88baa48c58bc33a', 'name': 'get_current_weather', 'arguments': '{"location": "上海市"}}'}, {'id': 'call_249b2de2f73340cdb46cbc', 'name': 'get_current_weather', 'arguments': '{"location": "天津市"}'}, {'id': 'call_833333634fda49d1b39e87', 'name': 'get_current_weather', 'arguments': '{"location": "重庆市"}}'}]
示例代码
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
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.JsonUtils;
import com.alibaba.dashscope.tools.ToolFunction;
import com.alibaba.dashscope.tools.FunctionDefinition;
import io.reactivex.Flowable;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.lang.System;
import com.github.victools.jsonschema.generator.Option;
import com.github.victools.jsonschema.generator.OptionPreset;
import com.github.victools.jsonschema.generator.SchemaGenerator;
import com.github.victools.jsonschema.generator.SchemaGeneratorConfig;
import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder;
import com.github.victools.jsonschema.generator.SchemaVersion;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class Main {
private static final Logger logger = LoggerFactory.getLogger(Main.class);
private static ObjectNode jsonSchemaWeather;
private static ObjectNode jsonSchemaTime;
static class TimeTool {
public String call() {
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return "当前时间:" + now.format(formatter) + "。";
}
}
static class WeatherTool {
private String location;
public WeatherTool(String location) {
this.location = location;
}
public String call() {
return location + "今天是晴天";
}
}
static {
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(
SchemaVersion.DRAFT_2020_12, OptionPreset.PLAIN_JSON);
SchemaGeneratorConfig config = configBuilder
.with(Option.EXTRA_OPEN_API_FORMAT_VALUES)
.without(Option.FLATTENED_ENUMS_FROM_TOSTRING)
.build();
SchemaGenerator generator = new SchemaGenerator(config);
jsonSchemaWeather = generator.generateSchema(WeatherTool.class);
jsonSchemaTime = generator.generateSchema(TimeTool.class);
}
private static void handleGenerationResult(GenerationResult message) {
System.out.println(JsonUtils.toJson(message));
}
public static void streamCallWithMessage(Generation gen, Message userMsg)
throws NoApiKeyException, ApiException, InputRequiredException {
GenerationParam param = buildGenerationParam(userMsg);
Flowable<GenerationResult> result = gen.streamCall(param);
result.blockingForEach(message -> handleGenerationResult(message));
}
private static GenerationParam buildGenerationParam(Message userMsg) {
FunctionDefinition fdWeather = buildFunctionDefinition(
"get_current_weather", "获取指定地区的天气", jsonSchemaWeather);
FunctionDefinition fdTime = buildFunctionDefinition(
"get_current_time", "获取当前时刻的时间", jsonSchemaTime);
return GenerationParam.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.model("qwq-plus")
.messages(Arrays.asList(userMsg))
.resultFormat(GenerationParam.ResultFormat.MESSAGE)
.incrementalOutput(true)
.tools(Arrays.asList(
ToolFunction.builder().function(fdWeather).build(),
ToolFunction.builder().function(fdTime).build()))
.build();
}
private static FunctionDefinition buildFunctionDefinition(
String name, String description, ObjectNode schema) {
return FunctionDefinition.builder()
.name(name)
.description(description)
.parameters(JsonUtils.parseString(schema.toString()).getAsJsonObject())
.build();
}
public static void main(String[] args) {
try {
Generation gen = new Generation();
Message userMsg = Message.builder()
.role(Role.USER.getValue())
.content("请告诉我杭州的天气")
.build();
streamCallWithMessage(gen, userMsg);
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
logger.error("An exception occurred: {}", e.getMessage());
}
System.exit(0);
}
}
返回结果
{"requestId":"4edb81cd-4647-9d5d-88f9-a4f30bc6d8dd","usage":{"input_tokens":238,"output_tokens":6,"total_tokens":244},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":"","reasoning_content":"好的,用户让我"}}]}}
{"requestId":"4edb81cd-4647-9d5d-88f9-a4f30bc6d8dd","usage":{"input_tokens":238,"output_tokens":12,"total_tokens":250},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":"","reasoning_content":"告诉杭州的天气。我"}}]}}
{"requestId":"4edb81cd-4647-9d5d-88f9-a4f30bc6d8dd","usage":{"input_tokens":238,"output_tokens":16,"total_tokens":254},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":"","reasoning_content":"需要先确定是否有"}}]}}
{"requestId":"4edb81cd-4647-9d5d-88f9-a4f30bc6d8dd","usage":{"input_tokens":238,"output_tokens":22,"total_tokens":260},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":"","reasoning_content":"相关的工具可用。查看提供的"}}]}}
{"requestId":"4edb81cd-4647-9d5d-88f9-a4f30bc6d8dd","usage":{"input_tokens":238,"output_tokens":28,"total_tokens":266},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":"","reasoning_content":"工具,发现有一个get_current"}}]}}
{"requestId":"4edb81cd-4647-9d5d-88f9-a4f30bc6d8dd","usage":{"input_tokens":238,"output_tokens":34,"total_tokens":272},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":"","reasoning_content":"_weather函数,参数是location"}}]}}
{"requestId":"4edb81cd-4647-9d5d-88f9-a4f30bc6d8dd","usage":{"input_tokens":238,"output_tokens":38,"total_tokens":276},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":"","reasoning_content":"。所以应该调"}}]}}
{"requestId":"4edb81cd-4647-9d5d-88f9-a4f30bc6d8dd","usage":{"input_tokens":238,"output_tokens":43,"total_tokens":281},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":"","reasoning_content":"用这个函数,参数"}}]}}
{"requestId":"4edb81cd-4647-9d5d-88f9-a4f30bc6d8dd","usage":{"input_tokens":238,"output_tokens":48,"total_tokens":286},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":"","reasoning_content":"设为杭州。不需要"}}]}}
{"requestId":"4edb81cd-4647-9d5d-88f9-a4f30bc6d8dd","usage":{"input_tokens":238,"output_tokens":52,"total_tokens":290},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":"","reasoning_content":"其他工具,因为"}}]}}
{"requestId":"4edb81cd-4647-9d5d-88f9-a4f30bc6d8dd","usage":{"input_tokens":238,"output_tokens":56,"total_tokens":294},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":"","reasoning_content":"用户只问了"}}]}}
{"requestId":"4edb81cd-4647-9d5d-88f9-a4f30bc6d8dd","usage":{"input_tokens":238,"output_tokens":60,"total_tokens":298},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":"","reasoning_content":"天气。接下来构造"}}]}}
{"requestId":"4edb81cd-4647-9d5d-88f9-a4f30bc6d8dd","usage":{"input_tokens":238,"output_tokens":64,"total_tokens":302},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":"","reasoning_content":"tool_call,把"}}]}}
{"requestId":"4edb81cd-4647-9d5d-88f9-a4f30bc6d8dd","usage":{"input_tokens":238,"output_tokens":68,"total_tokens":306},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":"","reasoning_content":"名称和参数填"}}]}}
{"requestId":"4edb81cd-4647-9d5d-88f9-a4f30bc6d8dd","usage":{"input_tokens":238,"output_tokens":73,"total_tokens":311},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":"","reasoning_content":"进去。确保参数是"}}]}}
{"requestId":"4edb81cd-4647-9d5d-88f9-a4f30bc6d8dd","usage":{"input_tokens":238,"output_tokens":78,"total_tokens":316},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":"","reasoning_content":"JSON对象,location是"}}]}}
{"requestId":"4edb81cd-4647-9d5d-88f9-a4f30bc6d8dd","usage":{"input_tokens":238,"output_tokens":82,"total_tokens":320},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":"","reasoning_content":"字符串。检查无"}}]}}
{"requestId":"4edb81cd-4647-9d5d-88f9-a4f30bc6d8dd","usage":{"input_tokens":238,"output_tokens":88,"total_tokens":326},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":"","reasoning_content":"误后返回。"}}]}}
{"requestId":"4edb81cd-4647-9d5d-88f9-a4f30bc6d8dd","usage":{"input_tokens":238,"output_tokens":106,"total_tokens":344},"output":{"choices":[{"finish_reason":"null","message":{"role":"assistant","content":"","reasoning_content":"","tool_calls":[{"type":"function","id":"call_ecc41296dccc47baa01567","function":{"name":"get_current_weather","arguments":"{\"location\": \"杭州"}}]}}]}}
{"requestId":"4edb81cd-4647-9d5d-88f9-a4f30bc6d8dd","usage":{"input_tokens":238,"output_tokens":108,"total_tokens":346},"output":{"choices":[{"finish_reason":"tool_calls","message":{"role":"assistant","content":"","reasoning_content":"","tool_calls":[{"type":"function","id":"","function":{"arguments":"\"}"}}]}}]}}
示例代码
curl --location "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation" \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--header "X-DashScope-SSE: enable" \
--data '{
"model": "qwq-plus",
"input":{
"messages":[
{
"role": "user",
"content": "杭州天气"
}
]
},
"parameters": {
"result_format": "message",
"tools": [{
"type": "function",
"function": {
"name": "get_current_time",
"description": "当你想知道现在的时间时非常有用。",
"parameters": {}
}
},{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "当你想查询指定城市的天气时非常有用。",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "城市或县区,比如北京市、杭州市、余杭区等。"
}
},
"required": ["location"]
}
}
}]
}
}'
返回结果
id:1
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"好的,用户问","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":228,"input_tokens":222,"output_tokens":6},"request_id":"351adfc9-47cc-9055-83ba-7300c1a4ef56"}
id:2
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"的是杭州的天气,","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":233,"input_tokens":222,"output_tokens":11},"request_id":"351adfc9-47cc-9055-83ba-7300c1a4ef56"}
id:3
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"我需要调用天气查询","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":239,"input_tokens":222,"output_tokens":17},"request_id":"351adfc9-47cc-9055-83ba-7300c1a4ef56"}
......
id:22
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"最后确保格式正确,用","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":338,"input_tokens":222,"output_tokens":116},"request_id":"351adfc9-47cc-9055-83ba-7300c1a4ef56"}
id:23
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"XML标签包裹JSON对象。","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":344,"input_tokens":222,"output_tokens":122},"request_id":"351adfc9-47cc-9055-83ba-7300c1a4ef56"}
id:24
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"这样应该就能正确","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":348,"input_tokens":222,"output_tokens":126},"request_id":"351adfc9-47cc-9055-83ba-7300c1a4ef56"}
id:25
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"获取杭州的天气信息","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":353,"input_tokens":222,"output_tokens":131},"request_id":"351adfc9-47cc-9055-83ba-7300c1a4ef56"}
id:26
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"tool_calls":[{"index":0,"id":"call_758d97beb1224496b77293","type":"function","function":{"name":"get_current_weather","arguments":"{\""}}],"role":"assistant","content":"","reasoning_content":""},"finish_reason":"null"}]},"usage":{"total_tokens":371,"input_tokens":222,"output_tokens":149},"request_id":"351adfc9-47cc-9055-83ba-7300c1a4ef56"}
id:27
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"tool_calls":[{"index":0,"id":"","type":"function","function":{"arguments":"location\": \"杭州市\"}"}}],"role":"assistant","content":"","reasoning_content":""},"finish_reason":"null"}]},"usage":{"total_tokens":377,"input_tokens":222,"output_tokens":155},"request_id":"351adfc9-47cc-9055-83ba-7300c1a4ef56"}
id:28
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"tool_calls":[{"index":0,"id":"","type":"function","function":{}}],"role":"assistant","content":"","reasoning_content":""},"finish_reason":"tool_calls"}]},"usage":{"total_tokens":377,"input_tokens":222,"output_tokens":155},"request_id":"351adfc9-47cc-9055-83ba-7300c1a4ef56"}
在得到 Function Calling 输出的工具信息后,您可以参考运行工具函数与大模型总结工具函数输出,使大模型能够根据工具运行的结果进行回答。
联网搜索
由于训练数据的时效性,QwQ 模型无法准确回答如股票价格、今日资讯等时效性问题。您可以通过设置enable_search
参数为true
以启用联网检索功能,使 QwQ 模型可以基于实时检索数据进行回复。
开启enable_search
后,模型会先判断是否需要使用联网搜索能力来回答您的输入问题:
需要联网搜索
当您输入的问题被模型判断需要使用联网搜索能力,模型会根据联网搜索的结果进行回复。联网搜索功能当前免费,但搜索到的信息会增加 Token 消耗。
不需要联网搜索
QwQ 模型本身已经可以回答如“你是谁”、“一年有多少天”等简单或常识性的问题。此时模型不会去联网搜索,而是直接进行回答。
如果您希望强制开启联网搜索功能,请参见以下代码中的
forced_search
参数。
除了快照版,其余的 QwQ 模型均支持联网搜索。
在设置enable_search
参数为true
后,您可以通过search_options
参数来配置联网搜索策略,包括以下方面:
是否强制开启联网搜索
通过
forced_search
配置,可选值:true
强制开启。
false
(默认值)不强制开启。
返回数据是否包含搜索来源的信息
通过
enable_source
配置,可选值:true
返回数据中包含搜索来源的信息。搜索来源信息通过
search_info
参数返回。false
(默认值)返回数据中不包含搜索来源的信息。
是否开启角标标注功能
通过
enable_citation
配置,在enable_source
为true
时生效。可选值:true
开启角标标注。
角标标注的样式可以通过下方的
citation_format
参数设置。false
(默认值)不开启角标标注。
角标标注的样式
通过
citation_format
配置,在enable_citation
为true
时生效。可选值:"[<number>]"
(默认值)角标形式为
[i]
。"[ref_<number>]"
角标形式为
[ref_i]
。
搜索互联网信息的数量
通过
search_strategy
配置。可选值:"standard"
(默认值)模型会联网搜索5条信息。
"pro"
模型会联网搜索10条信息。
示例代码
import os
import dashscope
messages = [
{'role': 'user', 'content': '哪吒2的票房'}
]
response = dashscope.Generation.call(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
api_key=os.getenv('DASHSCOPE_API_KEY'),
model="qwq-plus", # 此处以qwq-plus为例,可按需更换模型名称
messages=messages,
enable_search = True, # 开启联网搜索的参数
search_options = {
"forced_search": True, # 强制开启联网搜索
"enable_source": True, # 使返回结果包含搜索来源的信息,OpenAI 兼容方式暂不支持返回
"enable_citation": True, # 开启角标标注功能
"citation_format": "[ref_<number>]", # 角标形式为[ref_i]
"search_strategy": "pro" # 模型将搜索10条互联网信息
},
# QwQ 模型仅支持流式输出方式调用
stream=True,
)
# 定义完整思考过程
reasoning_content = ""
# 定义完整回复
answer_content = ""
# 判断是否结束思考过程并开始回复
is_answering = False
# 判断是否为第一个chunk,便于打印搜索信息
is_first_chunk = True
print("=" * 20 + "搜索信息" + "=" * 20)
for chunk in response:
if is_first_chunk:
search_results = chunk.output.search_info["search_results"]
for web in search_results:
print(f"[{web['index']}]: [{web['title']}]({web['url']})")
print("=" * 20 + "思考过程" + "=" * 20)
reasoning_content += chunk.output.choices[0].message.reasoning_content
print(chunk.output.choices[0].message.reasoning_content,end="",flush=True)
is_first_chunk = False
else:
# 如果思考过程与回复皆为空,则忽略
if (chunk.output.choices[0].message.content == "" and
chunk.output.choices[0].message.reasoning_content == ""):
pass
else:
# 如果当前为思考过程
if (chunk.output.choices[0].message.reasoning_content != "" and
chunk.output.choices[0].message.content == ""):
print(chunk.output.choices[0].message.reasoning_content, end="",flush=True)
reasoning_content += chunk.output.choices[0].message.reasoning_content
# 如果当前为回复
elif chunk.output.choices[0].message.content != "":
if not is_answering:
print("\n" + "=" * 20 + "完整回复" + "=" * 20)
is_answering = True
print(chunk.output.choices[0].message.content, end="",flush=True)
answer_content += chunk.output.choices[0].message.content
# 如果您需要打印完整思考过程与完整回复,请将以下代码解除注释后运行
# print("=" * 20 + "完整思考过程" + "=" * 20 + "\n")
# print(f"{reasoning_content}")
# print("=" * 20 + "完整回复" + "=" * 20 + "\n")
# print(f"{answer_content}")
# 如果您需要打印本次请求的 Token 消耗,请将以下代码解除注释后运行
# print("\n"+"="*20+"Token 消耗"+"="*20)
# print(chunk.usage)
返回结果
====================搜索信息====================
[1]: [哪吒2票房超153亿 小吒儿太争气了!-中华网](https://3g.china.com/act/news/10000169/20250324/48120687.html)
[2]: [《哪吒2》全球票房破153亿, 距离超越《泰坦尼克号》还有多远?-倾城一笑红颜吖](https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=effc0af9cee743b2b3485a75eb85dfae!!wm_id=01887e0e8266475b87b8ef1e578e5239)
[3]: [《哪吒2》导演总票房200亿, 他个人能赚多少? 普通人9辈子花不完-光影新天地](https://mparticle.uc.cn/article.html?title_type=1&uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=a9a1a74021c34364972f063ee24ff428!!wm_id=62bcfb22b72b4e86b229d7e92d86200f)
[4]: [《哪吒2》全球票房破153亿, 距离超越《泰坦尼克号》还有多远?-倾城一笑红颜吖](https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=effc0af9cee743b2b3485a75eb85dfae!!wm_id=01887e0e8266475b87b8ef1e578e5239)
[5]: [152.83亿票房神话背后: 《哪吒2》的荣耀与争议-观止之影](https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=9c926b6274f448468fb5b53eaba4297e!!wm_id=1f462f41cd824ce0aac3cafcb410dca6)
[6]: [《哪吒2》密钥再延一个月: 全球票房破152亿元, 白领贡献最多票房-第一财经](https://mparticle.uc.cn/article_org.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_cid=676384453016170496!!wm_id=1709157a815b423aab98ca7338f2971a)
[7]: [《哪吒2》密钥再延一个月:全球票房破152亿元,白领贡献最多票房-一财网](http://m.yicai.com/news/102529223.html)
[8]: [20亿好莱坞大片也不是对手, 《哪吒2》票房逆跌, 重登中国香港日冠-影视原说](https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=b7e62c0d086247d5aa38c2c00caf75e9!!wm_id=3660dc355efa44509f7f22e4240a7845)
[9]: [《哪吒2》全球票房之战: 国产动画的崛起与挑战-汪逸晨说](https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=25f5e73ea4af42f195d2f86e780cdbfb!!wm_id=6acd8b1f575e437c9f9b8c9f84811e12)
[10]: [票房|《哪吒2》登陆英国、日本院线 国内放映延长到五一-财新网](https://www.caixin.com/2025-03-24/102301462.html)
====================思考过程====================
好的,我现在需要回答用户关于《哪吒2》票房的问题。首先,我要查看用户提供的知识库内容,找到相关的票房数据。
根据知识库中的信息,多个来源提到了《哪吒2》的全球票房。例如,ref_1提到票房超过153亿人民币,而ref_2和ref_4也指出突破了153亿,并且是全球第五。ref_10更具体地指出截至3月24日9时,全球累计票房为153.09亿元,其中中国本土票房150.4亿元,海外2.69亿元。此外,ref_4提到距离《泰坦尼克号》还有约11.23亿的差距,而ref_10则说是近10亿元的差距,这里可能需要注意数据更新的时间点不同导致的差异。
用户的问题只是问票房,所以需要整合这些数据,说明当前的总票房,国内和海外的分布,以及可能的后续目标。同时要引用正确的来源。需要确认各个引用的准确性,比如不同来源提到的数字是否有冲突,但看起来主要的数据是153亿左右,并且正在接近《泰坦尼克号》。此外,ref_6和ref_7提到延长上映到4月30日,可能有助于票房进一步增长。
最后,确保回答中正确标注引用来源,比如总票房引用ref_1、ref_2、ref_4、ref_10,差距部分引用ref_4和ref_10。同时注意不要遗漏关键点,如海外票房占比相对较低,主要收入来自国内,以及可能的挑战。
====================完整回复====================
截至2025年3月24日9时,《哪吒2》全球累计票房已达到**153.09亿元人民币**,其中中国内地(含港澳台)票房为**150.4亿元**,海外票房为**2.69亿元**[ref_10]。这一成绩使其位列全球影史票房榜第五名,并成为唯一一部跻身21亿美元俱乐部的非好莱坞电影[ref_2][ref_4]。
目前,《哪吒2》距离超越全球票房第四名的《泰坦尼克号》(当前约为164.32亿元人民币)仍需约**11.23亿元**[ref_4],或接近10亿元的差距(不同数据源统计可能存在细微差异)[ref_10]。考虑到其在海外市场(尤其是香港)的持续表现——例如曾连续近一个月夺得香港日冠,并在英国、日本等地陆续上映[ref_8][ref_10],以及国内密钥延期至4月30日的策略[ref_6][ref_7],仍有进一步冲高票房的空间。
值得注意的是,影片的国内票房高度集中,占比超98%,而海外票房占比不足2%[ref_10],这与好莱坞大片的全球发行策略形成对比。此外,其国内观众群体以25岁及以上白领和三四线城市观众为主,女性观众占比58%[ref_6][ref_7]。
示例代码
// dashscope SDK的版本 >= 2.18.2
import java.util.Arrays;
import com.alibaba.dashscope.aigc.generation.SearchInfo;
import com.alibaba.dashscope.aigc.generation.SearchOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
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 io.reactivex.Flowable;
import java.lang.System;
public class Main {
private static final Logger logger = LoggerFactory.getLogger(Main.class);
private static StringBuilder reasoningContent = new StringBuilder();
private static StringBuilder finalContent = new StringBuilder();
private static boolean isFirstPrint = true;
private static void handleGenerationResult(GenerationResult message) {
String reasoning = message.getOutput().getChoices().get(0).getMessage().getReasoningContent();
String content = message.getOutput().getChoices().get(0).getMessage().getContent();
SearchInfo searchInfo = message.getOutput().getSearchInfo();
if (!reasoning.isEmpty()) {
reasoningContent.append(reasoning);
if (isFirstPrint) {
System.out.println("====================搜索信息====================");
isFirstPrint = false;
System.out.print(searchInfo.getSearchResults());
System.out.println("\n====================思考过程====================");
}
System.out.print(reasoning);
}
if (!content.isEmpty()) {
finalContent.append(content);
if (!isFirstPrint) {
System.out.println("\n====================完整回复====================");
isFirstPrint = true;
}
System.out.print(content);
}
if (message.getOutput().getChoices().get(0).getFinishReason().equals("stop") || message.getOutput().getChoices().get(0).getFinishReason().equals("length")){
System.out.println("\n====================Token 消耗====================");
System.out.println(message.getUsage());
}
}
private static GenerationParam buildGenerationParam(Message userMsg) {
// 定义搜索策略
SearchOptions searchOptions = SearchOptions.builder()
// 使返回结果中包含搜索信息的来源
.enableSource(true)
// 强制开启互联网搜索
.forcedSearch(true)
// 开启角标标注
.enableCitation(true)
// 设置角标标注样式为[ref_i]
.citationFormat("[ref_<number>]")
// 联网搜索10条信息
.searchStrategy("pro")
.build();
return GenerationParam.builder()
// 若没有配置环境变量,请用百炼API Key将下行替换为:.apiKey("sk-xxx")
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
// 此处以 qwq-plus 为例,可按需更换模型名称
.model("qwq-plus")
.messages(Arrays.asList(userMsg))
// 开启联网搜索的参数
.enableSearch(true)
.searchOptions(searchOptions)
.build();
}
public static void streamCallWithMessage(Generation gen, Message userMsg)
throws NoApiKeyException, ApiException, InputRequiredException {
GenerationParam param = buildGenerationParam(userMsg);
Flowable<GenerationResult> result = gen.streamCall(param);
result.blockingForEach(message -> handleGenerationResult(message));
}
public static void main(String[] args) {
try {
Generation gen = new Generation();
Message userMsg = Message.builder().role(Role.USER.getValue()).content("哪吒2的票房?").build();
streamCallWithMessage(gen, userMsg);
// 打印最终结果
// if (reasoningContent.length() > 0) {
// System.out.println("\n====================完整回复====================");
// System.out.println(finalContent.toString());
// }
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
logger.error("An exception occurred: {}", e.getMessage());
}
System.exit(0);
}
}
返回结果
====================搜索信息====================
[SearchInfo.SearchResult(siteName=, icon=, index=1, title=哪吒2海外票房破3亿了, 中国动画的全球崛起-行知探索圈, url=https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=6f339f9b001142ef81f9e5dd04f40777!!wm_id=217a3dfad10e46d095fa9af00282c896), SearchInfo.SearchResult(siteName=, icon=, index=2, title=《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影, url=https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282), SearchInfo.SearchResult(siteName=, icon=, index=3, title=《哪吒2》全球票房破153亿, 距离超越《泰坦尼克号》还有多远?-倾城一笑红颜吖, url=https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=effc0af9cee743b2b3485a75eb85dfae!!wm_id=01887e0e8266475b87b8ef1e578e5239), SearchInfo.SearchResult(siteName=, icon=, index=4, title=《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影, url=https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282), SearchInfo.SearchResult(siteName=, icon=, index=5, title=哪吒2海外票房破3亿了, 中国动画的全球崛起-行知探索圈, url=https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=6f339f9b001142ef81f9e5dd04f40777!!wm_id=217a3dfad10e46d095fa9af00282c896), SearchInfo.SearchResult(siteName=新浪网, icon=https://img.alicdn.com/imgextra/i2/O1CN01mvEkNg1mbgbrppM5C_!!6000000004973-55-tps-32-32.svg, index=6, title=《哪吒2》海外票房破3亿 暂列全球票房榜第5名-新浪财经, url=https://finance.sina.com.cn/tech/roll/2025-03-25/doc-ineqvkuu7132514.shtml), SearchInfo.SearchResult(siteName=, icon=, index=7, title=【#哪吒2海外票房破3亿#】3月24日,据专业平台数据,《哪吒之魔童闹海》海外票-观察者网, url=https://mparticle.uc.cn/article.html?biz_id=1034&uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_cid=677014919905815552!!wm_id=21b429951d2447878286e0640a469ef6), SearchInfo.SearchResult(siteName=第一财经, icon=https://img.alicdn.com/imgextra/i2/O1CN01IBw5aS1M3d9GmYvnx_!!6000000001379-55-tps-32-32.svg, index=8, title=《哪吒2》海外票房破3亿-一财网, url=http://m.yicai.com/news/102532036.html), SearchInfo.SearchResult(siteName=163网易免费邮, icon=https://img.alicdn.com/imgextra/i2/O1CN01rbsKN11MIkDguCxUW_!!6000000001412-55-tps-32-32.svg, index=9, title=《哪吒2》153亿票房遭"冷嘲热讽",我们为什么对国产动画如此苛刻-网易订阅, url=https://m.163.com/dy/article/JREIHES40556B7G8.html), SearchInfo.SearchResult(siteName=, icon=, index=10, title=《哪吒2》抄袭被实锤? 全球票房超153亿, 让太多人眼红-影视原说, url=https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=fd1f933252da43d79c09fc43ea53b972!!wm_id=3660dc355efa44509f7f22e4240a7845)]
====================思考过程====================
好的,我现在需要回答用户关于《哪吒2》票房的问题。首先,我得仔细看一下用户提供的知识库内容,里面有很多相关的引用资料。
用户的问题很简单,就是询问《哪吒2》的票房情况。根据知识库里的信息,我需要找到最新的票房数据以及相关的排名信息。首先,我注意到多个引用提到了全球累计票房达到153亿人民币,比如ref_1、ref_3、ref_5、ref_6、ref_7、ref_8、ref_10都有提到这一点。特别是ref_6和ref_8提到全球票房超过153.47亿元,而ref_5和ref_7指出这个成绩让该片成为全球票房第五的电影,同时也是亚洲电影中的首例。
另外,用户可能还关心海外票房的情况。根据ref_5、ref_6、ref_7、ref_8,海外票房已经突破3亿元人民币,这也是一个重要的数据点,说明影片在国际市场上的表现。同时,ref_6提到密钥延期到4月30日,这可能意味着票房还有进一步增长的空间。
需要注意的是,不同的引用可能有细微的数据差异,比如有的提到153亿,有的则是153.47亿,这可能是因为统计时间不同导致的。根据系统时间2025年3月25日,而部分引用如ref_6和ref_8的数据是在3月24日或25日发布的,所以应该以最新的数据为准,即超过153.47亿元。
另外,用户可能还想了解该票房在全球的排名情况,根据多个引用,目前《哪吒2》暂列全球票房榜第五名,仅次于像《阿凡达》《泰坦尼克号》这样的大片。例如,ref_3提到它进入前五,并且是唯一非好莱坞电影进入21亿美元俱乐部,这显示了其国际影响力。
不过,也要注意有些引用如ref_9和ref_10提到了一些争议,比如票房的争议或抄袭问题,但用户的问题主要是询问票房数字,所以这部分可能不需要深入,除非用户后续追问。但根据要求,回答需要优先引用提供的资料,所以应集中在票房数据上。
总结一下,我需要将全球票房和海外票房分开说明,并引用对应的来源。同时指出其排名和里程碑意义,比如成为亚洲电影中的首部进入全球前五,以及非好莱坞电影的突破。需要确保引用正确的ref编号,避免错误。
====================完整回复====================
截至2025年3月25日,《哪吒2》(《哪吒之魔童闹海》)的全球累计票房已突破**153.47亿元人民币**(含预售及海外票房),暂列全球影史票房榜第5名[ref_6][ref_7][ref_8]。其中,其海外票房已超过3亿元人民币,刷新了中国动画电影海外发行的多项纪录[ref_5][ref_6][ref_8]。
该片不仅是首部跻身全球票房前五的亚洲电影,也是唯一一部进入全球票房21亿美元俱乐部的非好莱坞电影,标志着中国动画电影在国际市场的里程碑式突破[ref_1][ref_3][ref_5]。目前其票房已超越《蜘蛛侠:跨纬度》等好莱坞大片,与排名第四的《泰坦尼克号》(约17.亿美元,约合115亿人民币)仅差约11亿元人民币[ref_3][ref_10]。
值得注意的是,《哪吒2》自上映以来持续延长上映周期,密钥已延期至2025年4月30日,票房仍有进一步增长的空间[ref_6]。
====================Token 消耗====================
GenerationUsage(inputTokens=1272, outputTokens=794, totalTokens=2066)
示例代码
curl -X POST "https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-DashScope-SSE: enable" \
-d '{
"model": "qwq-plus",
"input":{
"messages":[
{
"role": "user",
"content": "哪吒2的票房"
}
]
},
"parameters":{
"enable_search": true,
"search_options": {
"forced_search": true,
"enable_source": true,
"enable_citation": true,
"citation_format": "[ref_<number>]",
"search_strategy": "pro"
}
}
}'
返回结果
id:1
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"好的,我现在","role":"assistant"},"finish_reason":"null"}],"search_info":{"search_results":[{"site_name":"","icon":"","index":1,"title":"哪吒2海外票房破3亿了, 中国动画的全球崛起-行知探索圈","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=6f339f9b001142ef81f9e5dd04f40777!!wm_id=217a3dfad10e46d095fa9af00282c896"},{"site_name":"","icon":"","index":2,"title":"《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282"},{"site_name":"","icon":"","index":3,"title":"《哪吒2》全球票房破153亿, 距离超越《泰坦尼克号》还有多远?-倾城一笑红颜吖","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=effc0af9cee743b2b3485a75eb85dfae!!wm_id=01887e0e8266475b87b8ef1e578e5239"},{"site_name":"","icon":"","index":4,"title":"《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282"},{"site_name":"新浪网","icon":"https://img.alicdn.com/imgextra/i2/O1CN01mvEkNg1mbgbrppM5C_!!6000000004973-55-tps-32-32.svg","index":5,"title":"《哪吒2》海外票房破3亿 暂列全球票房榜第5名-新浪财经","url":"https://finance.sina.com.cn/tech/roll/2025-03-25/doc-ineqvkuu7132514.shtml"},{"site_name":"第一财经","icon":"https://img.alicdn.com/imgextra/i2/O1CN01IBw5aS1M3d9GmYvnx_!!6000000001379-55-tps-32-32.svg","index":6,"title":"《哪吒2》海外票房破3亿-一财网","url":"http://m.yicai.com/news/102532036.html"},{"site_name":"163网易免费邮","icon":"https://img.alicdn.com/imgextra/i2/O1CN01rbsKN11MIkDguCxUW_!!6000000001412-55-tps-32-32.svg","index":7,"title":"《哪吒2》153亿票房遭\"冷嘲热讽\",我们为什么对国产动画如此苛刻-网易订阅","url":"https://m.163.com/dy/article/JREIHES40556B7G8.html"},{"site_name":"财新网","icon":"https://img.alicdn.com/imgextra/i2/O1CN01oWqr251caB9yMliXs_!!6000000003616-73-tps-16-16.ico","index":8,"title":"票房|《哪吒2》登陆英国、日本院线 国内放映延长到五一-财新网","url":"https://www.caixin.com/2025-03-24/102301462.html"},{"site_name":"","icon":"","index":9,"title":"《哪吒2》抄袭被实锤? 全球票房超153亿, 让太多人眼红-影视原说","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=fd1f933252da43d79c09fc43ea53b972!!wm_id=3660dc355efa44509f7f22e4240a7845"},{"site_name":"","icon":"","index":10,"title":"《哪吒2》延长上映至五一,票房火爆, 能否超越全球纪录成为第一-娱乐无限播","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1228e8af15cf412e8d43c934a2a6a482!!wm_id=30ba0aef32144af39424a1942c5b7de8"}]}},"usage":{"total_tokens":1324,"input_tokens":1319,"output_tokens":5},"request_id":"f9fd41a8-2665-9abf-9366-96bbe2875be4"}
id:2
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"需要回答用户关于《哪","role":"assistant"},"finish_reason":"null"}],"search_info":{"search_results":[{"site_name":"","icon":"","index":1,"title":"哪吒2海外票房破3亿了, 中国动画的全球崛起-行知探索圈","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=6f339f9b001142ef81f9e5dd04f40777!!wm_id=217a3dfad10e46d095fa9af00282c896"},{"site_name":"","icon":"","index":2,"title":"《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282"},{"site_name":"","icon":"","index":3,"title":"《哪吒2》全球票房破153亿, 距离超越《泰坦尼克号》还有多远?-倾城一笑红颜吖","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=effc0af9cee743b2b3485a75eb85dfae!!wm_id=01887e0e8266475b87b8ef1e578e5239"},{"site_name":"","icon":"","index":4,"title":"《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282"},{"site_name":"新浪网","icon":"https://img.alicdn.com/imgextra/i2/O1CN01mvEkNg1mbgbrppM5C_!!6000000004973-55-tps-32-32.svg","index":5,"title":"《哪吒2》海外票房破3亿 暂列全球票房榜第5名-新浪财经","url":"https://finance.sina.com.cn/tech/roll/2025-03-25/doc-ineqvkuu7132514.shtml"},{"site_name":"第一财经","icon":"https://img.alicdn.com/imgextra/i2/O1CN01IBw5aS1M3d9GmYvnx_!!6000000001379-55-tps-32-32.svg","index":6,"title":"《哪吒2》海外票房破3亿-一财网","url":"http://m.yicai.com/news/102532036.html"},{"site_name":"163网易免费邮","icon":"https://img.alicdn.com/imgextra/i2/O1CN01rbsKN11MIkDguCxUW_!!6000000001412-55-tps-32-32.svg","index":7,"title":"《哪吒2》153亿票房遭\"冷嘲热讽\",我们为什么对国产动画如此苛刻-网易订阅","url":"https://m.163.com/dy/article/JREIHES40556B7G8.html"},{"site_name":"财新网","icon":"https://img.alicdn.com/imgextra/i2/O1CN01oWqr251caB9yMliXs_!!6000000003616-73-tps-16-16.ico","index":8,"title":"票房|《哪吒2》登陆英国、日本院线 国内放映延长到五一-财新网","url":"https://www.caixin.com/2025-03-24/102301462.html"},{"site_name":"","icon":"","index":9,"title":"《哪吒2》抄袭被实锤? 全球票房超153亿, 让太多人眼红-影视原说","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=fd1f933252da43d79c09fc43ea53b972!!wm_id=3660dc355efa44509f7f22e4240a7845"},{"site_name":"","icon":"","index":10,"title":"《哪吒2》延长上映至五一,票房火爆, 能否超越全球纪录成为第一-娱乐无限播","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1228e8af15cf412e8d43c934a2a6a482!!wm_id=30ba0aef32144af39424a1942c5b7de8"}]}},"usage":{"total_tokens":1330,"input_tokens":1319,"output_tokens":11},"request_id":"f9fd41a8-2665-9abf-9366-96bbe2875be4"}
id:3
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"吒2》票房的问题。","role":"assistant"},"finish_reason":"null"}],"search_info":{"search_results":[{"site_name":"","icon":"","index":1,"title":"哪吒2海外票房破3亿了, 中国动画的全球崛起-行知探索圈","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=6f339f9b001142ef81f9e5dd04f40777!!wm_id=217a3dfad10e46d095fa9af00282c896"},{"site_name":"","icon":"","index":2,"title":"《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282"},{"site_name":"","icon":"","index":3,"title":"《哪吒2》全球票房破153亿, 距离超越《泰坦尼克号》还有多远?-倾城一笑红颜吖","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=effc0af9cee743b2b3485a75eb85dfae!!wm_id=01887e0e8266475b87b8ef1e578e5239"},{"site_name":"","icon":"","index":4,"title":"《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282"},{"site_name":"新浪网","icon":"https://img.alicdn.com/imgextra/i2/O1CN01mvEkNg1mbgbrppM5C_!!6000000004973-55-tps-32-32.svg","index":5,"title":"《哪吒2》海外票房破3亿 暂列全球票房榜第5名-新浪财经","url":"https://finance.sina.com.cn/tech/roll/2025-03-25/doc-ineqvkuu7132514.shtml"},{"site_name":"第一财经","icon":"https://img.alicdn.com/imgextra/i2/O1CN01IBw5aS1M3d9GmYvnx_!!6000000001379-55-tps-32-32.svg","index":6,"title":"《哪吒2》海外票房破3亿-一财网","url":"http://m.yicai.com/news/102532036.html"},{"site_name":"163网易免费邮","icon":"https://img.alicdn.com/imgextra/i2/O1CN01rbsKN11MIkDguCxUW_!!6000000001412-55-tps-32-32.svg","index":7,"title":"《哪吒2》153亿票房遭\"冷嘲热讽\",我们为什么对国产动画如此苛刻-网易订阅","url":"https://m.163.com/dy/article/JREIHES40556B7G8.html"},{"site_name":"财新网","icon":"https://img.alicdn.com/imgextra/i2/O1CN01oWqr251caB9yMliXs_!!6000000003616-73-tps-16-16.ico","index":8,"title":"票房|《哪吒2》登陆英国、日本院线 国内放映延长到五一-财新网","url":"https://www.caixin.com/2025-03-24/102301462.html"},{"site_name":"","icon":"","index":9,"title":"《哪吒2》抄袭被实锤? 全球票房超153亿, 让太多人眼红-影视原说","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=fd1f933252da43d79c09fc43ea53b972!!wm_id=3660dc355efa44509f7f22e4240a7845"},{"site_name":"","icon":"","index":10,"title":"《哪吒2》延长上映至五一,票房火爆, 能否超越全球纪录成为第一-娱乐无限播","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1228e8af15cf412e8d43c934a2a6a482!!wm_id=30ba0aef32144af39424a1942c5b7de8"}]}},"usage":{"total_tokens":1336,"input_tokens":1319,"output_tokens":17},"request_id":"f9fd41a8-2665-9abf-9366-96bbe2875be4"}
id:4
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"首先,我要查看","role":"assistant"},"finish_reason":"null"}],"search_info":{"search_results":[{"site_name":"","icon":"","index":1,"title":"哪吒2海外票房破3亿了, 中国动画的全球崛起-行知探索圈","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=6f339f9b001142ef81f9e5dd04f40777!!wm_id=217a3dfad10e46d095fa9af00282c896"},{"site_name":"","icon":"","index":2,"title":"《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282"},{"site_name":"","icon":"","index":3,"title":"《哪吒2》全球票房破153亿, 距离超越《泰坦尼克号》还有多远?-倾城一笑红颜吖","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=effc0af9cee743b2b3485a75eb85dfae!!wm_id=01887e0e8266475b87b8ef1e578e5239"},{"site_name":"","icon":"","index":4,"title":"《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282"},{"site_name":"新浪网","icon":"https://img.alicdn.com/imgextra/i2/O1CN01mvEkNg1mbgbrppM5C_!!6000000004973-55-tps-32-32.svg","index":5,"title":"《哪吒2》海外票房破3亿 暂列全球票房榜第5名-新浪财经","url":"https://finance.sina.com.cn/tech/roll/2025-03-25/doc-ineqvkuu7132514.shtml"},{"site_name":"第一财经","icon":"https://img.alicdn.com/imgextra/i2/O1CN01IBw5aS1M3d9GmYvnx_!!6000000001379-55-tps-32-32.svg","index":6,"title":"《哪吒2》海外票房破3亿-一财网","url":"http://m.yicai.com/news/102532036.html"},{"site_name":"163网易免费邮","icon":"https://img.alicdn.com/imgextra/i2/O1CN01rbsKN11MIkDguCxUW_!!6000000001412-55-tps-32-32.svg","index":7,"title":"《哪吒2》153亿票房遭\"冷嘲热讽\",我们为什么对国产动画如此苛刻-网易订阅","url":"https://m.163.com/dy/article/JREIHES40556B7G8.html"},{"site_name":"财新网","icon":"https://img.alicdn.com/imgextra/i2/O1CN01oWqr251caB9yMliXs_!!6000000003616-73-tps-16-16.ico","index":8,"title":"票房|《哪吒2》登陆英国、日本院线 国内放映延长到五一-财新网","url":"https://www.caixin.com/2025-03-24/102301462.html"},{"site_name":"","icon":"","index":9,"title":"《哪吒2》抄袭被实锤? 全球票房超153亿, 让太多人眼红-影视原说","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=fd1f933252da43d79c09fc43ea53b972!!wm_id=3660dc355efa44509f7f22e4240a7845"},{"site_name":"","icon":"","index":10,"title":"《哪吒2》延长上映至五一,票房火爆, 能否超越全球纪录成为第一-娱乐无限播","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1228e8af15cf412e8d43c934a2a6a482!!wm_id=30ba0aef32144af39424a1942c5b7de8"}]}},"usage":{"total_tokens":1340,"input_tokens":1319,"output_tokens":21},"request_id":"f9fd41a8-2665-9abf-9366-96bbe2875be4"}
...
id:124
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"。 \n\n需要注意的是,不同","reasoning_content":"","role":"assistant"},"finish_reason":"null"}],"search_info":{"search_results":[{"site_name":"","icon":"","index":1,"title":"哪吒2海外票房破3亿了, 中国动画的全球崛起-行知探索圈","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=6f339f9b001142ef81f9e5dd04f40777!!wm_id=217a3dfad10e46d095fa9af00282c896"},{"site_name":"","icon":"","index":2,"title":"《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282"},{"site_name":"","icon":"","index":3,"title":"《哪吒2》全球票房破153亿, 距离超越《泰坦尼克号》还有多远?-倾城一笑红颜吖","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=effc0af9cee743b2b3485a75eb85dfae!!wm_id=01887e0e8266475b87b8ef1e578e5239"},{"site_name":"","icon":"","index":4,"title":"《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282"},{"site_name":"新浪网","icon":"https://img.alicdn.com/imgextra/i2/O1CN01mvEkNg1mbgbrppM5C_!!6000000004973-55-tps-32-32.svg","index":5,"title":"《哪吒2》海外票房破3亿 暂列全球票房榜第5名-新浪财经","url":"https://finance.sina.com.cn/tech/roll/2025-03-25/doc-ineqvkuu7132514.shtml"},{"site_name":"第一财经","icon":"https://img.alicdn.com/imgextra/i2/O1CN01IBw5aS1M3d9GmYvnx_!!6000000001379-55-tps-32-32.svg","index":6,"title":"《哪吒2》海外票房破3亿-一财网","url":"http://m.yicai.com/news/102532036.html"},{"site_name":"163网易免费邮","icon":"https://img.alicdn.com/imgextra/i2/O1CN01rbsKN11MIkDguCxUW_!!6000000001412-55-tps-32-32.svg","index":7,"title":"《哪吒2》153亿票房遭\"冷嘲热讽\",我们为什么对国产动画如此苛刻-网易订阅","url":"https://m.163.com/dy/article/JREIHES40556B7G8.html"},{"site_name":"财新网","icon":"https://img.alicdn.com/imgextra/i2/O1CN01oWqr251caB9yMliXs_!!6000000003616-73-tps-16-16.ico","index":8,"title":"票房|《哪吒2》登陆英国、日本院线 国内放映延长到五一-财新网","url":"https://www.caixin.com/2025-03-24/102301462.html"},{"site_name":"","icon":"","index":9,"title":"《哪吒2》抄袭被实锤? 全球票房超153亿, 让太多人眼红-影视原说","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=fd1f933252da43d79c09fc43ea53b972!!wm_id=3660dc355efa44509f7f22e4240a7845"},{"site_name":"","icon":"","index":10,"title":"《哪吒2》延长上映至五一,票房火爆, 能否超越全球纪录成为第一-娱乐无限播","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1228e8af15cf412e8d43c934a2a6a482!!wm_id=30ba0aef32144af39424a1942c5b7de8"}]}},"usage":{"total_tokens":1923,"input_tokens":1319,"output_tokens":604},"request_id":"f9fd41a8-2665-9abf-9366-96bbe2875be4"}
id:125
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"数据源的票房","reasoning_content":"","role":"assistant"},"finish_reason":"null"}],"search_info":{"search_results":[{"site_name":"","icon":"","index":1,"title":"哪吒2海外票房破3亿了, 中国动画的全球崛起-行知探索圈","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=6f339f9b001142ef81f9e5dd04f40777!!wm_id=217a3dfad10e46d095fa9af00282c896"},{"site_name":"","icon":"","index":2,"title":"《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282"},{"site_name":"","icon":"","index":3,"title":"《哪吒2》全球票房破153亿, 距离超越《泰坦尼克号》还有多远?-倾城一笑红颜吖","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=effc0af9cee743b2b3485a75eb85dfae!!wm_id=01887e0e8266475b87b8ef1e578e5239"},{"site_name":"","icon":"","index":4,"title":"《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282"},{"site_name":"新浪网","icon":"https://img.alicdn.com/imgextra/i2/O1CN01mvEkNg1mbgbrppM5C_!!6000000004973-55-tps-32-32.svg","index":5,"title":"《哪吒2》海外票房破3亿 暂列全球票房榜第5名-新浪财经","url":"https://finance.sina.com.cn/tech/roll/2025-03-25/doc-ineqvkuu7132514.shtml"},{"site_name":"第一财经","icon":"https://img.alicdn.com/imgextra/i2/O1CN01IBw5aS1M3d9GmYvnx_!!6000000001379-55-tps-32-32.svg","index":6,"title":"《哪吒2》海外票房破3亿-一财网","url":"http://m.yicai.com/news/102532036.html"},{"site_name":"163网易免费邮","icon":"https://img.alicdn.com/imgextra/i2/O1CN01rbsKN11MIkDguCxUW_!!6000000001412-55-tps-32-32.svg","index":7,"title":"《哪吒2》153亿票房遭\"冷嘲热讽\",我们为什么对国产动画如此苛刻-网易订阅","url":"https://m.163.com/dy/article/JREIHES40556B7G8.html"},{"site_name":"财新网","icon":"https://img.alicdn.com/imgextra/i2/O1CN01oWqr251caB9yMliXs_!!6000000003616-73-tps-16-16.ico","index":8,"title":"票房|《哪吒2》登陆英国、日本院线 国内放映延长到五一-财新网","url":"https://www.caixin.com/2025-03-24/102301462.html"},{"site_name":"","icon":"","index":9,"title":"《哪吒2》抄袭被实锤? 全球票房超153亿, 让太多人眼红-影视原说","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=fd1f933252da43d79c09fc43ea53b972!!wm_id=3660dc355efa44509f7f22e4240a7845"},{"site_name":"","icon":"","index":10,"title":"《哪吒2》延长上映至五一,票房火爆, 能否超越全球纪录成为第一-娱乐无限播","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1228e8af15cf412e8d43c934a2a6a482!!wm_id=30ba0aef32144af39424a1942c5b7de8"}]}},"usage":{"total_tokens":1927,"input_tokens":1319,"output_tokens":608},"request_id":"f9fd41a8-2665-9abf-9366-96bbe2875be4"}
id:126
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"统计可能存在细微差异,","reasoning_content":"","role":"assistant"},"finish_reason":"null"}],"search_info":{"search_results":[{"site_name":"","icon":"","index":1,"title":"哪吒2海外票房破3亿了, 中国动画的全球崛起-行知探索圈","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=6f339f9b001142ef81f9e5dd04f40777!!wm_id=217a3dfad10e46d095fa9af00282c896"},{"site_name":"","icon":"","index":2,"title":"《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282"},{"site_name":"","icon":"","index":3,"title":"《哪吒2》全球票房破153亿, 距离超越《泰坦尼克号》还有多远?-倾城一笑红颜吖","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=effc0af9cee743b2b3485a75eb85dfae!!wm_id=01887e0e8266475b87b8ef1e578e5239"},{"site_name":"","icon":"","index":4,"title":"《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282"},{"site_name":"新浪网","icon":"https://img.alicdn.com/imgextra/i2/O1CN01mvEkNg1mbgbrppM5C_!!6000000004973-55-tps-32-32.svg","index":5,"title":"《哪吒2》海外票房破3亿 暂列全球票房榜第5名-新浪财经","url":"https://finance.sina.com.cn/tech/roll/2025-03-25/doc-ineqvkuu7132514.shtml"},{"site_name":"第一财经","icon":"https://img.alicdn.com/imgextra/i2/O1CN01IBw5aS1M3d9GmYvnx_!!6000000001379-55-tps-32-32.svg","index":6,"title":"《哪吒2》海外票房破3亿-一财网","url":"http://m.yicai.com/news/102532036.html"},{"site_name":"163网易免费邮","icon":"https://img.alicdn.com/imgextra/i2/O1CN01rbsKN11MIkDguCxUW_!!6000000001412-55-tps-32-32.svg","index":7,"title":"《哪吒2》153亿票房遭\"冷嘲热讽\",我们为什么对国产动画如此苛刻-网易订阅","url":"https://m.163.com/dy/article/JREIHES40556B7G8.html"},{"site_name":"财新网","icon":"https://img.alicdn.com/imgextra/i2/O1CN01oWqr251caB9yMliXs_!!6000000003616-73-tps-16-16.ico","index":8,"title":"票房|《哪吒2》登陆英国、日本院线 国内放映延长到五一-财新网","url":"https://www.caixin.com/2025-03-24/102301462.html"},{"site_name":"","icon":"","index":9,"title":"《哪吒2》抄袭被实锤? 全球票房超153亿, 让太多人眼红-影视原说","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=fd1f933252da43d79c09fc43ea53b972!!wm_id=3660dc355efa44509f7f22e4240a7845"},{"site_name":"","icon":"","index":10,"title":"《哪吒2》延长上映至五一,票房火爆, 能否超越全球纪录成为第一-娱乐无限播","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1228e8af15cf412e8d43c934a2a6a482!!wm_id=30ba0aef32144af39424a1942c5b7de8"}]}},"usage":{"total_tokens":1932,"input_tokens":1319,"output_tokens":613},"request_id":"f9fd41a8-2665-9abf-9366-96bbe2875be4"}
id:127
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"但整体趋势和","reasoning_content":"","role":"assistant"},"finish_reason":"null"}],"search_info":{"search_results":[{"site_name":"","icon":"","index":1,"title":"哪吒2海外票房破3亿了, 中国动画的全球崛起-行知探索圈","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=6f339f9b001142ef81f9e5dd04f40777!!wm_id=217a3dfad10e46d095fa9af00282c896"},{"site_name":"","icon":"","index":2,"title":"《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282"},{"site_name":"","icon":"","index":3,"title":"《哪吒2》全球票房破153亿, 距离超越《泰坦尼克号》还有多远?-倾城一笑红颜吖","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=effc0af9cee743b2b3485a75eb85dfae!!wm_id=01887e0e8266475b87b8ef1e578e5239"},{"site_name":"","icon":"","index":4,"title":"《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282"},{"site_name":"新浪网","icon":"https://img.alicdn.com/imgextra/i2/O1CN01mvEkNg1mbgbrppM5C_!!6000000004973-55-tps-32-32.svg","index":5,"title":"《哪吒2》海外票房破3亿 暂列全球票房榜第5名-新浪财经","url":"https://finance.sina.com.cn/tech/roll/2025-03-25/doc-ineqvkuu7132514.shtml"},{"site_name":"第一财经","icon":"https://img.alicdn.com/imgextra/i2/O1CN01IBw5aS1M3d9GmYvnx_!!6000000001379-55-tps-32-32.svg","index":6,"title":"《哪吒2》海外票房破3亿-一财网","url":"http://m.yicai.com/news/102532036.html"},{"site_name":"163网易免费邮","icon":"https://img.alicdn.com/imgextra/i2/O1CN01rbsKN11MIkDguCxUW_!!6000000001412-55-tps-32-32.svg","index":7,"title":"《哪吒2》153亿票房遭\"冷嘲热讽\",我们为什么对国产动画如此苛刻-网易订阅","url":"https://m.163.com/dy/article/JREIHES40556B7G8.html"},{"site_name":"财新网","icon":"https://img.alicdn.com/imgextra/i2/O1CN01oWqr251caB9yMliXs_!!6000000003616-73-tps-16-16.ico","index":8,"title":"票房|《哪吒2》登陆英国、日本院线 国内放映延长到五一-财新网","url":"https://www.caixin.com/2025-03-24/102301462.html"},{"site_name":"","icon":"","index":9,"title":"《哪吒2》抄袭被实锤? 全球票房超153亿, 让太多人眼红-影视原说","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=fd1f933252da43d79c09fc43ea53b972!!wm_id=3660dc355efa44509f7f22e4240a7845"},{"site_name":"","icon":"","index":10,"title":"《哪吒2》延长上映至五一,票房火爆, 能否超越全球纪录成为第一-娱乐无限播","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1228e8af15cf412e8d43c934a2a6a482!!wm_id=30ba0aef32144af39424a1942c5b7de8"}]}},"usage":{"total_tokens":1936,"input_tokens":1319,"output_tokens":617},"request_id":"f9fd41a8-2665-9abf-9366-96bbe2875be4"}
id:128
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"排名基本一致。","reasoning_content":"","role":"assistant"},"finish_reason":"null"}],"search_info":{"search_results":[{"site_name":"","icon":"","index":1,"title":"哪吒2海外票房破3亿了, 中国动画的全球崛起-行知探索圈","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=6f339f9b001142ef81f9e5dd04f40777!!wm_id=217a3dfad10e46d095fa9af00282c896"},{"site_name":"","icon":"","index":2,"title":"《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282"},{"site_name":"","icon":"","index":3,"title":"《哪吒2》全球票房破153亿, 距离超越《泰坦尼克号》还有多远?-倾城一笑红颜吖","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=effc0af9cee743b2b3485a75eb85dfae!!wm_id=01887e0e8266475b87b8ef1e578e5239"},{"site_name":"","icon":"","index":4,"title":"《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282"},{"site_name":"新浪网","icon":"https://img.alicdn.com/imgextra/i2/O1CN01mvEkNg1mbgbrppM5C_!!6000000004973-55-tps-32-32.svg","index":5,"title":"《哪吒2》海外票房破3亿 暂列全球票房榜第5名-新浪财经","url":"https://finance.sina.com.cn/tech/roll/2025-03-25/doc-ineqvkuu7132514.shtml"},{"site_name":"第一财经","icon":"https://img.alicdn.com/imgextra/i2/O1CN01IBw5aS1M3d9GmYvnx_!!6000000001379-55-tps-32-32.svg","index":6,"title":"《哪吒2》海外票房破3亿-一财网","url":"http://m.yicai.com/news/102532036.html"},{"site_name":"163网易免费邮","icon":"https://img.alicdn.com/imgextra/i2/O1CN01rbsKN11MIkDguCxUW_!!6000000001412-55-tps-32-32.svg","index":7,"title":"《哪吒2》153亿票房遭\"冷嘲热讽\",我们为什么对国产动画如此苛刻-网易订阅","url":"https://m.163.com/dy/article/JREIHES40556B7G8.html"},{"site_name":"财新网","icon":"https://img.alicdn.com/imgextra/i2/O1CN01oWqr251caB9yMliXs_!!6000000003616-73-tps-16-16.ico","index":8,"title":"票房|《哪吒2》登陆英国、日本院线 国内放映延长到五一-财新网","url":"https://www.caixin.com/2025-03-24/102301462.html"},{"site_name":"","icon":"","index":9,"title":"《哪吒2》抄袭被实锤? 全球票房超153亿, 让太多人眼红-影视原说","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=fd1f933252da43d79c09fc43ea53b972!!wm_id=3660dc355efa44509f7f22e4240a7845"},{"site_name":"","icon":"","index":10,"title":"《哪吒2》延长上映至五一,票房火爆, 能否超越全球纪录成为第一-娱乐无限播","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1228e8af15cf412e8d43c934a2a6a482!!wm_id=30ba0aef32144af39424a1942c5b7de8"}]}},"usage":{"total_tokens":1940,"input_tokens":1319,"output_tokens":621},"request_id":"f9fd41a8-2665-9abf-9366-96bbe2875be4"}
id:129
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"","role":"assistant"},"finish_reason":"stop"}],"search_info":{"search_results":[{"site_name":"","icon":"","index":1,"title":"哪吒2海外票房破3亿了, 中国动画的全球崛起-行知探索圈","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=6f339f9b001142ef81f9e5dd04f40777!!wm_id=217a3dfad10e46d095fa9af00282c896"},{"site_name":"","icon":"","index":2,"title":"《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282"},{"site_name":"","icon":"","index":3,"title":"《哪吒2》全球票房破153亿, 距离超越《泰坦尼克号》还有多远?-倾城一笑红颜吖","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=effc0af9cee743b2b3485a75eb85dfae!!wm_id=01887e0e8266475b87b8ef1e578e5239"},{"site_name":"","icon":"","index":4,"title":"《哪吒2》153亿票房背后: 我们追捧的到底是国漫, 还是特效鸦片?-逍遥扒扒影","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1331f1eb7f174d0d8c5ba11efa65daad!!wm_id=a1eb50c1972d4eb2b0dc95d47c886282"},{"site_name":"新浪网","icon":"https://img.alicdn.com/imgextra/i2/O1CN01mvEkNg1mbgbrppM5C_!!6000000004973-55-tps-32-32.svg","index":5,"title":"《哪吒2》海外票房破3亿 暂列全球票房榜第5名-新浪财经","url":"https://finance.sina.com.cn/tech/roll/2025-03-25/doc-ineqvkuu7132514.shtml"},{"site_name":"第一财经","icon":"https://img.alicdn.com/imgextra/i2/O1CN01IBw5aS1M3d9GmYvnx_!!6000000001379-55-tps-32-32.svg","index":6,"title":"《哪吒2》海外票房破3亿-一财网","url":"http://m.yicai.com/news/102532036.html"},{"site_name":"163网易免费邮","icon":"https://img.alicdn.com/imgextra/i2/O1CN01rbsKN11MIkDguCxUW_!!6000000001412-55-tps-32-32.svg","index":7,"title":"《哪吒2》153亿票房遭\"冷嘲热讽\",我们为什么对国产动画如此苛刻-网易订阅","url":"https://m.163.com/dy/article/JREIHES40556B7G8.html"},{"site_name":"财新网","icon":"https://img.alicdn.com/imgextra/i2/O1CN01oWqr251caB9yMliXs_!!6000000003616-73-tps-16-16.ico","index":8,"title":"票房|《哪吒2》登陆英国、日本院线 国内放映延长到五一-财新网","url":"https://www.caixin.com/2025-03-24/102301462.html"},{"site_name":"","icon":"","index":9,"title":"《哪吒2》抄袭被实锤? 全球票房超153亿, 让太多人眼红-影视原说","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=fd1f933252da43d79c09fc43ea53b972!!wm_id=3660dc355efa44509f7f22e4240a7845"},{"site_name":"","icon":"","index":10,"title":"《哪吒2》延长上映至五一,票房火爆, 能否超越全球纪录成为第一-娱乐无限播","url":"https://mparticle.uc.cn/article.html?uc_param_str=frdnsnpfvecpntnwprdssskt#!wm_aid=1228e8af15cf412e8d43c934a2a6a482!!wm_id=30ba0aef32144af39424a1942c5b7de8"}]}},"usage":{"total_tokens":1940,"input_tokens":1319,"output_tokens":621},"request_id":"f9fd41a8-2665-9abf-9366-96bbe2875be4"}
在设置enable_search
参数为true
后,您可以通过search_options
参数来配置联网搜索策略,包括以下方面:
是否强制开启联网搜索
通过
forced_search
配置,可选值:true
强制开启。
false
(默认值)不强制开启。
搜索互联网信息的数量
通过
search_strategy
配置。可选值:"standard"
(默认值)模型会联网搜索5条信息。
"pro"
模型会联网搜索10条信息。
OpenAI 兼容方式暂不支持返回搜索来源的信息。
示例代码
from openai import OpenAI
import os
# 初始化OpenAI客户端
client = OpenAI(
# 如果没有配置环境变量,请用百炼API Key替换:api_key="sk-xxx"
api_key = os.getenv("DASHSCOPE_API_KEY"),
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"
)
reasoning_content = "" # 定义完整思考过程
answer_content = "" # 定义完整回复
is_answering = False # 判断是否结束思考过程并开始回复
# 创建聊天完成请求
completion = client.chat.completions.create(
model="qwq-plus", # 此处以 qwq-plus 为例,可按需更换模型名称
messages=[
{"role": "user", "content": "哪吒2的票房"}
],
extra_body={
"enable_search": True, # 开启联网搜索的参数
"search_options": {
"forced_search": True, # 强制联网搜索的参数
"search_strategy": "pro" # 模型将搜索10条互联网信息
}
},
# QwQ 模型仅支持流式输出方式调用
stream=True,
# 解除以下注释会在最后一个chunk返回Token使用量
stream_options={
"include_usage": True
}
)
print("\n" + "=" * 20 + "思考过程" + "=" * 20 + "\n")
for chunk in completion:
# 如果chunk.choices为空,则打印usage
if not chunk.choices:
print("\n" + "=" * 20 + "Usage" + "=" * 20)
print(chunk.usage)
else:
delta = chunk.choices[0].delta
# 打印思考过程
if hasattr(delta, 'reasoning_content') and delta.reasoning_content != None:
print(delta.reasoning_content, end='', flush=True)
reasoning_content += delta.reasoning_content
else:
# 开始回复
if delta.content != "" and is_answering is False:
print("\n" + "=" * 20 + "完整回复" + "=" * 20 + "\n")
is_answering = True
# 打印回复过程
print(delta.content, end='', flush=True)
answer_content += delta.content
# print("=" * 20 + "完整思考过程" + "=" * 20 + "\n")
# print(reasoning_content)
# print("=" * 20 + "完整回复" + "=" * 20 + "\n")
# print(answer_content)
返回结果
====================思考过程====================
嗯,用户问的是《哪吒2》的票房情况,我需要先整理一下知识库里的信息。首先,知识库里的多篇文章都提到了《哪吒2》的全球票房已经突破153亿人民币,其中海外票房部分有不同的数据,比如有的说超过3亿,有的提到153.47亿。可能要注意到不同来源的时间差异,比如观察者网和新浪网的数据是到3月24日或25日的,而用户提供的当前时间是2025年3月25日,所以这些数据应该是最新的。
然后,用户可能想知道具体的数据,比如国内和海外的分别,以及在全球票房榜的位置。根据知识库内容,全球票房排在第五,暂时位于《泰坦尼克号》之后,还差约11亿才能超过。需要指出这个差距,以及海外票房还在增长,因为有些国家还没上映,比如日本、韩国等,可能后续还有增长空间。
另外,用户可能还关心票房背后的意义,比如是否代表国漫崛起,或者存在争议。但问题直接问票房,所以可能需要简洁回答数据,再补充一些相关情况。要注意不同来源的数据可能略有差异,比如有的说153亿,有的153.47亿,可能需要说明是综合数据,或者以最近的为准。
最后,确保回答清晰,分点列出国内、海外、全球总票房,排名情况,以及可能的后续发展。同时引用多个来源的信息,确保准确性。可能还要提到上映延期到4月30日,有助于票房继续增长。这样用户的问题就能得到全面解答了。
====================完整回复====================
根据最新的权威信息,《哪吒2》(《哪吒之魔童闹海》)的票房情况如下:
### **全球票房**
- **总票房**:已突破 **153.47亿元人民币**(含中国内地及海外票房),目前暂列全球影史票房榜第5位。
---
### **分地区票房**
1. **中国内地票房**:
- 截至3月21日,内地票房已达 **149亿元人民币**,且仍在延长上映中(密钥延期至4月30日),预计将进一步增长。
2. **海外票房**:
- **已突破3亿元人民币**(截至3月24日数据)。
- **主要市场表现**:
- **北美**:票房约2048万美元(约合1.4亿元人民币)。
- **澳大利亚、新西兰**:票房约559万美元(约合3900万元人民币)。
- **待上映地区**:日本、韩国、俄罗斯、南非、印度尼西亚等市场已确认引进,但具体档期尚未公布,后续票房仍有较大增长空间。
---
### **与《泰坦尼克号》的差距**
- 当前全球票房排名第4的是《泰坦尼克号》(重映版),票房约 **154.6亿元人民币**。
- **《哪吒2》需再增加约11亿元人民币**方能超越,登顶全球影史前四。
---
### **关键背景与意义**
1. **历史地位**:
- 已成为中国影史票房冠军,并是全球动画电影票房冠军。
- 近20年来国产电影在海外市场的最佳表现(非内地票房占比虽小,但创纪录)。
2. **延长上映与潜力**:
- 因持续热度,影片密钥延期至4月30日,国内票房可能进一步攀升。
- 海外多国待上映,若后续开画表现良好,全球票房有望继续突破。
---
### **争议与讨论**
- 部分观众认为影片成功依赖“视觉特效堆砌”,而非叙事深度,引发“国漫崛起”与“特效鸦片”之争。
- 尽管票房亮眼,仍存在对国产动画内容深度和可持续性的质疑。
---
### **总结**
《哪吒2》目前以 **153.47亿** 稳居全球票房第五,正逼近《泰坦尼克号》的纪录。其国内票房表现强势,海外虽起步较慢但潜力巨大,未来能否更进一步值得持续关注。
====================Usage====================
CompletionUsage(completion_tokens=903, prompt_tokens=1198, total_tokens=2101, completion_tokens_details=None, prompt_tokens_details=None)
示例代码
import OpenAI from "openai";
import process from 'process';
// 初始化 openai 客户端
const openai = new OpenAI({
apiKey: process.env.DASHSCOPE_API_KEY, // 从环境变量读取
baseURL: 'https://dashscope.aliyuncs.com/compatible-mode/v1'
});
let reasoningContent = '';
let answerContent = '';
let isAnswering = false;
async function main() {
try {
const stream = await openai.chat.completions.create({
model: 'qwq-plus',
messages: [{ role: 'user', content: '哪吒2的票房' }],
enable_search: true, // 开启联网搜索的参数
search_options: {
forced_search: true // 强制联网搜索的参数
},
// QwQ 模型仅支持流式输出方式调用
stream: true
});
console.log('\n' + '='.repeat(20) + '思考过程' + '='.repeat(20) + '\n');
for await (const chunk of stream) {
if (!chunk.choices?.length) {
console.log('\nUsage:');
console.log(chunk.usage);
continue;
}
const delta = chunk.choices[0].delta;
// 处理思考过程
if (delta.reasoning_content) {
process.stdout.write(delta.reasoning_content);
reasoningContent += delta.reasoning_content;
}
// 处理正式回复
else if (delta.content) {
if (!isAnswering) {
console.log('\n' + '='.repeat(20) + '完整回复' + '='.repeat(20) + '\n');
isAnswering = true;
}
process.stdout.write(delta.content);
answerContent += delta.content;
}
}
} catch (error) {
console.error('Error:', error);
}
}
main();
返回结果
====================思考过程====================
好的,用户问的是《哪吒2》的票房,我需要从知识库里的信息中整理出最新的数据。首先看一下知识库里的几条信息:
第一条是新华网的报道,提到票房冲上全球第7,突破141.6亿,超过《蜘蛛侠:英雄无归》。时间应该是较早的,因为后面还有更高的数据。
第二条科技日报的再刷纪录,提到超过130亿,暂时排第8位,但可能已经被后续数据更新了。
第三条中国网的新闻在3月14日,指出全球票房突破150亿,接近《星球大战:原力觉醒》的第五名。这里的时间是3月14日,而当前系统时间是3月21日,可能之后还有更新。
第四条科技日报的海外票房破2亿,全球票房超过149.79亿,冲击第五位。这里提到的全球票房是149.79亿,接近150亿,但可能还没到。
第五条新华每日电讯提到海外票房突破2亿,全球票房超过149.79亿,并且评分不错,但同样可能是在3月14日左右的数据。
现在需要确定最新的数据。第三条中国网的新闻明确提到3月14日突破150亿,而第四条可能是在同一天或之后的数据,但第四条的全球票房是149.79亿,接近150亿,可能稍早一点。但第三条已经明确说突破150亿,所以应该以第三条为准。另外,系统时间是3月21日,可能之后票房还在增长,但知识库里的最新数据是到3月14日的150亿,所以应该以这个为准。不过第四条提到的149.79亿可能是在3月14日当天的数据,而第三条突破150亿也是同一天。可能中国网的报道是当天的,所以综合来看,全球票房已经突破150亿,暂列第五位,正在冲击前五。需要确认是否已经进入前五,但根据第三条,它接近第五名的《星球大战:原力觉醒》,可能已经超越,但可能还未正式确认。需要看是否有明确的排名信息。第三条提到“暂列亚洲影史新纪录”,但全球排名可能还在接近第五的位置。所以最终回答应该综合这些信息,给出最新的150亿,并说明排名情况,以及海外票房的数据。需要确保数据准确,优先使用最新的日期,即中国网的3月14日突破150亿,并且海外票房2亿,冲击前五。可能用户想知道当前的最新数据,但根据知识库,最新的就是到3月14日的150亿,之后可能还在增长,但知识库没有更新到21日的数据,所以只能根据现有信息回答。
====================完整回复====================
截至2025年3月14日,《哪吒之魔童闹海》(《哪吒2》)的全球票房(含预售及海外)已突破**150亿元人民币**,创下亚洲影史新纪录,并成功跻身全球影史票房榜前五,目前暂列第五位,正逼近《星球大战:原力觉醒》的全球票房成绩。
### 具体数据:
1. **全球总票房**:超过150亿元人民币(含海外票房约2亿元人民币)。
2. **海外表现**:海外票房突破2亿元,且在烂番茄获得100%新鲜度,爆米花指数达99%,热度持续攀升。
3. **排名**:超越《蜘蛛侠:英雄无归》等影片,目前位列全球影史票房榜第5名,仅次于《阿凡达》《泰坦尼克号》《星球大战:原力觉醒》和《复仇者联盟4》。
### 说明:
- 知识库中最新数据为3月14日的150亿元,当前时间(3月21日)票房可能仍有小幅增长,但尚未有更新的官方数据公布。
- 该片已连续打破多项纪录,成为全球动画电影票房冠军,并持续推动中国电影在国际市场的影响力。
如需更实时的数据,建议关注权威票房平台或官方公告。
示例代码
curl -X POST https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwq-plus",
"messages": [
{
"role": "user",
"content": "哪吒2的票房"
}
],
"enable_search": true,
"search_options": {
"forced_search": true
},
"stream": true,
"stream_options": {
"include_usage": true
}
}'
返回结果
data: {"choices":[{"delta":{"content":null,"role":"assistant","reasoning_content":""},"index":0,"logprobs":null,"finish_reason":null}],"object":"chat.completion.chunk","usage":null,"created":1742537753,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-32c5e654-b497-9fc8-bba0-27e2f34026b2"}
data: {"choices":[{"finish_reason":null,"delta":{"content":null,"reasoning_content":"好的,我现在"},"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742537753,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-32c5e654-b497-9fc8-bba0-27e2f34026b2"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"需要回答用户关于《哪"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742537753,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-32c5e654-b497-9fc8-bba0-27e2f34026b2"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"吒2》票房的问题。"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742537753,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-32c5e654-b497-9fc8-bba0-27e2f34026b2"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"首先,我要查看用户提供的"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742537753,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-32c5e654-b497-9fc8-bba0-27e2f34026b2"}
data: {"choices":[{"delta":{"content":null,"reasoning_content":"知识库内容,里面有几个"},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742537753,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-32c5e654-b497-9fc8-bba0-27e2f34026b2"}
......
data: {"choices":[{"delta":{"content":"票房冠军,并跻身","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742537753,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-32c5e654-b497-9fc8-bba0-27e2f34026b2"}
data: {"choices":[{"delta":{"content":"全球前五,持续","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742537753,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-32c5e654-b497-9fc8-bba0-27e2f34026b2"}
data: {"choices":[{"delta":{"content":"刷新纪录。具体","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742537753,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-32c5e654-b497-9fc8-bba0-27e2f34026b2"}
data: {"choices":[{"delta":{"content":"排名可能因不同榜单","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742537753,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-32c5e654-b497-9fc8-bba0-27e2f34026b2"}
data: {"choices":[{"delta":{"content":"的统计方式略有差异,","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742537753,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-32c5e654-b497-9fc8-bba0-27e2f34026b2"}
data: {"choices":[{"delta":{"content":"但其市场表现和","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742537753,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-32c5e654-b497-9fc8-bba0-27e2f34026b2"}
data: {"choices":[{"delta":{"content":"影响力已得到广泛","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742537753,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-32c5e654-b497-9fc8-bba0-27e2f34026b2"}
data: {"choices":[{"delta":{"content":"认可。","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742537753,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-32c5e654-b497-9fc8-bba0-27e2f34026b2"}
data: {"choices":[{"finish_reason":"stop","delta":{"content":"","reasoning_content":null},"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1742537753,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-32c5e654-b497-9fc8-bba0-27e2f34026b2"}
data: {"choices":[],"object":"chat.completion.chunk","usage":{"prompt_tokens":511,"completion_tokens":1057,"total_tokens":1568},"created":1742537753,"system_fingerprint":null,"model":"qwq-plus","id":"chatcmpl-32c5e654-b497-9fc8-bba0-27e2f34026b2"}
data: [DONE]
注意事项
常见问题
Q:怎么关闭思考过程?
A:无法关闭,QwQ 模型的推理模式是先输出思考内容,再输出回复内容。
Q:免费额度用完后如何购买 Token?
A:您可以访问费用与成本中心进行充值,确保您的账户没有欠费即可调用 QwQ 模型。
超出免费额度后,调用 QwQ 模型会自动扣费,出账周期为一小时,消费明细请前往账单详情进行查看。
Q:如何接入Chatbox或Cherry Studio?
A:请根据您的使用情况参考以下步骤:
此处以使用较多的工具为例,其它大模型工具接入的方法较为类似。
Dify 云服务暂时不支持接入 QwQ 模型。
在设置界面的模型提供方选择添加自定义提供方。
进行 API 设置
名称输入“阿里云”(可自定义);
API 域名输入
https://dashscope.aliyuncs.com/compatible-mode/v1
;API 路径输入
/chat/completions
;API 密钥输入您的 API Key,获取方法请参见:获取API Key;
模型输入您需要使用的 QwQ模型,此处以
qwq-plus
为例(请注意字母的大小写);单击保存,完成设置。
进行对话测试
在输入框输入“你是谁?”进行测试:
单击左下角的设置按钮,在模型服务栏中找到阿里云百炼,API 密钥输入您的 API Key,获取方法请参见:获取API Key;API 地址填入
https://dashscope.aliyuncs.com/compatible-mode/v1/
;单击添加。在模型 ID填入您需要使用的 QwQ 模型,此处以
qwq-plus
为例(请注意模型 ID的大小写); 模型名称与分组名称会自动生成。如果您点击 API 密钥位置的检查后报错:“连接失败 400 This model only support stream mode, please enable the stream parameter to access the model”,请忽略该信息,您仍可以在对话框中与 QwQ 模型正常对话。
在界面上方选中添加的模型。输入“你是谁”进行测试:
Q:可以上传图片或文档进行提问吗?
A:QwQ 模型仅支持文本输入,不支持输入图片或文档。通义千问VL模型支持图片输入,Qwen- Long模型支持文档输入。
Q:如何在使用 LangChain 时输出思考过程?
A:请参考以下步骤:
更新依赖库
确保
langchain_community
和dashscope
为最新版本:pip install -U langchain_community dashscope
调用 QwQ 模型
QwQ 模型目前仅支持流式输出,通过以下代码来分开打印“思考过程”与“回复内容”:
from langchain_community.chat_models.tongyi import ChatTongyi from langchain_core.messages import HumanMessage chatLLM = ChatTongyi( model="qwq-plus", # 此处以qwq-plus为例,您可按需更换模型名称。 ) completion = chatLLM.stream([HumanMessage(content="你是谁")]) is_answering = False print("="*20+"思考过程 "+"="*20) for chunk in completion: if chunk.additional_kwargs.get("reasoning_content"): print(chunk.additional_kwargs.get("reasoning_content"),end="",flush=True) else: if not is_answering: print("\n"+"="*20+"回复内容"+"="*20) is_answering = True print(chunk.content,end="",flush=True)
可以获得如下输出:
====================思考过程 ==================== 嗯,用户问我“你是谁”,我需要先确定他们想了解什么。可能他们刚接触我的时候,或者想确认我的身份。首先,我应该简要介绍自己是通义千问,阿里巴巴集团旗下的超大规模语言模型。然后说明我的功能,比如回答问题、创作文字、编程等,这样用户知道我能做什么。还要提到我支持多语言,这样用户知道语言不是障碍。接下来,可能需要解释我的应用场景,比如写故事、写公文、写邮件、写剧本等,这样用户能具体了解我的用途。还要提到我的训练数据截止时间,这样用户知道我的知识更新到什么时候。最后,邀请用户提问,保持友好和开放的态度。需要确保回答简洁明了,信息全面,同时口语化,避免使用专业术语。可能用户是普通用户,不需要太技术性的解释。还要注意不要遗漏关键点,比如我的研发公司、功能、多语言支持、应用场景和训练时间。检查有没有重复或冗余的信息,确保流畅自然。可能用户还想知道如何与我互动,所以最后的邀请提问很重要。总之,结构应该是先介绍身份,再功能,应用场景,训练数据,最后邀请提问。这样用户能快速获取所需信息,并知道下一步该怎么做。 ====================回复内容==================== 你好!我是通义千问,阿里巴巴集团旗下的超大规模语言模型。我能够回答问题、创作文字,比如写故事、写公文、写邮件、写剧本、逻辑推理、编程等等,还能表达观点,玩游戏等。我支持多种语言,包括但不限于中文、英文、德语、法语、西班牙语等。 我的训练数据截止时间是2024年12月,这意味着我对2024年之前的信息有较好的了解,但对之后发生的事情可能不了解。如果你有任何问题或需要帮助,欢迎随时告诉我!
Q:如何查看Token消耗量及调用次数?
A:模型调用完一小时后,在模型观测页面的模型列表区域,找到目标模型,然后单击监控,即可查看调用统计。具体请参见模型观测文档。
数据按小时更新,高峰期可能有小时级延迟,请您耐心等待。
错误码
如果执行报错,请参见错误信息进行解决。
- 本页导读 (1)
- 概述
- QwQ 模型介绍
- 商业版模型
- 开源版模型
- 快速开始
- 多轮对话
- Function Calling(工具调用)
- 联网搜索
- 注意事项
- 常见问题
- Q:怎么关闭思考过程?
- Q:免费额度用完后如何购买 Token?
- Q:如何接入Chatbox或Cherry Studio?
- Q:可以上传图片或文档进行提问吗?
- Q:如何在使用 LangChain 时输出思考过程?
- Q:如何查看Token消耗量及调用次数?
- 错误码