返回顶部
热门问答 更多热门问答
技术文章 更多技术文章

Ollama新版功能:AI思维链控制

[复制链接]
链载Ai 显示全部楼层 发表于 昨天 18:52 |阅读模式 打印 上一主题 下一主题


ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;display: table;padding: 0.3em 1em;color: rgb(255, 255, 255);background: rgb(0, 152, 116);border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 6px;">1、概述

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;font-size: 17px;text-indent: 2em;letter-spacing: 0.1em;color: rgb(63, 63, 63);">Ollama 现在可以启用或禁用思考功能。这使用户可以灵活地针对不同的应用程序和用例选择模型的思考行为。

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;font-size: 17px;text-indent: 2em;letter-spacing: 0.1em;color: rgb(63, 63, 63);">当开启思考时,输出会将模型的思考和模型的输出分离;当关闭思考时,模型不会思考,直接输出内容。

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;font-size: 17px;text-indent: 2em;letter-spacing: 0.1em;color: rgb(63, 63, 63);">支持思考的模型:

    ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;font-size: 17px;color: rgb(63, 63, 63);" class="list-paddingleft-1">
  • ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;font-size: 17px;text-indent: -1em;display: block;margin: 0.5em 8px;color: rgb(63, 63, 63);">
    • DeepSeek R1
  • ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;font-size: 17px;text-indent: -1em;display: block;margin: 0.5em 8px;color: rgb(63, 63, 63);">
    • Qwen3

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;display: table;padding: 0.3em 1em;color: rgb(255, 255, 255);background: rgb(0, 152, 116);border-radius: 8px;box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 6px;">2、CLI命令行中使用

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;font-size: 17px;text-indent: 2em;letter-spacing: 0.1em;color: rgb(63, 63, 63);">CLI中缺省是启用思考模式的,如:

ollamarundeepseek-r1

ingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif;font-size: 17px;text-indent: 2em;letter-spacing: 0.1em;color: rgb(63, 63, 63);">如果要禁用思考模式,可以在互动环境时输入***/set nothink***

在互动环节输入:/set think以启用思考模式

也可以直接在执行命令的时候设置思考模式

ollamarundeepseek-r1--think#开启思考模式ollamarundeepseek-r1--think=false#禁用思考模式

对于直接使用脚本进行推理时,可以使用--hidethinking,这会启用思维模型但只想返回最终的结果,而不包括思考过程。

ollamarundeepseek-r1:8b--hidethinking"9.9与9.11哪一个更大?"

3、Rest API

Ollama 的生成 API(/api/generate)和聊天 API(/api/chat)均已更新,以支持思考。

新增了一个think参数,可以设置为true或false用于启用模型的思考过程。当该think参数设置为 true 时,输出将把模型的思考与模型的输出分离。这可以帮助用户打造全新的应用体验,例如通过图形界面以动画形式呈现思考过程,或者让游戏中的 NPC 在输出前显示思考气泡。当该think参数设置为 false 时,模型将不会思考,直接输出内容。

使用 Ollama 聊天 API 并启用思考的示例

curlhttp://localhost:11434/api/chat-d'{"model":"deepseek-r1","messages":[{"role":"user","content":"howmanyrinthewordstrawberry?"}],"think":true,"stream":false}'

输出

{"model":"deepseek-r1","created_at":"2025-05-29T09:35:56.836222Z","message":{"role":"assistant","content":"Theword\"strawberry\"contains**three**instancesoftheletter'R'...""thinking":"First,thequestionis:\"howmanyrinthewordstrawberry?\"Ineedtocountthenumberoftimestheletter'r'appearsintheword\"strawberry\".Letmewritedowntheword:...","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}}

4、Python 库

请更新到最新的 Ollama Python 库。

pipinstallollama
fromollamaimportchatmessages=[{'role':'user','content':'Whatis10+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)

5、JavaScript 库

请更新到最新的 Ollama JavaScript 库。

npmiollama
importollamafrom'ollama'asyncfunctionmain(){constresponse=awaitollama.chat({model:'deepseek-r1',messages:[{role:'user',content:'Whatis10+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()

思考式流式响应示例

importollamafrom'ollama'asyncfunctionmain(){constresponse=awaitollama.chat({model:'deepseek-r1',messages:[{role:'user',content:'Whatis10+23',},],stream:true,think:true,})letstartedThinking=falseletfinishedThinking=falseforawait(constchunkofresponse){if(chunk.message.thinking&&!startedThinking){startedThinking=trueprocess.stdout.write('Thinking:\n========\n\n')}elseif(chunk.message.content&&startedThinking&&!finishedThinking){finishedThinking=trueprocess.stdout.write('\n\nResponse:\n========\n\n')}if(chunk.message.thinking){process.stdout.write(chunk.message.thinking)}elseif(chunk.message.content){process.stdout.write(chunk.message.content)}}}main()

6、ollamf4j

暂不支持

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

链载AI是专业的生成式人工智能教程平台。提供Stable Diffusion、Midjourney AI绘画教程,Suno AI音乐生成指南,以及Runway、Pika等AI视频制作与动画生成实战案例。从提示词编写到参数调整,手把手助您从入门到精通。
  • 官方手机版

  • 微信公众号

  • 商务合作

  • Powered by Discuz! X3.5 | Copyright © 2025-2025. | 链载Ai
  • 桂ICP备2024021734号 | 营业执照 | |广西笔趣文化传媒有限公司|| QQ