【自然语言处理与大模型】开关推理模型的思考功能
·
使用推理模型时如果每次都显示思考过程,会导致响应时间变长。有没有方法可以直接关闭这个思考功能呢?在Qwen3和MiniCPM4.1测试可行。
方法一:直接在提示词的最后带上/no_think
方法二:extra_body参数中带上"chat_template_kwargs": {"enable_thinking": True}
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8000/v1",
api_key="EMPTY"
)
# 允许用户动态控制模型的行为。具体来说,您可以在用户提示或系统消息中添加 /think 和 /no_think 来逐回合切换模型的思考模式。
response = client.chat.completions.create(
model="/root/autodl-tmp/llm_models/MiniCPM4.1-8B",
messages=[
{"role": "user", "content": "为什么有人说1+1=3呢?"}, # 软思考 /think /no_think
],
extra_body={
"add_special_tokens": True,
"chat_template_kwargs": {"enable_thinking": True}, # 硬思考 enable_thinking
},
)
print(response)
更多推荐


所有评论(0)