微信扫码
添加专属顾问
我要投稿
Ollama新版带来AI思维链控制功能,让用户自由切换模型的思考模式,打造更灵活的交互体验。核心内容: 1. 思考模式开关功能详解(CLI/REST API双端支持) 2. 应用场景演示:动画呈现思考过程/NPC气泡对话 3. 支持模型清单与典型使用命令示例
~~关注我,一起成长~~
Ollama 现在可以启用或禁用思考功能。这使用户可以灵活地针对不同的应用程序和用例选择模型的思考行为。
当开启思考时,输出会将模型的思考和模型的输出分离;当关闭思考时,模型不会思考,直接输出内容。
支持思考的模型:
CLI中缺省是启用思考模式的,如:
ollama run deepseek-r1
如果要禁用思考模式,可以在互动环境时输入***/set nothink***
在互动环节输入:/set think以启用思考模式
也可以直接在执行命令的时候设置思考模式
ollama run deepseek-r1 --think # 开启思考模式
ollama run deepseek-r1 --think=false #禁用思考模式
对于直接使用脚本进行推理时,可以使用--hidethinking,这会启用思维模型但只想返回最终的结果,而不包括思考过程。
ollama run deepseek-r1:8b --hidethinking "9.9与9.11哪一个更大?"
Ollama 的生成 API(/api/generate)和聊天 API(/api/chat)均已更新,以支持思考。
新增了一个think参数,可以设置为true或false用于启用模型的思考过程。当该think参数设置为 true 时,输出将把模型的思考与模型的输出分离。这可以帮助用户打造全新的应用体验,例如通过图形界面以动画形式呈现思考过程,或者让游戏中的 NPC 在输出前显示思考气泡。当该think参数设置为 false 时,模型将不会思考,直接输出内容。
使用 Ollama 聊天 API 并启用思考的示例
curl http://localhost:11434/api/chat -d '{
"model": "deepseek-r1",
"messages": [
{
"role": "user",
"content": "how many r in the word strawberry?"
}
],
"think": true,
"stream": false
}'
输出
{"model":"deepseek-r1",
"created_at":"2025-05-29T09:35:56.836222Z",
"message":
{"role": "assistant",
"content": "The word \"strawberry\" contains **three** instances of the letter 'R' ..."
"thinking": "First, the question is: \"how many r in the word strawberry?\" I need to count the number of times the letter 'r' appears in the word \"strawberry\". Let me write down the word:...",
"done_reason":"stop",
"done":true,
"total_duration":47975065417,
"load_duration":29758167,
"prompt_eval_count":10,
"prompt_eval_duration":174191542,
"eval_count":2514,
"eval_duration":47770692833
}
}
请更新到最新的 Ollama Python 库。
pip install ollama
from ollama import chat
messages = [
{
'role': 'user',
'content': 'What is 10 + 23?',
},
]
response = chat('deepseek-r1', messages=messages, think=True)
print('Thinking:\n========\n\n' + response.message.thinking)
print('\nResponse:\n========\n\n' + response.message.content)
请更新到最新的 Ollama JavaScript 库。
npm i ollama
import ollama from 'ollama'
async function main() {
const response = await ollama.chat({
model: 'deepseek-r1',
messages: [
{
role: 'user',
content: 'What is 10 + 23',
},
],
stream: false,
think: true,
})
console.log('Thinking:\n========\n\n' + response.message.thinking)
console.log('\nResponse:\n========\n\n' + response.message.content + '\n\n')
}
main()
思考式流式响应示例
import ollama from 'ollama'
async function main() {
const response = await ollama.chat({
model: 'deepseek-r1',
messages: [
{
role: 'user',
content: 'What is 10 + 23',
},
],
stream: true,
think: true,
})
let startedThinking = false
let finishedThinking = false
for await (const chunk of response) {
if (chunk.message.thinking && !startedThinking) {
startedThinking = true
process.stdout.write('Thinking:\n========\n\n')
} else if (chunk.message.content && startedThinking && !finishedThinking) {
finishedThinking = true
process.stdout.write('\n\nResponse:\n========\n\n')
}
if (chunk.message.thinking) {
process.stdout.write(chunk.message.thinking)
} else if (chunk.message.content) {
process.stdout.write(chunk.message.content)
}
}
}
main()
暂不支持
------正文结束------
长按图片,识别二维码,关注我!
喜欢的话右下角点个【赞👍🏻】和【在看】吧
你的每个【点赞】和【在看】
我都当做鼓励❤️
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费场景POC验证,效果验证后签署服务协议。零风险落地应用大模型,已交付160+中大型企业
2025-07-05
炸裂!AI“读心术”被破解,我们终于能亲眼看见它的思考过程了!
2025-07-05
智谱新出的模型,做PPT太会整活了
2025-07-05
微软裁员9000人!给员工整不会了:用不用AI都要被裁?
2025-07-04
Karpathy:我不是要造新词,是「上下文工程」对 Agent 来说太重要了
2025-07-04
AI Agent的核心:Context Engineering(上下文工程)
2025-07-04
AI Agent与AI Workflow:“对决”与“共生”,未来属于“混血儿”!
2025-07-04
破局AI内卷:揭秘驱动10倍效能的AI工作流三大核心技术支柱
2025-07-04
深度揭秘:下一代AI生产力,颠覆你的工作与认知?99%的人还没看懂!
2025-05-29
2025-04-11
2025-04-12
2025-04-29
2025-04-12
2025-04-29
2025-05-07
2025-05-23
2025-05-07
2025-04-17