Qwen3、QwQ(基于Qwen2.5) 与 DeepSeek-R1 模型具有强大的推理能力。模型会先输出思考过程,再输出回答内容。
深度思考模型介绍
百炼提供了Qwen3、QwQ、DeepSeek-R1 模型的 API。最新的Qwen3系列模型推理能力强,回复速度快,且支持 Function Calling 与联网搜索,推荐您优先使用Qwen3 模型。
Qwen3 模型支持思考模式和非思考模式,您可以通过 enable_thinking
参数实现两种模式的切换。除此之外,模型的能力得到了大幅提升:
推理能力:在数学、代码和逻辑推理等评测中,显著超过 QwQ 和同尺寸的非推理模型,达到同规模业界顶尖水平。
人类偏好能力:创意写作、角色扮演、多轮对话、指令遵循能力均大幅提升,通用能力显著超过同尺寸模型。
Agent 能力:在推理、非推理两种模式下都达到业界领先水平,能精准调用外部工具。
多语言能力:支持100多种语言和方言,多语言翻译、指令理解、常识推理能力都明显提升。
回复格式:修复了之前版本存在的回复格式的问题,如异常 Markdown、中间截断、错误输出 boxed 等问题。
开启enable_thinking
有极小概率不会输出思考过程。
思考模式下仅支持流式输出。
通义千问-Plus/Turbo仅latest版本和0428快照属于Qwen3系列,支持开启思考模式。
商业版模型默认不开启思考模式,需要设置enable_thinking
为true
才会开启思考模式。
通义千问-Plus
模型名称 | 版本 | 上下文长度 | 最大输入 | 最大思维链长度 | 最大回复长度 | 输入成本 | 输出成本 | 免费额度 |
(Token数) | (每千Token) | |||||||
qwen-plus-latest 始终等同最新快照版 Batch调用半价 | 最新版 | 131,072 | 129,024 | 38,912 | 8,192 | 0.0008元 | 0.016元 | 各100万 Token 有效期:百炼开通后180天内 |
qwen-plus-2025-04-28 又称qwen-plus-0428 | 快照版 |
通义千问-Turbo
模型名称 | 版本 | 上下文长度 | 最大输入 | 最大思维链长度 | 最大回复长度 | 输入成本 | 输出成本 | 免费额度 |
(Token数) | (每千Token) | |||||||
qwen-turbo-latest 始终等同最新快照版 Batch调用半价 | 最新版 | 131,072 | 129,024 | 38,912 | 8,192 | 0.0003元 | 0.006元 | 各100万 Token 有效期:百炼开通后180天内 |
qwen-turbo-2025-04-28 又称qwen-plus-0428 | 快照版 |
模型名称 | 上下文长度 | 最大输入 | 最大思维链长度 | 最大回复长度 | 输入成本 | 输出成本 | 免费额度 |
(Token数) | (每千Token) | ||||||
qwen3-235b-a22b | 131,072 | 98,304 | 38,912 | 8,192 | 0.004元 | 0.04元 | 各100万 Token 有效期:百炼开通后180天内 |
qwen3-32b | 0.002元 | 0.02元 | |||||
qwen3-30b-a3b | 0.0015元 | 0.015元 | |||||
qwen3-14b | 0.001元 | 0.01元 | |||||
qwen3-8b | 0.0005元 | 0.005元 | |||||
qwen3-4b | 0.0003元 | 0.003元 | |||||
qwen3-1.7b | 32,768 | 28,672 | 与输入相加不超过30,720 | ||||
qwen3-0.6b |
开源版模型默认开启思考模式,如需关闭,请设置
enable_thinking
为false
。Qwen3 开源版模型在思考与非思考模式下都只可以通过流式输出方式调用。
基于 Qwen2.5 模型训练的 QwQ 推理模型,通过强化学习大幅度提升了模型推理能力。模型数学代码等核心指标(AIME 24/25、LiveCodeBench)以及部分通用指标(IFEval、LiveBench等)达到DeepSeek-R1 满血版水平。相较于开源版,商业版具有最新的能力和改进。
QwQ 不支持关闭思考过程。
思考模式下仅支持流式输出。
本文介绍的 QwQ 模型使用方法不适用于 qwq-32b-preview,如果您使用 qwq-32b-preview 模型,请参考文本生成。
模型名称 | 版本 | 上下文长度 | 最大输入 | 最大思维链长度 | 最大回复长度 | 输入成本 | 输出成本 | 免费额度 |
(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 | 快照版 |
开源版模型
模型名称 | 上下文长度 | 最大输入 | 最大思维链长度 | 最大回复长度 | 输入成本 | 输出成本 | 免费额度 |
(Token数) | (每千Token) | ||||||
qwq-32b | 131,072 | 98,304 | 32,768 | 8,192 | 0.002元 | 0.006元 | 100万 Token 有效期:百炼开通后180天内 |
DeepSeek-R1 模型是由深度求索(DeepSeek)公司推出的大语言模型。
deepseek-r1 模型包含 671B 参数,激活 37B,在后训练阶段大规模使用了强化学习技术,在仅有极少标注数据的情况下,极大提升了模型推理能力,尤其在数学、代码、自然语言推理等任务上。
DeepSeek-R1-Distill 系列模型是基于知识蒸馏技术,通过使用 DeepSeek-R1 生成的训练样本对 Qwen、Llama 等开源大模型进行微调训练后,所得到的增强型模型。
DeepSeek-R1 不支持关闭思考过程。
模型名称 | 上下文长度 | 最大输入 | 最大思维链长度 | 最大回复长度 | 输入成本 | 输出成本 | 免费额度 |
(Token数) | (每千Token) | ||||||
deepseek-r1 671B 满血版模型 | 65,792 | 57,344 | 32,768 | 8,192 | 0.004元 Batch调用:0.002元 | 0.016元 Batch调用:0.008元 | 各100万Token 有效期:百炼开通后180天内 |
deepseek-r1-distill-qwen-1.5b 基于 Qwen2.5-Math-1.5B | 32,768 | 32,768 | 16,384 | 16,384 | 限时免费体验 | ||
deepseek-r1-distill-qwen-7b 基于 Qwen2.5-Math-7B | 0.0005元 | 0.001元 | 各100万Token 有效期:百炼开通后180天内 | ||||
deepseek-r1-distill-qwen-14b 基于 Qwen2.5-14B | 0.001元 | 0.003元 | |||||
deepseek-r1-distill-qwen-32b 基于 Qwen2.5-32B | 0.002元 | 0.006元 | |||||
deepseek-r1-distill-llama-8b 基于 Llama-3.1-8B | 限时免费体验 | ||||||
deepseek-r1-distill-llama-70b 基于 Llama-3.3-70B |
并发限流请参考限流。
快速开始
API 使用前提:已获取API Key并完成配置API Key到环境变量。如果通过SDK调用,需要安装 OpenAI 或 DashScope SDK(DashScope Java SDK 版本需要不低于2.19.4)。
您可以运行以下代码,通过流式输出的方式调用深度思考模型。通过响应的reasoning_content
字段获取思考过程,content
字段获取回复内容。
示例代码
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",
)
messages = [{"role": "user", "content": "你是谁"}]
completion = client.chat.completions.create(
model="qwen-plus-2025-04-28", # 您可以按需更换为其它深度思考模型
messages=messages,
# enable_thinking 参数开启思考过程,QwQ 与 DeepSeek-R1 模型总会进行思考,不支持该参数
extra_body={"enable_thinking": True},
stream=True,
# stream_options={
# "include_usage": True
# },
)
reasoning_content = "" # 完整思考过程
answer_content = "" # 完整回复
is_answering = False # 是否进入回复阶段
print("\n" + "=" * 20 + "思考过程" + "=" * 20 + "\n")
for chunk in completion:
if not chunk.choices:
print("\nUsage:")
print(chunk.usage)
continue
delta = chunk.choices[0].delta
# 只收集思考内容
if hasattr(delta, "reasoning_content") and delta.reasoning_content is not None:
if not is_answering:
print(delta.reasoning_content, end="", flush=True)
reasoning_content += delta.reasoning_content
# 收到content,开始进行回复
if hasattr(delta, "content") and delta.content:
if not is_answering:
print("\n" + "=" * 20 + "完整回复" + "=" * 20 + "\n")
is_answering = True
print(delta.content, end="", flush=True)
answer_content += delta.content
返回结果
====================思考过程====================
好的,用户问“你是谁”,我需要给出一个准确且友好的回答。首先,我要确认自己的身份,即通义千问,由阿里巴巴集团旗下的通义实验室研发。接下来,应该说明我的主要功能,比如回答问题、创作文字、逻辑推理等。同时,要保持语气亲切,避免过于技术化,让用户感觉轻松。还要注意不要使用复杂术语,确保回答简洁明了。另外,可能需要加入一些互动元素,邀请用户提问,促进进一步交流。最后,检查是否有遗漏的重要信息,比如我的中文名称“通义千问”和英文名称“Qwen”,以及所属公司和实验室。确保回答全面且符合用户期望。
====================完整回复====================
你好!我是通义千问,是阿里巴巴集团旗下的通义实验室自主研发的超大规模语言模型。我可以回答问题、创作文字、进行逻辑推理、编程等,旨在为用户提供高质量的信息和服务。你可以叫我Qwen,或者直接叫我通义千问。有什么我可以帮你的吗?
示例代码
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 messages = [{ role: 'user', content: '你是谁' }];
const stream = await openai.chat.completions.create({
// 您可以按需更换为其它 Qwen3 模型、QwQ模型或DeepSeek-R1 模型
model: 'qwen-plus-2025-04-28',
messages,
stream: true,
// enable_thinking 参数开启思考过程,QwQ 与 DeepSeek-R1 模型总会进行思考,不支持该参数
enable_thinking: 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 !== undefined && delta.reasoning_content !== null) {
if (!isAnswering) {
process.stdout.write(delta.reasoning_content);
}
reasoningContent += delta.reasoning_content;
}
// 收到content,开始进行回复
if (delta.content !== undefined && 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();
返回结果
====================思考过程====================
好的,用户问“你是谁”,我需要回答我的身份。首先,我应该明确说明我是通义千问,由阿里云开发的超大规模语言模型。接下来,可以提到我的主要功能,比如回答问题、创作文字、逻辑推理等。还要强调我的多语言支持,包括中文和英文,这样用户知道我可以处理不同语言的请求。另外,可能需要解释一下我的应用场景,比如学习、工作和生活中的帮助。不过用户的问题比较直接,可能不需要太详细的信息,保持简洁明了。同时,要确保语气友好,邀请用户进一步提问。检查有没有遗漏的重要信息,比如我的版本或最新更新,但可能用户不需要那么详细。最后,确认回答准确无误,没有错误信息。
====================完整回复====================
我是通义千问,是阿里巴巴集团旗下的通义实验室自主研发的超大规模语言模型。我能够回答问题、创作文字、逻辑推理、编程等多种任务,支持中英文等多种语言。如果你有任何问题或需要帮,欢迎随时告诉我!
示例代码
Qwen3 模型需要设置enable_thinking
为true
来开启思考模式;enable_thinking
对 QwQ 与 DeepSeek-R1 模型无效。
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": "qwen-plus-2025-04-28",
"messages": [
{
"role": "user",
"content": "你是谁"
}
],
"stream": true,
"stream_options": {
"include_usage": true
},
"enable_thinking": true
}'
返回结果
data: {"choices":[{"delta":{"content":null,"role":"assistant","reasoning_content":""},"index":0,"logprobs":null,"finish_reason":null}],"object":"chat.completion.chunk","usage":null,"created":1745485391,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-e2edaf2c-8aaf-9e54-90e2-b21dd5045503"}
.....
data: {"choices":[{"finish_reason":"stop","delta":{"content":"","reasoning_content":null},"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745485391,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-e2edaf2c-8aaf-9e54-90e2-b21dd5045503"}
data: {"choices":[],"object":"chat.completion.chunk","usage":{"prompt_tokens":10,"completion_tokens":360,"total_tokens":370},"created":1745485391,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-e2edaf2c-8aaf-9e54-90e2-b21dd5045503"}
data: [DONE]
使用 DashScope 方式调用 Qwen3 模型时:
incremental_output
参数需要设置为true
,不支持设置为false
,仅支持增量流式返回;result_format
参数需要设置为"message"
。
使用 DashScope 方式调用 QwQ 模型时:
incremental_output
参数默认为true
,且不支持设置为false
,仅支持增量流式返回;result_format
参数默认为"message"
。
示例代码
import os
from dashscope import Generation
messages = [{"role": "user", "content": "你是谁?"}]
completion = Generation.call(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key = "sk-xxx",
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 可按需更换为其它深度思考模型
model="qwen-plus-2025-04-28",
messages=messages,
result_format="message", # Qwen3开源版模型只支持设定为"message";为了更好的体验,其它模型也推荐您优先设定为"message"
# 开启深度思考,该参数对 QwQ、DeepSeek-R1 模型无效
enable_thinking=True,
stream=True,
incremental_output=True, # Qwen3开源版模型只支持 true;为了更好的体验,其它模型也推荐您优先设定为 true
)
# 定义完整思考过程
reasoning_content = ""
# 定义完整回复
answer_content = ""
# 判断是否结束思考过程并开始回复
is_answering = False
print("=" * 20 + "思考过程" + "=" * 20)
for chunk in completion:
# 如果思考过程与回复皆为空,则忽略
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.19.4
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.Constants;
import io.reactivex.Flowable;
import java.lang.System;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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"))
// 此处使用qwen-plus-2025-04-28模型,可以按需替换为其它深度思考模型
.model("qwen-plus-2025-04-28")
// 开启深度思考,对 QwQ、DeepSeek-R1模型无效
.enableThinking(true)
.incrementalOutput(true) // Qwen3开源版模型只支持 true;为了更好的体验,其它模型也推荐您优先设定为 true
.resultFormat("message") // Qwen3开源版模型只支持设定为"message";为了更好的体验,其它模型也推荐您优先设定为"message"
.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);
}
}
返回结果
====================思考过程====================
好的,用户问“你是谁?”,我需要根据之前的设定来回答。首先,我的角色是通义千问,阿里巴巴集团旗下的超大规模语言模型。要保持口语化,简洁易懂。
用户可能刚接触我,或者想确认我的身份。应该先直接回答我是谁,然后简要说明我的功能和用途,比如回答问题、创作文字、编程等。还要提到支持多语言,这样用户知道我可以处理不同语言的需求。
另外,根据指导方针,要保持拟人性,所以语气要友好,可能用表情符号增加亲切感。同时,可能需要引导用户进一步提问或使用我的功能,比如问他们需要什么帮助。
需要注意不要使用复杂术语,避免冗长。检查是否有遗漏的关键点,比如多语言支持和具体能力。确保回答符合所有要求,包括口语化和简洁。
====================完整回复====================
你好!我是通义千问,阿里巴巴集团旗下的超大规模语言模型。我能够回答问题、创作文字,比如写故事、写公文、写邮件、写剧本、逻辑推理、编程等等,还能表达观点,玩游戏等。我熟练掌握多种语言,包括但不限于中文、英文、德语、法语、西班牙语等。有什么需要我帮忙的吗?
示例代码
Qwen3 模型需要设置enable_thinking
为true
来开启思考模式;enable_thinking
对 QwQ 与 DeepSeek-R1 模型无效。
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": "qwen-plus-2025-04-28",
"input":{
"messages":[
{
"role": "user",
"content": "你是谁?"
}
]
},
"parameters":{
"enable_thinking": true,
"incremental_output": true,
"result_format": "message"
}
}'
返回结果
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"}
多轮对话
大模型 API 默认不会记录您的历史对话信息。多轮对话功能可以让大模型“拥有记忆”,满足如追问、信息采集等需要连续交流的场景。深度思考模型会返回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 = "" # 定义完整回复
messages = []
conversation_idx = 1
while True:
is_answering = False # 判断是否结束思考过程并开始回复
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="qwen-plus-2025-04-28",
messages=messages,
# enable_thinking 参数开启思考过程,QwQ 与 DeepSeek-R1 模型总会进行思考,不支持该参数
extra_body={"enable_thinking": True},
stream=True,
# 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
# 将模型回复的content添加到上下文中
messages.append({"role": "assistant", "content": answer_content})
print("\n")
示例代码
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: 'qwen-plus-2025-04-28',
messages: messages,
// enable_thinking 参数开启思考过程,QwQ 与 DeepSeek-R1 模型总会进行思考,不支持该参数
enable_thinking: true,
stream: true,
// stream_options:{
// include_usage: 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": "qwen-plus-2025-04-28",
"messages": [
{
"role": "user",
"content": "你好"
},
{
"role": "assistant",
"content": "你好!很高兴见到你,有什么我可以帮忙的吗?"
},
{
"role": "user",
"content": "你是谁?"
}
],
"stream": true,
"stream_options": {
"include_usage": true
},
"enable_thinking": 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'),
# 此处以qwen-plus-2025-04-28为例,可按需更换为其它深度思考模型
model="qwen-plus-2025-04-28",
messages=messages,
# enable_thinking 参数开启思考过程,QwQ 与 DeepSeek-R1 模型总会进行思考,不支持该参数
enable_thinking=True,
result_format="message",
stream=True,
incremental_output=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
# 将模型回复的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.19.4
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"))
// 此处以 qwen-plus-2025-04-28 为例,可按需更换模型名称
.model("qwen-plus-2025-04-28")
.enableThinking(true)
.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": "qwen-plus-2025-04-28",
"input":{
"messages":[
{
"role": "user",
"content": "你好"
},
{
"role": "assistant",
"content": "你好!很高兴见到你,有什么我可以帮忙的吗?"
},
{
"role": "user",
"content": "你是谁?"
}
]
},
"parameters":{
"enable_thinking": true,
"incremental_output": true,
"result_format": "message"
}
}'
限制思考长度
深度思考模型有时会输出冗长的推理过程,需要较长时间才能进行回复内容的生成,且会消耗较多 Token。为了解决这一问题,您可以设置thinking_budget
参数来约束推理过程的最大长度。
thinking_budget
的设置不会影响大模型的思考过程。如果模型思考过程生成的 Token 数超过thinking_budget
,推理内容会进行截断并立刻开始生成最终回复内容。
该参数仅支持Qwen3 模型设定。
示例代码
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",
)
messages = [{"role": "user", "content": "你是谁"}]
completion = client.chat.completions.create(
model="qwen-plus-2025-04-28", # 您可以按需更换为其它深度思考模型
messages=messages,
# enable_thinking 参数开启思考过程,thinking_budget 参数设置最大推理过程 Token 数,两个参数对 QwQ 与 DeepSeek-R1 模型无效
extra_body={
"enable_thinking": True,
"thinking_budget": 50
},
stream=True,
# stream_options={
# "include_usage": True
# },
)
reasoning_content = "" # 完整思考过程
answer_content = "" # 完整回复
is_answering = False # 是否进入回复阶段
print("\n" + "=" * 20 + "思考过程" + "=" * 20 + "\n")
for chunk in completion:
if not chunk.choices:
print("\nUsage:")
print(chunk.usage)
continue
delta = chunk.choices[0].delta
# 只收集思考内容
if hasattr(delta, "reasoning_content") and delta.reasoning_content is not None:
if not is_answering:
print(delta.reasoning_content, end="", flush=True)
reasoning_content += delta.reasoning_content
# 收到content,开始进行回复
if hasattr(delta, "content") and delta.content:
if not is_answering:
print("\n" + "=" * 20 + "完整回复" + "=" * 20 + "\n")
is_answering = True
print(delta.content, end="", flush=True)
answer_content += delta.content
返回结果
====================思考过程====================
好的,用户问“你是谁”,我需要给出一个清晰且友好的回答。首先,应该明确自己的身份,即通义千问,由阿里巴巴集团旗下的通义实验室研发。接下来,要说明自己的主要功能,比如回答
====================完整回复====================
我是通义千问,是阿里巴巴集团旗下的通义实验室研发的超大规模语言模型。我能够回答问题、创作文字、逻辑推理、编程等,旨在为用户提供帮助和便利。有什么我可以帮您的吗?
示例代码
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 messages = [{ role: 'user', content: '你是谁' }];
const stream = await openai.chat.completions.create({
// 此处以qwen-plus-2025-04-28为例,可按需更换为其它深度思考模型
model: 'qwen-plus-2025-04-28',
messages,
stream: true,
// enable_thinking 参数开启思考过程,thinking_budget 参数设置最大推理过程 Token 数,两个参数对 QwQ 与 DeepSeek-R1 模型无效
enable_thinking: true,
thinking_budget: 50
});
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 !== undefined && delta.reasoning_content !== null) {
if (!isAnswering) {
process.stdout.write(delta.reasoning_content);
}
reasoningContent += delta.reasoning_content;
}
// 收到content,开始进行回复
if (delta.content !== undefined && 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();
返回结果
====================思考过程====================
好的,用户问“你是谁”,我需要给出一个清晰准确的回答。首先,我应该介绍自己的身份,即通义千问,由阿里巴巴集团旗下的通义实验室研发。接下来,要说明我的主要功能,比如回答问题
====================完整回复====================
我是通义千问,是阿里巴巴集团旗下的通义实验室自主研发的超大规模语言模型。我能够回答问题、创作文字、逻辑推理、编程等多种任务。如果你有任何问题或需要帮助,欢迎随时告诉我!
示例代码
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": "qwen-plus-2025-04-28",
"messages": [
{
"role": "user",
"content": "你是谁"
}
],
"stream": true,
"stream_options": {
"include_usage": true
},
"enable_thinking": true,
"thinking_budget": 50
}'
返回结果
data: {"choices":[{"delta":{"content":null,"role":"assistant","reasoning_content":""},"index":0,"logprobs":null,"finish_reason":null}],"object":"chat.completion.chunk","usage":null,"created":1745485391,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-e2edaf2c-8aaf-9e54-90e2-b21dd5045503"}
.....
data: {"choices":[{"finish_reason":"stop","delta":{"content":"","reasoning_content":null},"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745485391,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-e2edaf2c-8aaf-9e54-90e2-b21dd5045503"}
data: {"choices":[],"object":"chat.completion.chunk","usage":{"prompt_tokens":10,"completion_tokens":360,"total_tokens":370},"created":1745485391,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-e2edaf2c-8aaf-9e54-90e2-b21dd5045503"}
data: [DONE]
示例代码
import os
from dashscope import Generation
messages = [{"role": "user", "content": "你是谁?"}]
completion = Generation.call(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key = "sk-xxx",
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 可按需更换为其它深度思考模型
model="qwen-plus-2025-04-28",
messages=messages,
result_format="message",
# 开启深度思考,该参数对 QwQ、DeepSeek-R1 模型无效
enable_thinking=True,
# 设置最大推理过程 Token 数,该参数对 QwQ、DeepSeek-R1 模型无效
thinking_budget=50,
stream=True,
incremental_output=True,
)
# 定义完整思考过程
reasoning_content = ""
# 定义完整回复
answer_content = ""
# 判断是否结束思考过程并开始回复
is_answering = False
print("=" * 20 + "思考过程" + "=" * 20)
for chunk in completion:
# 如果思考过程与回复皆为空,则忽略
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.19.4
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.Constants;
import io.reactivex.Flowable;
import java.lang.System;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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"))
// 此处使用qwen-plus-2025-04-28模型,可以按需替换为其它深度思考模型
.model("qwen-plus-2025-04-28")
// 开启深度思考,对 QwQ、DeepSeek-R1模型无效
.enableThinking(true)
.thinkingBudget(50)
.incrementalOutput(true)
.resultFormat("message")
.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": "qwen-plus-2025-04-28",
"input":{
"messages":[
{
"role": "user",
"content": "你是谁?"
}
]
},
"parameters":{
"enable_thinking": true,
"thinking_budget": 50,
"incremental_output": true,
"result_format": "message"
}
}'
返回结果
id:1
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"好的","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":14,"output_tokens":3,"input_tokens":11,"output_tokens_details":{"reasoning_tokens":1}},"request_id":"2ce91085-3602-9c32-9c8b-fe3d583a2c38"}
id:2
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":",","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":15,"output_tokens":4,"input_tokens":11,"output_tokens_details":{"reasoning_tokens":2}},"request_id":"2ce91085-3602-9c32-9c8b-fe3d583a2c38"}
......
id:133
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"!","reasoning_content":"","role":"assistant"},"finish_reason":"null"}]},"usage":{"total_tokens":149,"output_tokens":138,"input_tokens":11,"output_tokens_details":{"reasoning_tokens":50}},"request_id":"2ce91085-3602-9c32-9c8b-fe3d583a2c38"}
id:134
event:result
:HTTP_STATUS/200
data:{"output":{"choices":[{"message":{"content":"","reasoning_content":"","role":"assistant"},"finish_reason":"stop"}]},"usage":{"total_tokens":149,"output_tokens":138,"input_tokens":11,"output_tokens_details":{"reasoning_tokens":50}},"request_id":"2ce91085-3602-9c32-9c8b-fe3d583a2c38"}
联网搜索
由于训练数据的时效性,大模型无法准确回答如股票价格、今日资讯等时效性问题。您可以通过设置enable_search
参数为true
以启用联网检索功能,使大模型可以基于实时检索数据进行回复。
仅 Qwen3 商业版模型、QwQ 商业版模型(除了qwq-plus-2025-03-05)支持联网搜索。
开启enable_search
后,模型会先判断是否需要使用联网搜索能力来回答您的问题:
需要联网搜索
当问题被模型判断需要使用联网搜索能力,模型会根据联网搜索的结果进行回复。
联网搜索功能当前免费,但搜索到的信息会增加 Token 消耗。
不需要联网搜索
模型本身已经可以回答如“你是谁”、“一年有多少天”等简单或常识性的问题。此时模型不会去联网搜索,而是直接进行回答。
如果您希望强制开启联网搜索功能,请参见下文的
forced_search
参数。
在设置enable_search
参数为true
后,您可以通过search_options
参数来配置联网搜索策略,包括以下方面:
通过forced_search
配置,可选值:
true
强制开启。
false
(默认值)不强制开启。
该策略仅支持 DashScope 方式。通过enable_source
配置,可选值:
true
返回数据中包含搜索来源的信息。搜索来源信息通过
search_info
参数返回。false
(默认值)返回数据中不包含搜索来源的信息。
该策略仅支持 DashScope 方式。
就像在写论文时在右上角用[i] 来标注引用的文献,角标标注可以在大模型的回复内容中标注引用来源。如果返回数据包含搜索来源的信息(enable_source
为true
),您可以通过enable_citation
来配置是否开启角标标注功能。可选值:
true
开启角标标注。
角标标注的样式可以通过下方的
citation_format
参数设置。false
(默认值)不开启角标标注。
在开启角标标注功能后,您可以通过citation_format
配置角标样式。可选值:
"[<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'),
# 此处以qwen-plus-2025-04-28为例,可按需更换为支持联网搜索的模型
model="qwen-plus-2025-04-28",
messages=messages,
# 开启深度思考的参数,对 QwQ 模型无效
enable_thinking = True,
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条互联网信息
},
stream=True,
incremental_output=True,
result_format="message",
)
# 定义完整思考过程
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》票房破119亿元 2025累计票房破200亿!](https://www.1905.com/news/20250217/1714723.shtml)
[2]: [《哪吒2》票房将达215亿,超《阿凡达》成全球第一,5大理由支撑](https://www.360kuai.com/pc/9630dbf8c5a1770de?cota=3&kuai_so=1&sign=360_e39369d1)
[3]: [《哪吒2》票房破135亿:2025年中国电影市场的梦幻开局](https://www.sohu.com/a/862924685_122077416?scm=10001.325_13-109000.0.0.5_32)
[4]: [哪吒2票房突破120亿元](https://baijiahao.baidu.com/s?id=1824275513693903228)
[5]: [哪吒2票房突破153亿](https://m.gmw.cn/2025-03/23/content_1303998589.htm)
[6]: [哪吒2总票房破131亿](https://m.gmw.cn/2025-02/22/content_1303977481.htm)
[7]: [2025年娱乐新趋势哪吒2票房破150亿!国产动画如何征服全球市场?](https://m.sohu.com/a/874897462_122173903/?scm=10001.334_13-101000-0_922.0-0.0.a2_5X162X1746)
[8]: [哪吒2全球票房破156亿](https://m.gmw.cn/2025-04/09/content_1304011206.htm)
[9]: [《哪吒2》票房彻底疯了 ](https://m.china-xian.com/question/202503/5sy28p2jld.htm)
====================思考过程====================
好的,我现在需要回答用户关于《哪吒2》票房的问题。首先,我要查看提供的知识库内容,找到相关的票房数据。
看到有多个引用提到《哪吒2》的票房情况。比如,ref_1提到票房破119亿元,但后面还有其他ref提到更高的数字。ref_3说票房破135亿,ref_5提到全球票房突破153亿,ref_8则提到全球票房破156亿。另外,ref_7提到票房破150亿,而ref_5和ref_8的数据似乎更具体,分别达到153亿和156亿。还有ref_1提到累计票房即将冲击120亿元,但后续的ref_3、ref_5、ref_8都有更高的数据。
需要确认这些数据的时间点。例如,ref_1的日期是2025年第6周,也就是2月10日到16日,此时票房是119亿。而ref_3提到的是截至2025年2月24日,票房破135亿。之后ref_5在某个时间点提到153亿,ref_8提到156亿。可能这些数据是逐步更新的,所以最新的应该是ref_8的156亿。不过需要检查是否有更近的引用。
另外,ref_7提到的是150亿,而ref_5和ref_8的数据更高。可能不同的ref有不同的统计时间和范围,比如是否包含海外票房。例如,ref_5提到全球票房(含预售及海外)突破153亿,而ref_8也是全球票房破156亿。因此,应该综合这些信息,指出不同时间点的票房成绩,并说明最新数据是156亿。
还需要注意是否有矛盾的地方。例如,ref_1提到累计票房突破200亿,但其他ref的数字没有达到这个数值,可能ref_1中的2025全年电影票房累计突破200亿是指整个市场的总票房,而不是《哪吒2》单独的票房。需要仔细区分。
总结一下,用户的问题是关于《哪吒2》的票房,需要列出不同时间点的票房数据,并指出最高纪录。同时要引用对应的ref编号,确保准确性。
====================完整回复====================
根据现有资料,《哪吒之魔童闹海》(《哪吒2》)的票房表现如下:
1. **国内票房**:截至2025年2月24日,该片国内票房已突破135亿元[ref_3],随后持续增长,累计票房接近150亿元[ref_7]。
2. **全球票房**:
- 截至2025年4月,影片全球票房(含预售及海外)已突破**156亿元**[ref_8]。
- 此前,全球票房曾突破**153亿元**[ref_5],并位居全球影史票房榜前五[ref_8]。
3. **市场地位**:
- 《哪吒2》成为首部进入全球票房前十的非好莱坞动画电影,且在欧洲37国同步上映,创下华语影片发行新纪录[ref_7]。
- 影片还以150亿元票房成绩超越《阿凡达》(2009年第一部),一度登上全球票房榜首[ref_2]。
4. **其他数据**:
- 2025年第6周(2月10日-16日),周票房达38.4亿元,累计票房接近120亿元[ref_1]。
- 影片在海外市场表现亮眼,例如在英国超级点映票房达100万美元,创造国际动画电影点映新纪录[ref_1]。
综上,《哪吒2》的票房成绩体现了其在国内及全球市场的巨大影响力,最终全球票房有望进一步攀升。
示例代码
// dashscope SDK的版本 >= 2.19.4
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"))
.model("qwen-plus-2025-04-28")
.enableThinking(true)
.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": "qwen-plus-2025-04-28",
"input":{
"messages":[
{
"role": "user",
"content": "哪吒2的票房"
}
]
},
"parameters":{
"enable_thinking": true,
"incremental_output": true,
"result_format": "message",
"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"}
示例代码
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(
# 此处以qwen-plus-2025-04-28为例,可更换为其它支持联网搜索的深度思考模型
model="qwen-plus-2025-04-28",
messages=[{"role": "user", "content": "哪吒2的票房"}],
extra_body={
# 开启深度思考的参数,对 QwQ 模型无效
"enable_thinking": True,
"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的票房”,所以我要找到最新的票房数字。根据知识库中的信息,最近的数据是来自不同时间点的多个记录。例如,有提到截至2025年4月17日,票房破155亿,而另一处提到全球票房破156亿。还有3月8日的数据是148亿,3月24日左右是153亿,以及另一条提到155亿和156亿。看起来最新的应该是4月17日的155亿和之后的156亿。不过需要确认时间顺序。
注意到知识库中有一条提到“哪吒2全球票房破156亿”的条目,其中包含4月16日神舟二十号的消息,可能时间接近当前系统时间2025年4月27日。因此,可能156亿是最近的数据。但还有另一条提到“破155亿”并提到4月17日联合国教科文组织的消息,可能两者都是同一时间段的数据,可能存在不同来源的统计差异。
另外,用户提供的系统时间是4月27日,而知识库中最新的数据是到4月17日左右,之后可能没有更新的数据。因此,我需要综合所有信息,给出最接近当前时间的票房数字。可能需要指出不同来源的数字,并说明当前的最新情况,比如提到156亿可能更接近,但需要确认是否有更高数据。
此外,知识库中还提到《哪吒2》在全球影史票房榜的位置,比如第5名或第6名,这可能帮助确认票房数值是否准确。例如,156亿应该位于全球前五的位置,而之前的153亿是第5名。因此,可能最新的数据是156亿,并且仍在增长,接近或超过某些里程碑,比如超过《阿凡达》的票房(假设《阿凡达》的票房约为28亿美元,但需要换算人民币)。
最后,我需要整理这些信息,给出一个清晰的回答,说明当前票房的最新数据,并引用知识库中的不同来源,同时注意可能的更新情况。
====================完整回复====================
根据提供的知识库信息,截至2025年4月17日,《哪吒之魔童闹海》(《哪吒2》)的全球票房已突破**155亿元人民币**,并随后进一步攀升至**156亿元**(部分数据来源显示)。以下是关键信息整理:
---
### **票房里程碑**
1. **156亿元(全球票房,含预售及海外)**
- 根据4月17日左右的最新数据,《哪吒2》全球票房突破156亿元,暂列**全球影史票房榜前5名**(部分统计显示已超越《复仇者联盟4》等影片)。
- 在欧洲地区,英国点映票房达100万美元,创国际动画电影点映新纪录,进一步推动海外票房增长。
2. **国内票房表现**
- 截至2025年2月24日,国内票房已破135亿元,刷新国产动画电影票房纪录。
- 2025年第6周(2月10-16日),单周票房达38.4亿元,持续蝉联周冠军,累计票房迅速向120亿元迈进。
3. **国际影响力**
- 在欧洲37国同步上映,柏林电影节评委称赞其为“动画界的《寄生虫》”,亚洲市场份额占比超79%(中国58%+东南亚21%)。
- 海外发行策略成功,英国、东南亚等地票房表现强劲,助力全球票房突破150亿元大关。
---
### **票房分析与行业影响**
- **技术与内容创新**:采用AI辅助的VRAI技术,缩短70%渲染时间,同时以东方哲学和“逆天命”主题引发全球共鸣,豆瓣评分8.5分,成人观众占比达87%。
- **产业升级**:带动北京200多家视效公司协同发展,形成全产业链闭环,推动国产动画从“代工”向“文化输出”转型。
- **目标与挑战**:业界预测其最终票房可能达到**215亿元**,有望超越《阿凡达》(约28亿美元,按汇率换算约合人民币190亿元),成为全球影史票房冠军。
---
### **当前进展**
- 截至知识库最新数据(4月17日),票房已达**156亿元**,并仍在增长中。
- 若持续当前势头,或将在未来几周内冲击**160亿元**,进一步巩固其全球票房地位。
如需更实时数据,建议参考权威票房平台(如猫眼、灯塔专业版)或最新新闻报道。
====================Usage====================
CompletionUsage(completion_tokens=1088, prompt_tokens=4355, total_tokens=5443, 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({
// 此处以qwen-plus-2025-04-28为例,可更换为其它支持联网搜索的深度思考模型
model: 'qwen-plus-2025-04-28',
messages: [{ role: 'user', content: '哪吒2的票房' }],
// 开启深度思考的参数,对 QwQ 模型无效
enable_thinking: true,
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》的票房情况。我需要先看看知识库里的相关信息。根据提供的资料,《哪吒之魔童闹海》的全球票房已经突破156亿,暂列全球影史票房榜前五。还有提到超过150亿,创亚洲纪录,以及日本上映后全球票房超155.16亿。这些数据可能有时间上的差异,比如不同日期的统计结果。
需要确认用户的问题是否有特定的时间点,但用户没有说明,所以应该给出最新的数据。知识库里最新的信息是“全球票房破156亿”和“全球票房超155.16亿”,可能前者是更近的统计数据。另外,要注意到不同的来源可能有不同的数字,比如有的说156亿,有的说155.16亿,这可能是因为统计时间和方式不同。
还需要注意,用户可能想知道当前的票房,而系统时间是2025年4月27日,但知识库中的信息可能截止到2023年或更早,因为《哪吒2》在2025年可能已经下映了。不过根据知识库内容,电影在国内持续上映至4月30日,所以可能在2025年4月27日还在上映中,因此票房可能还在增长。
需要综合所有信息,给出一个准确的回答,同时指出数据可能有变动,并建议参考权威渠道获取最新数据。另外,要提到票房排名情况,比如全球第五,以及亚洲纪录等信息。
====================完整回复====================
根据现有信息,《哪吒之魔童闹海》(《哪吒2》)的全球票房已突破**156亿元人民币**,暂列全球影史票房榜前五。该片在海外市场的表现也十分亮眼,截至相关报道发布时,其全球票房已超过**155.16亿元**,并创下了亚洲电影的票房新纪录。
需要注意的是:
1. **数据时间差异**:不同报道中的票房数字(如150亿、155亿、156亿)可能因统计时间或渠道不同而存在细微差异。
2. **上映周期**:该片在中国大陆的上映时间曾两次延期,最终持续至**2025年4月30日**,因此实际票房可能仍在动态变化中。
3. **票房计算方式**:电影票房通常指影片上映后的放映收益总和,并非直接等同于观众人次。
如需最新数据,建议参考权威影视票房统计平台或官方公告。
示例代码
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": "qwen-plus-2025-04-28",
"messages": [
{
"role": "user",
"content": "哪吒2的票房"
}
],
"enable_thinking": true,
"enable_search": true,
"search_options": {
"forced_search": true
},
"stream": true,
"stream_options": {
"include_usage": true
}
}'
Function Calling(工具调用)
虽然深度思考模型拥有强大的推理能力,但无法与外部世界进行交互。Function Calling 通过引入外部工具,可以帮助深度思考模型实现天气查询、数据库查询、发送邮件等功能。
DeepSeek-R1 系列模型暂不支持 Function Calling。
Qwen3、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"] # 必填参数
}
}
}
]
messages = [{"role": "user", "content": input("请输入问题:")}]
completion = client.chat.completions.create(
# 此处以qwen-plus-2025-04-28为例,可更换为其它深度思考模型
model="qwen-plus-2025-04-28",
messages=messages,
extra_body={
# 开启深度思考,该参数对 QwQ 模型无效
"enable_thinking": True
},
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,类型字符串。每个城市需要单独查询,因为函数一次只能查一个地点。因此,我需要为每个直辖市调用一次这个函数。
然后,我需要考虑如何生成正确的工具调用。每个调用应该包含城市名称作为参数。比如,第一个调用是北京,第二个是上海,依此类推。确保参数名称是location,值是正确的城市名。
另外,用户可能希望得到每个城市的天气信息,所以需要确保每个函数调用都正确无误。可能需要连续调用四次,每次对应一个城市。不过,根据工具的使用规则,可能需要分多次处理,或者一次生成多个调用。但根据示例,可能每次只调用一个函数,所以可能需要逐步进行。
最后,确认是否有其他需要考虑的因素,比如参数是否正确,城市名称是否准确,以及是否需要处理可能的错误情况,比如城市不存在或API不可用。但目前看来,四个直辖市都是明确的,应该没问题。
====================回复内容====================
===================工具调用信息===================
[{'id': 'call_767af2834c12488a8fe6e3', 'name': 'get_current_weather', 'arguments': '{"location": "北京市"}'}, {'id': 'call_2cb05a349c89437a947ada', 'name': 'get_current_weather', 'arguments': '{"location": "上海市"}'}, {'id': 'call_988dd180b2ca4b0a864ea7', 'name': 'get_current_weather', 'arguments': '{"location": "天津市"}'}, {'id': 'call_4e98c57ea96a40dba26d12', '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({
// 此处以qwen-plus-2025-04-28为例,可更换为其它深度思考模型
model: "qwen-plus-2025-04-28",
messages,
// 开启深度思考,该参数对 QwQ 模型无效
enable_thinking: true,
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": "qwen-plus-2025-04-28",
"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"]
}
}
}
],
"enable_thinking": true,
"stream": true
}'
示例代码
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(
# 此处以qwen-plus-2025-04-28为例,可更换为其它深度思考模型
model="qwen-plus-2025-04-28",
messages=messages,
enable_thinking=True,
tools=tools,
parallel_tool_calls=True,
stream=True,
incremental_output=True,
result_format="message"
)
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": "重庆市"}}'}]
示例代码
// dashscope SDK的版本 >= 2.19.4
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("qwen-plus-2025-04-28")
.enableThinking(true)
.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 -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": "qwen-plus-2025-04-28",
"input":{
"messages":[
{
"role": "user",
"content": "杭州天气"
}
]
},
"parameters": {
"result_format": "message",
"enable_thinking": true,
"incremental_output": true,
"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"]
}
}
}]
}
}'
在得到 Function Calling 输出的工具信息后,您可以参考运行工具函数与大模型总结工具函数输出,使大模型能够根据工具运行的结果进行回答。
开启/关闭思考模式
除了通过enable_thinking
参数设置,Qwen3 模型还提供了通过提示词动态控制思考模式的便捷方法。当enable_thinking
为true
时,您可以在提示词中加上/no_think
,使 Qwen3 模型在之后的回复关闭思考模式。若您需要在多轮对话重新开启思考模式,只需在最新输入的提示词加上/think
。
在多轮对话中,模型会遵循最近的/think
或/no_think
指令。
如果 Qwen3 模型没有输出思考过程,输出 Token 将按非思考模式的价格计费。
示例代码
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",
)
# 在 prompt 加上/no_think,即使enable_thinking设为true也会关闭思考模式。
messages = [{"role": "user", "content": "你是谁/no_think"}]
completion = client.chat.completions.create(
model="qwen-plus-2025-04-28", # 您可以按需更换为其它Qwen3 模型
messages=messages,
# enable_thinking 参数开启思考过程,QwQ 与 DeepSeek-R1 模型总会进行思考,不支持该参数
extra_body={"enable_thinking": True},
stream=True,
# stream_options={
# "include_usage": True
# },
)
reasoning_content = "" # 完整思考过程
answer_content = "" # 完整回复
is_answering = False # 是否进入回复阶段
print("\n" + "=" * 20 + "思考过程" + "=" * 20 + "\n")
for chunk in completion:
if not chunk.choices:
print("\nUsage:")
print(chunk.usage)
continue
delta = chunk.choices[0].delta
# 只收集思考内容
if hasattr(delta, "reasoning_content") and delta.reasoning_content is not None:
if not is_answering:
print(delta.reasoning_content, end="", flush=True)
reasoning_content += delta.reasoning_content
# 收到content,开始进行回复
if hasattr(delta, "content") and delta.content:
if not is_answering:
print("\n" + "=" * 20 + "完整回复" + "=" * 20 + "\n")
is_answering = True
print(delta.content, end="", flush=True)
answer_content += delta.content
返回结果
====================思考过程====================
====================完整回复====================
我是通义千问,阿里巴巴集团旗下的通义实验室自主研发的超大规模语言模型。我可以帮助你回答问题、创作文字、进行逻辑推理、编程等任务。如果你有任何问题或需要帮助,欢迎随时向我提问!
示例代码
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 {
// 在 prompt 加上/no_think,即使enable_thinking设为true也会关闭思考模式。
const messages = [{ role: 'user', content: '你是谁/no_think' }];
const stream = await openai.chat.completions.create({
// 您可以按需更换为其它Qwen3 模型
model: 'qwen-plus-2025-04-28',
messages,
stream: true,
// enable_thinking 参数开启思考过程,QwQ 与 DeepSeek-R1 模型总会进行思考,不支持该参数
enable_thinking: 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 !== undefined && delta.reasoning_content !== null) {
if (!isAnswering) {
process.stdout.write(delta.reasoning_content);
}
reasoningContent += delta.reasoning_content;
}
// 收到content,开始进行回复
if (delta.content !== undefined && 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();
返回结果
====================思考过程====================
====================完整回复====================
我是通义千问,阿里巴巴集团旗下的通义实验室自主研发的超大规模语言模型。我可以帮助你回答问题、创作文字,比如写故事、写公文、写邮件、写剧本、逻辑推理、编程等等,还能表达观点,玩游戏等。如果你有任何问题或需要帮助,欢迎随时向我提问!
示例代码
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": "qwen-plus-2025-04-28",
"messages": [
{
"role": "user",
"content": "你是谁/no_think"
}
],
"stream": true,
"stream_options": {
"include_usage": true
},
"enable_thinking": true
}'
返回结果
data: {"choices":[{"delta":{"content":"","role":"assistant"},"index":0,"logprobs":null,"finish_reason":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"finish_reason":null,"delta":{"content":"我是"},"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"通","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"义千问","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":",阿里巴巴","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"集团旗下的通","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"义实验室自主研发","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"的超","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"大规模语言模型","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"。我可以","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"帮助","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"你回答问题","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"、创作","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"文字","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":",","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"比如","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"写故事、","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"写公","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"文、写","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"邮件","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"、","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"写剧本","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"、","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"逻辑","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"推理、编程","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"等等","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":",","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"还能","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"表达","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"观点","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":",","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"玩游戏","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"等","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"。如果你有任何","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"问题或","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"需要帮助,","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"欢迎随时告诉我","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"delta":{"content":"!","reasoning_content":null},"finish_reason":null,"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[{"finish_reason":"stop","delta":{"content":"","reasoning_content":null},"index":0,"logprobs":null}],"object":"chat.completion.chunk","usage":null,"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: {"choices":[],"object":"chat.completion.chunk","usage":{"prompt_tokens":12,"completion_tokens":70,"total_tokens":82,"completion_tokens_details":{"reasoning_tokens":0}},"created":1745899582,"system_fingerprint":null,"model":"qwen-plus-2025-04-28","id":"chatcmpl-d57a6697-b319-9d92-837f-f9dada8557c5"}
data: [DONE]
示例代码
import os
from dashscope import Generation
# 在 prompt 加上/no_think,即使enable_thinking设为true也会关闭思考模式。
messages = [{"role": "user", "content": "你是谁? /no_think"}]
completion = Generation.call(
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key = "sk-xxx",
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 可按需更换为其它Qwen3模型
model="qwen-plus-2025-04-28",
messages=messages,
result_format="message",
enable_thinking=True,
stream=True,
incremental_output=True,
)
# 定义完整思考过程
reasoning_content = ""
# 定义完整回复
answer_content = ""
# 判断是否结束思考过程并开始回复
is_answering = False
print("=" * 20 + "思考过程" + "=" * 20)
for chunk in completion:
# 如果思考过程与回复皆为空,则忽略
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.19.4
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.Constants;
import io.reactivex.Flowable;
import java.lang.System;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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"))
// 此处使用qwen-plus-2025-04-28模型,可以按需替换为其它Qwen3模型
.model("qwen-plus-2025-04-28")
.enableThinking(true)
.incrementalOutput(true)
.resultFormat("message")
.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();
// 在 prompt 加上/no_think,即使enable_thinking设为true也会关闭思考模式。
Message userMsg = Message.builder().role(Role.USER.getValue()).content("你是谁?/no_think").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": "qwen-plus-2025-04-28",
"input":{
"messages":[
{
"role": "user",
"content": "你是谁?/no_think"
}
]
},
"parameters":{
"enable_thinking": true,
"incremental_output": true,
"result_format": "message"
}
}'
返回结果
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"}
非流式输出
注意事项
为了达到模型的最佳推理效果,不建议设置 System Message。
常见问题
API 参考
深度思考模型的输入与输出参数请参见通义千问。
错误码
如果执行报错,请参见错误信息进行解决。
- 本页导读 (1)
- 深度思考模型介绍
- 快速开始
- 多轮对话
- 限制思考长度
- 联网搜索
- Function Calling(工具调用)
- 开启/关闭思考模式
- 非流式输出
- 注意事项
- 常见问题
- Q:怎么关闭思考过程?
- Q:免费额度用完后如何购买 Token?
- Q:如何接入 Chatbox、Cherry Studio、Cline或 Dify?
- Q:可以上传图片或文档进行提问吗?
- Q:如何在使用 LangChain 时输出思考过程?
- Q:如何查看Token消耗量及调用次数?
- API 参考
- 错误码