Skip to content

fix(openai_compat): strip <think> tags from content before sending to…#1233

Closed
denysvitali wants to merge 1 commit intosipeed:mainfrom
denysvitali:fix/strip-think-tags
Closed

fix(openai_compat): strip <think> tags from content before sending to…#1233
denysvitali wants to merge 1 commit intosipeed:mainfrom
denysvitali:fix/strip-think-tags

Conversation

@denysvitali
Copy link
Copy Markdown

📝 Description

Some models (e.g. MiniMax M2.5, DeepSeek) embed chain-of-thought in the content field using tags rather than a dedicated reasoning_content field. Move these blocks into ReasoningContent so channels don't render raw thinking output to users.

🗣️ Type of Change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 📖 Documentation update
  • ⚡ Code refactoring (no functional changes, no api changes)

🤖 AI Code Generation

  • 🤖 Fully AI-generated (100% AI, 0% Human)
  • 🛠️ Mostly AI-generated (AI draft, Human verified/modified)
  • 👨‍💻 Mostly Human-written (Human lead, AI assisted or none)

🔗 Related Issue

📚 Technical Context (Skip for Docs)

  • Reference URL:
  • Reasoning:

🧪 Test Environment

  • Hardware:
  • OS:
  • Model/Provider:
  • Channels:

📸 Evidence (Optional)

Click to view Logs/Screenshots

☑️ Checklist

  • My code/docs follow the style of this project.
  • I have performed a self-review of my own changes.
  • I have updated the documentation accordingly.

… user

Some models (e.g. MiniMax M2.5, DeepSeek) embed chain-of-thought in the
content field using <think> tags rather than a dedicated reasoning_content
field. Move these blocks into ReasoningContent so channels don't render
raw thinking output to users.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 8, 2026

CLA assistant check
All committers have signed the CLA.

@sipeed-bot sipeed-bot bot added type: bug Something isn't working domain: provider go Pull requests that update go code labels Mar 8, 2026
Copy link
Copy Markdown

@nikolasdehor nikolasdehor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This addresses the same problem as PR #1237 (leaked thinking tags) but takes a different approach: extracting <think> content into ReasoningContent rather than stripping all reasoning/thinking tags.

Comparison with PR #1237:

  • #1233 (this PR): only handles <think>...</think>, moves content to ReasoningContent
  • #1237: handles <think>, <thinking>, <thought>, <reasoning>, <final>, escaped unicode, unclosed blocks -- strips all of them

Feedback on this PR:

  1. Only <think> is handled -- some providers use <thinking>, <thought>, or <reasoning> tags. PR #1237 is more comprehensive in this regard.

  2. Good idea to preserve reasoning -- moving thinking content to ReasoningContent rather than discarding it is arguably better than pure stripping. This lets channels/UI that support reasoning display optionally show it. However, the condition `if msgReasoning == "" && strings.Contains(msgContent, "")" means this only fires when no dedicated reasoning field exists.

  3. Regex concern -- (?s)<think>(.*?)</think> with the lazy quantifier is correct for matching the innermost <think> block. However, this won't handle nested tags (unlikely but possible) or malformed HTML.

  4. No test coverage -- PR #1237 includes tests; this PR does not. Tests are important for a parsing change like this.

  5. Redundant regex compilation inside callback -- thinkTagRe.FindStringSubmatch(m) is called inside ReplaceAllStringFunc, which already matched the regex. The submatch is available if you use ReplaceAllStringSubmatchFunc (not in stdlib, but the pattern can be restructured to use FindAllStringSubmatch + manual reconstruction).

I would recommend consolidating this with PR #1237. The "move to ReasoningContent" behavior from this PR is superior to pure stripping, while #1237 has better tag coverage and tests.

@sipeed-bot
Copy link
Copy Markdown

sipeed-bot bot commented Mar 25, 2026

@denysvitali Hi! This PR has had no activity for over 2 weeks, so I'm closing it for now to keep things organized. Feel free to reopen anytime if you'd like to continue.

@sipeed-bot sipeed-bot bot closed this Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: provider go Pull requests that update go code type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants