continue icon indicating copy to clipboard operation
continue copied to clipboard

Support `<think />` tags from R1

Open Patrick-Erichsen opened this issue 1 year ago • 14 comments

Before submitting your bug report

Relevant environment info


Description

DeepSeek-R1 model produces <think /> tags that we can parse and render in a nicer UI than the default Think... text that we use for reasoning models like o1 that don't expose their reasoning steps.

Example implementation from chat.deepseek.com

Image

Image

To reproduce

No response

Log output


Patrick-Erichsen avatar Jan 23 '25 18:01 Patrick-Erichsen

Is this already being worked on, to remove the think from the chat window, (show hide) also make sure its not being sent back into the regular context window for follow up messages?

chriswritescode-dev avatar Jan 24 '25 19:01 chriswritescode-dev

https://github.com/continuedev/continue/pull/3840 Waiting for review

german-swan avatar Jan 24 '25 20:01 german-swan

@germankrause I'm using the current pre-release 0.9.259 with OpenRouter:

    {
      "title": "DeepSeek R1",
      "provider": "openai",
      "model": "deepseek/deepseek-r1",
      "apiKey": <API_KEY>,
      "completionOptions": {},
      "apiBase": "https://openrouter.ai/api/v1"
    },

Which works great! The output is super useful.

However, the reasoning output is not displayed. It seems that OpenRouter needs include_reasoning be set to true, or it will just skip the <think/> output: https://openrouter.ai/announcements/reasoning-tokens-for-thinking-models

Just wanted to flag this in case it's useful at this point.

manmal avatar Feb 03 '25 09:02 manmal

Thanks for the heads up here @manmal ! Created an issue for that here: https://github.com/continuedev/continue/issues/3946

Patrick-Erichsen avatar Feb 03 '25 21:02 Patrick-Erichsen

I'm using the current pre-release 0.9.259 with deepseek official api, the reasoning output is still not displayed

kingcanfish avatar Feb 04 '25 07:02 kingcanfish

How do I achieve this with OpenAI-compatible API provided by Ollama plus a custom DeepSeek-based model?

  • I have imported a DeepSeek-distilled Qwen model (from HuggingFace) into Ollama,
  • and then served the model using Ollama's OpenAI-compatible API.

With the latest Continue, and my configuration:

    {
      "title": "DeepSeek-R1 Distill Qwen 7B fp16",
      "provider": "openai",
      "model": "ollama-ds-r1-distill-qwen-7b",
      "apiBase": "http://10.103.245.111:21434/v1",
      "apiKey": "ollama"
    }

This is what I've got:

https://github.com/user-attachments/assets/87573e10-e81c-4ec5-a268-fac1810a0a5a

I believe this is caused by the lack of <think>/n in the prompt, or something extra added to the prompt. Running the model directly with ollama run yields amazing results, but not on Continue.

I'd be great if there is a way to customize prompts for any models. Any pointers?

mindcrunch4u avatar Feb 06 '25 08:02 mindcrunch4u

Try it:

{
"models": [
{
 "title": "DeepSeek R1",
      "provider": "openai",
      "model": "deepseek-r1",
      "apiKey": "",
      "apiBase": "",
      "useLegacyCompletionsEndpoint": false,
      "systemMessage": "# 角色定义\nrole: \"AI Assistant (DeepSeek-R1-Enhanced)\"\nauthor: \"DeepSeek\"\ndescription: >\n  通用型智能助手,通过结构化思考流程提供可靠服务。\n# 输出规范\noutput_schema:\n  thinking_section:  # 强制思考段落\n    required: true\n    tags: \"<think>\\\\n嗯{thinkContent}</think>{finalContent}\"\n    content_rules:\n      - 使用Markdown格式\n      - 内容有效性验证:\n          rules:\n            - rule: \"non_empty\"  # 非空验证规则"
 }
]
}

This will make Deepseek start its answers with <think>, but will cause the default replies to be in Chinese. Translate systemMessage to your default language to change this.

Image

xkeyC avatar Feb 17 '25 07:02 xkeyC

Image I find that editing code or code completion takes the tag with it, how do I get rid of the tag.

   {
      "title": "DeepSeek-R1",
      "model": "DeepSeek-R1",
      "apiKey": "xxxxx",
      "provider": "deepseek",
      "apiBase": "https://{HOST}/v1"
    },

This is the OpenAI-compatible interface I deployed with vllm

GhangZh avatar Feb 19 '25 08:02 GhangZh

我想知道现在的渲染是如何处理think内容的,我使用groq的api是可以有"Thought for x.x. s",但我使用deepseek/siliconflow api却不可以。deepseek/siliconflow 都是将<think></think> 独立成单独的单独的 reasoning_content 字段。我不知道是否是这样处理的?

translate : I want to know how the current rendering handles think content. When I use Groq's API, I can get "Thought for x.x. s" outputs, but this doesn't work when I use the DeepSeek/SiliconFlow API. Both DeepSeek and SiliconFlow seem to place <think></think> content in separate reasoning_content fields. I'm not sure if this is how they actually handle it?

Aucannot avatar Feb 20 '25 03:02 Aucannot

This issue hasn't been updated in 90 days and will be closed after an additional 10 days without activity. If it's still important, please leave a comment and share any new information that would help us address the issue.

github-actions[bot] avatar May 22 '25 02:05 github-actions[bot]

reasoning not displayed on pycharm for deep seek r1 , is it only implemented in vs code ?

Altroo avatar May 30 '25 15:05 Altroo

Image I find that editing code or code completion takes the tag with it, how do I get rid of the tag.

   {
      "title": "DeepSeek-R1",
      "model": "DeepSeek-R1",
      "apiKey": "xxxxx",
      "provider": "deepseek",
      "apiBase": "https://{HOST}/v1"
    },

This is the OpenAI-compatible interface I deployed with vllm

I have the same problem and I'm using Openai Compatible qwen3

meriam2303 avatar Jun 03 '25 12:06 meriam2303

This issue hasn't been updated in 90 days and will be closed after an additional 10 days without activity. If it's still important, please leave a comment and share any new information that would help us address the issue.

github-actions[bot] avatar Sep 02 '25 02:09 github-actions[bot]

This issue was closed because it wasn't updated for 10 days after being marked stale. If it's still important, please reopen + comment and we'll gladly take another look!

github-actions[bot] avatar Sep 13 '25 02:09 github-actions[bot]