[GH-ISSUE #23] Help: 在ollama上运行时, 怎么才能让它不返回<think>标签 ? When running on ollama, how can I make it not return the < think > tag? #20

Closed
opened 2026-10-26 21:10:51 +00:00 by bsakaguchi · 26 comments
Owner

Originally created by @breakenknife on GitHub (Jan 21, 2025).
Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-R1/issues/23

如题, 在ollama上运行时, 每个回答都会在think标签对里返回一段很长的思考过程,怎么让它只返回最终答案?
For example, when running on ollama ,each reply will return a long thought process in think labels. How can we make it return only the final answer?

Originally created by @breakenknife on GitHub (Jan 21, 2025). Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-R1/issues/23 如题, 在ollama上运行时, 每个回答都会在think标签对里返回一段很长的思考过程,怎么让它只返回最终答案? For example, when running on ollama ,each reply will return a long thought process in think labels. How can we make it return only the final answer?
bsakaguchi 2026-10-26 21:10:51 +00:00
Author
Owner

@catsled commented on GitHub (Jan 21, 2025):

训练的时候这个是 reward的一部分,应该没办法跳过吧,只能写个规则让它在输出的时候不输出这些

<!-- gh-comment-id:2603887282 --> @catsled commented on GitHub (Jan 21, 2025): 训练的时候这个是 reward的一部分,应该没办法跳过吧,只能写个规则让它在输出的时候不输出这些
Author
Owner

@klmoretti commented on GitHub (Jan 21, 2025):

r1是推理模型,他的能力可以说完全依托于think,不想要think可以用deekseek-v3。
或者你可以手动把think的内容屏蔽掉,类似于o1模型的api使用体验。
但无论如何,得到最终结果之前,模型都会进行think(也有时候think是空的),也就意味着,这段时间你必须等待。

<!-- gh-comment-id:2603887699 --> @klmoretti commented on GitHub (Jan 21, 2025): r1是推理模型,他的能力可以说完全依托于think,不想要think可以用deekseek-v3。 或者你可以手动把think的内容屏蔽掉,类似于o1模型的api使用体验。 但无论如何,得到最终结果之前,模型都会进行think(也有时候think是空的),也就意味着,这段时间你必须等待。
Author
Owner

@xxyyy commented on GitHub (Jan 22, 2025):

用起来速度比qwen2.5慢了,输出了一堆think的内容

<!-- gh-comment-id:2606372726 --> @xxyyy commented on GitHub (Jan 22, 2025): 用起来速度比qwen2.5慢了,输出了一堆think的内容
Author
Owner

@haibingtown commented on GitHub (Jan 22, 2025):

https://api-docs.deepseek.com/zh-cn/guides/reasoning_model 官方的接口,会有额外字段存放推理内容,vllm 或 ollama 部署好像一直有 tag,有什么好的处理办法吗

Image

<!-- gh-comment-id:2606444509 --> @haibingtown commented on GitHub (Jan 22, 2025): https://api-docs.deepseek.com/zh-cn/guides/reasoning_model 官方的接口,会有额外字段存放推理内容,vllm 或 ollama 部署好像一直有<think> tag,有什么好的处理办法吗 ![Image](https://github.com/user-attachments/assets/e6a4a4a2-41c7-4908-b87f-f46bd79bc655)
Author
Owner

@yhfgyyf commented on GitHub (Jan 22, 2025):

现阶段只能content.split("</think>")[-1],这个也是chat_template里添加history进行多轮对话的方法

<!-- gh-comment-id:2606513846 --> @yhfgyyf commented on GitHub (Jan 22, 2025): 现阶段只能`content.split("</think>")[-1]`,这个也是chat_template里添加history进行多轮对话的方法
Author
Owner

@LCorleone commented on GitHub (Jan 22, 2025):

现阶段只能content.split("</think>")[-1],这个也是chat_template里添加history进行多轮对话的方法

流式场景如果不想用户见到think的内容就很麻烦了

<!-- gh-comment-id:2606577221 --> @LCorleone commented on GitHub (Jan 22, 2025): > 现阶段只能`content.split("</think>")[-1]`,这个也是chat_template里添加history进行多轮对话的方法 流式场景如果不想用户见到think的内容就很麻烦了
Author
Owner

@breakenknife commented on GitHub (Jan 23, 2025):

各位我升级open-webui到0.5.6之后,问题解决了,它会隐藏标签内容.
同时,我发现用idea的continue插件请求ollama上的deepseekR1模型时, 却没有思考过程,不知道continue插件做了什么特殊处理?

<!-- gh-comment-id:2609199866 --> @breakenknife commented on GitHub (Jan 23, 2025): 各位我升级open-webui到0.5.6之后,问题解决了,它会隐藏<think>标签内容. 同时,我发现用idea的continue插件请求ollama上的deepseekR1模型时, 却没有思考过程,不知道continue插件做了什么特殊处理?
Author
Owner

@joezhouchenye commented on GitHub (Feb 2, 2025):

deepseek-coder-v2用来翻译也不错,就没think了,模型也不大

<!-- gh-comment-id:2629417991 --> @joezhouchenye commented on GitHub (Feb 2, 2025): deepseek-coder-v2用来翻译也不错,就没think了,模型也不大
Author
Owner

@omaiyiwa commented on GitHub (Feb 5, 2025):

https://api-docs.deepseek.com/zh-cn/guides/reasoning_model 官方的接口,会有额外字段存放推理内容,vllm 或 ollama 部署好像一直有 tag,有什么好的处理办法吗

Image

我在本地调用DeepSeek-R1-Distill-Qwen-7B模型,有think内容,但是为什么没有reasoning_content,只有content,使用的是sglang加载

<!-- gh-comment-id:2635579540 --> @omaiyiwa commented on GitHub (Feb 5, 2025): > https://api-docs.deepseek.com/zh-cn/guides/reasoning_model 官方的接口,会有额外字段存放推理内容,vllm 或 ollama 部署好像一直有 tag,有什么好的处理办法吗 > > ![Image](https://github.com/user-attachments/assets/e6a4a4a2-41c7-4908-b87f-f46bd79bc655) 我在本地调用DeepSeek-R1-Distill-Qwen-7B模型,有think内容,但是为什么没有reasoning_content,只有content,使用的是sglang加载
Author
Owner

@xjw00654 commented on GitHub (Feb 5, 2025):

vllm 已经支持了
https://docs.vllm.ai/en/latest/features/reasoning_outputs.html

亲测
vllm serve /mnt/nas/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B/ --dtype auto --port 8000 --tensor-parallel-size 2 --gpu-memory-utilization 0.95 --served-model-name Qwen-14B-Chat --max-model-len 32000 --enable-reasoning --reasoning-parser deepseek_r1
可行

<!-- gh-comment-id:2635756740 --> @xjw00654 commented on GitHub (Feb 5, 2025): vllm 已经支持了 https://docs.vllm.ai/en/latest/features/reasoning_outputs.html 亲测 `vllm serve /mnt/nas/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B/ --dtype auto --port 8000 --tensor-parallel-size 2 --gpu-memory-utilization 0.95 --served-model-name Qwen-14B-Chat --max-model-len 32000 --enable-reasoning --reasoning-parser deepseek_r1` 可行
Author
Owner

@wudidiandian commented on GitHub (Feb 5, 2025):

关键是ollama测试了,DeepSeek-R1-Distill-Qwen-7B,DeepSeek-R1-Distill-Llama-8B,两个模型与原qwen,llama版本模型比较,蒸馏过的模型回答结果并不好,只是思考过程输出了,结果也不对,问下各位大佬,蒸馏过的模型在哪方面会更出色呢?有简单的测试样例么

<!-- gh-comment-id:2636834254 --> @wudidiandian commented on GitHub (Feb 5, 2025): 关键是ollama测试了,DeepSeek-R1-Distill-Qwen-7B,DeepSeek-R1-Distill-Llama-8B,两个模型与原qwen,llama版本模型比较,蒸馏过的模型回答结果并不好,只是思考过程输出了,结果也不对,问下各位大佬,蒸馏过的模型在哪方面会更出色呢?有简单的测试样例么
Author
Owner

@weihao-zhao commented on GitHub (Feb 5, 2025):

vllm 已经支持了 https://docs.vllm.ai/en/latest/features/reasoning_outputs.html

亲测 vllm serve /mnt/nas/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B/ --dtype auto --port 8000 --tensor-parallel-size 2 --gpu-memory-utilization 0.95 --served-model-name Qwen-14B-Chat --max-model-len 32000 --enable-reasoning --reasoning-parser deepseek_r1 可行

很强,不过这里可能有需求是用户可以指定模型是否深度思考,就像 deepseek 的 deepthink button 一样,如果能支持的话可以避免同时 host v3 和 r1 两个模型。

<!-- gh-comment-id:2638134637 --> @weihao-zhao commented on GitHub (Feb 5, 2025): > vllm 已经支持了 https://docs.vllm.ai/en/latest/features/reasoning_outputs.html > > 亲测 `vllm serve /mnt/nas/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B/ --dtype auto --port 8000 --tensor-parallel-size 2 --gpu-memory-utilization 0.95 --served-model-name Qwen-14B-Chat --max-model-len 32000 --enable-reasoning --reasoning-parser deepseek_r1` 可行 很强,不过这里可能有需求是用户可以指定模型是否深度思考,就像 deepseek 的 deepthink button 一样,如果能支持的话可以避免同时 host v3 和 r1 两个模型。
Author
Owner

@xjw00654 commented on GitHub (Feb 7, 2025):

vllm 已经支持了 https://docs.vllm.ai/en/latest/features/reasoning_outputs.html
亲测 vllm serve /mnt/nas/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B/ --dtype auto --port 8000 --tensor-parallel-size 2 --gpu-memory-utilization 0.95 --served-model-name Qwen-14B-Chat --max-model-len 32000 --enable-reasoning --reasoning-parser deepseek_r1 可行

很强,不过这里可能有需求是用户可以指定模型是否深度思考,就像 deepseek 的 deepthink button 一样,如果能支持的话可以避免同时 host v3 和 r1 两个模型。

R1 Distill出来的模型大概率会带think的标签,要没有就用常规模型。

<!-- gh-comment-id:2643272352 --> @xjw00654 commented on GitHub (Feb 7, 2025): > > vllm 已经支持了 https://docs.vllm.ai/en/latest/features/reasoning_outputs.html > > 亲测 `vllm serve /mnt/nas/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B/ --dtype auto --port 8000 --tensor-parallel-size 2 --gpu-memory-utilization 0.95 --served-model-name Qwen-14B-Chat --max-model-len 32000 --enable-reasoning --reasoning-parser deepseek_r1` 可行 > > 很强,不过这里可能有需求是用户可以指定模型是否深度思考,就像 deepseek 的 deepthink button 一样,如果能支持的话可以避免同时 host v3 和 r1 两个模型。 R1 Distill出来的模型大概率会带think的标签,要没有<think></think>就用常规模型。
Author
Owner

@hitcca commented on GitHub (Feb 8, 2025):

最近想尝试Graphrag +Ollama使用本地部署。使用deepseek-r1大模型,报错ValueError: Columns must be same length as key。不知道与输出think是否有关

<!-- gh-comment-id:2645752971 --> @hitcca commented on GitHub (Feb 8, 2025): 最近想尝试Graphrag +Ollama使用本地部署。使用deepseek-r1大模型,报错ValueError: Columns must be same length as key。不知道与输出think是否有关
Author
Owner

@ilovedumplings commented on GitHub (Feb 10, 2025):

https://api-docs.deepseek.com/zh-cn/guides/reasoning_model 官方的接口,会有额外字段存放推理内容,vllm 或 ollama 部署好像一直有 tag,有什么好的处理办法吗
Image

我在本地调用DeepSeek-R1-Distill-Qwen-7B模型,有think内容,但是为什么没有reasoning_content,只有content,使用的是sglang加载

我也是.这个你知道原因嘛?

<!-- gh-comment-id:2646851513 --> @ilovedumplings commented on GitHub (Feb 10, 2025): > > https://api-docs.deepseek.com/zh-cn/guides/reasoning_model 官方的接口,会有额外字段存放推理内容,vllm 或 ollama 部署好像一直有 tag,有什么好的处理办法吗 > > ![Image](https://github.com/user-attachments/assets/e6a4a4a2-41c7-4908-b87f-f46bd79bc655) > > 我在本地调用DeepSeek-R1-Distill-Qwen-7B模型,有think内容,但是为什么没有reasoning_content,只有content,使用的是sglang加载 我也是.这个你知道原因嘛?
Author
Owner

@xjw00654 commented on GitHub (Feb 10, 2025):

https://api-docs.deepseek.com/zh-cn/guides/reasoning_model 官方的接口,会有额外字段存放推理内容,vllm 或 ollama 部署好像一直有 tag,有什么好的处理办法吗
Image

我在本地调用DeepSeek-R1-Distill-Qwen-7B模型,有think内容,但是为什么没有reasoning_content,只有content,使用的是sglang加载

我也是.这个你知道原因嘛?

换vllm部署,估计这会sgl还没支持? 初步翻了翻只看到了有v3的支持文档。

vllm serve /mnt/nas/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B/ --dtype auto --port 8000 --tensor-parallel-size 2 --gpu-memory-utilization 0.95 --served-model-name Qwen-14B-Chat --max-model-len 32000 --enable-reasoning --reasoning-parser deepseek_r1
<!-- gh-comment-id:2646920941 --> @xjw00654 commented on GitHub (Feb 10, 2025): > > > https://api-docs.deepseek.com/zh-cn/guides/reasoning_model 官方的接口,会有额外字段存放推理内容,vllm 或 ollama 部署好像一直有 tag,有什么好的处理办法吗 > > > ![Image](https://github.com/user-attachments/assets/e6a4a4a2-41c7-4908-b87f-f46bd79bc655) > > > > > > 我在本地调用DeepSeek-R1-Distill-Qwen-7B模型,有think内容,但是为什么没有reasoning_content,只有content,使用的是sglang加载 > > 我也是.这个你知道原因嘛? 换vllm部署,估计这会sgl还没支持? 初步翻了翻只看到了有v3的支持文档。 ```bash vllm serve /mnt/nas/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B/ --dtype auto --port 8000 --tensor-parallel-size 2 --gpu-memory-utilization 0.95 --served-model-name Qwen-14B-Chat --max-model-len 32000 --enable-reasoning --reasoning-parser deepseek_r1 ```
Author
Owner

@ilovedumplings commented on GitHub (Feb 10, 2025):

enable-reasoning

--enable-reasoning --reasoning-parser deepseek_r1 请问是这个参数决定引擎是否不输出think标签是嘛?

<!-- gh-comment-id:2646932391 --> @ilovedumplings commented on GitHub (Feb 10, 2025): > enable-reasoning --enable-reasoning --reasoning-parser deepseek_r1 请问是这个参数决定引擎是否不输出think标签是嘛?
Author
Owner

@kidd20172017 commented on GitHub (Feb 11, 2025):

vllm 已经支持了 https://docs.vllm.ai/en/latest/features/reasoning_outputs.html

亲测 vllm serve /mnt/nas/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B/ --dtype auto --port 8000 --tensor-parallel-size 2 --gpu-memory-utilization 0.95 --served-model-name Qwen-14B-Chat --max-model-len 32000 --enable-reasoning --reasoning-parser deepseek_r1 可行

你好请问你是哪个版本的vllm

<!-- gh-comment-id:2649713010 --> @kidd20172017 commented on GitHub (Feb 11, 2025): > vllm 已经支持了 https://docs.vllm.ai/en/latest/features/reasoning_outputs.html > > 亲测 `vllm serve /mnt/nas/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B/ --dtype auto --port 8000 --tensor-parallel-size 2 --gpu-memory-utilization 0.95 --served-model-name Qwen-14B-Chat --max-model-len 32000 --enable-reasoning --reasoning-parser deepseek_r1` 可行 你好请问你是哪个版本的vllm
Author
Owner

@Shicc commented on GitHub (Feb 19, 2025):

从ollama拉的deepseek的蒸馏模型,运行的时候,think标签都可以折叠,也可以选择性展示,但是从huggingface下载的模型,就很生硬的显示这样的标签,如何折叠呢?

<!-- gh-comment-id:2667898021 --> @Shicc commented on GitHub (Feb 19, 2025): 从ollama拉的deepseek的蒸馏模型,运行的时候,think标签都可以折叠,也可以选择性展示,但是从huggingface下载的模型,就很生硬的显示<think/>这样的标签,如何折叠呢?
Author
Owner

@Daniel70-liu commented on GitHub (Mar 1, 2025):

請問 ollama 如何在 modelfile 摺疊think標籤內容讓他不顯示,或是有什麼方法可以實現嗎? 謝謝

<!-- gh-comment-id:2692193651 --> @Daniel70-liu commented on GitHub (Mar 1, 2025): 請問 ollama 如何在 modelfile 摺疊think標籤內容讓他不顯示,或是有什麼方法可以實現嗎? 謝謝
Author
Owner

@titusTong commented on GitHub (Mar 17, 2025):

我发现使用这个包可以解决:https://www.npmjs.com/package/parse-reasoning

npm install parse-reasoning
<!-- gh-comment-id:2728984877 --> @titusTong commented on GitHub (Mar 17, 2025): 我发现使用这个包可以解决:https://www.npmjs.com/package/parse-reasoning ``` npm install parse-reasoning ```
Author
Owner

@song2181 commented on GitHub (Mar 27, 2025):

从ollama拉的deepseek的蒸馏模型,运行的时候,think标签都可以折叠,也可以选择性展示,但是从huggingface下载的模型,就很生硬的显示这样的标签,如何折叠呢?
请问这个解决了吗,遇到了相同的问题

<!-- gh-comment-id:2757504062 --> @song2181 commented on GitHub (Mar 27, 2025): > 从ollama拉的deepseek的蒸馏模型,运行的时候,think标签都可以折叠,也可以选择性展示,但是从huggingface下载的模型,就很生硬的显示这样的标签,如何折叠呢? 请问这个解决了吗,遇到了相同的问题
Author
Owner

@ytfrdfiw commented on GitHub (Apr 14, 2025):

enable-reasoning

--enable-reasoning --reasoning-parser deepseek_r1 请问是这个参数决定引擎是否不输出think标签是嘛?

亲测,我使用vllm0.8.3,加上上面的配置后,返回的内容分为reasoning_content和content,前者是推理内容,后者是结果。
感谢分享。 @xjw00654

<!-- gh-comment-id:2800842312 --> @ytfrdfiw commented on GitHub (Apr 14, 2025): > > enable-reasoning > > --enable-reasoning --reasoning-parser deepseek_r1 请问是这个参数决定引擎是否不输出think标签是嘛? 亲测,我使用vllm0.8.3,加上上面的配置后,返回的内容分为reasoning_content和content,前者是推理内容,后者是结果。 感谢分享。 @xjw00654
Author
Owner

@github-actions[bot] commented on GitHub (Jun 1, 2025):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this issue is still relevant, please leave a comment to keep it open. Thank you for your contributions!

<!-- gh-comment-id:2926056710 --> @github-actions[bot] commented on GitHub (Jun 1, 2025): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this issue is still relevant, please leave a comment to keep it open. Thank you for your contributions!
Author
Owner

@github-actions[bot] commented on GitHub (Jun 18, 2025):

false

<!-- gh-comment-id:2982177261 --> @github-actions[bot] commented on GitHub (Jun 18, 2025): false
Author
Owner

@yifanzheng commented on GitHub (Aug 16, 2025):

我本地使用 ollama 运行 deepseek-r1:7b 模型(也就是 DeepSeek-R1-Distill-Qwen-7B 模型),使用 langchain-ollama 进行调用,可以通过设置参数 reasoning = True 将 think 块给屏蔽掉,让模型直接输出最终答案。

代码如下:

llm = ChatOllama(base_url="http://localhost:11434",
                 model="deepseek-r1:7b",
                 temperature=0.3,
                 reasoning = True  # 设置 content 不输出 think 块
      )

langchain 版本:

Image
<!-- gh-comment-id:3193675071 --> @yifanzheng commented on GitHub (Aug 16, 2025): 我本地使用 ollama 运行 `deepseek-r1:7b` 模型(也就是 `DeepSeek-R1-Distill-Qwen-7B` 模型),使用 langchain-ollama 进行调用,可以通过设置参数 `reasoning = True` 将 think 块给屏蔽掉,让模型直接输出最终答案。 代码如下: ```python llm = ChatOllama(base_url="http://localhost:11434", model="deepseek-r1:7b", temperature=0.3, reasoning = True # 设置 content 不输出 think 块 ) ``` langchain 版本: <img width="707" height="147" alt="Image" src="https://github.com/user-attachments/assets/0c379f98-04fd-4c17-abf4-b3570e06dfad" />
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
deepseek-ai/DeepSeek-R1#20
No description provided.