fix: handle missing opening <think> tag for deepseek-r1-671b#1034
Open
MaxwellCalkin wants to merge 1 commit intoItzCrazyKns:masterfrom
Open
fix: handle missing opening <think> tag for deepseek-r1-671b#1034MaxwellCalkin wants to merge 1 commit intoItzCrazyKns:masterfrom
MaxwellCalkin wants to merge 1 commit intoItzCrazyKns:masterfrom
Conversation
deepseek-r1-671b only emits a closing think tag without an opening think tag. The existing logic handled the reverse case (opening without closing, during streaming) but not this one, causing thinking content to leak into the main answer instead of being rendered in the ThinkBox. Prepend think opening tag when think closing tag is found without a matching opening tag. Fixes ItzCrazyKns#810
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #810.
deepseek-r1-671b updated its chat template and now only emits a closing
</think>tag at the end of its thinking output, without an opening<think>tag. The existing thinking-tag logic inuseChat.tsxhandled the reverse case (opening<think>without closing</think>, which occurs during streaming) but did not handle this case. As a result, the model's thinking content leaked into the main answer instead of being rendered in the ThinkBox component.Changes
In
src/lib/hooks/useChat.tsx, the thinking tag detection in thesectionsuseMemo now:if (processedText.includes('<think>'))guard)<think>when</think>is found without a matching opening tag, so the markdown-to-jsx parser can route the content to the ThinkBox componentThis ensures models that omit the opening
<think>tag (like deepseek-r1-671b) still have their thinking content rendered correctly in the collapsible ThinkBox, while the existing streaming behavior (closing tag added when opening tag is present but closing is missing) is preserved.Test plan
<think>and</think>) — should continue working as before<think>without</think>should still get auto-closedSummary by cubic
Fixes #810. Ensures models that only emit a closing (like
deepseek-r1-671b) render their thinking in the ThinkBox instead of the main answer.src/lib/hooks/useChat.tsx, always count both<think>and</think>tags during parsing.</think>appears without a matching<think>, prepend<think>so the markdown parser routes content to the ThinkBox.<think>without a closing tag.Written for commit b688355. Summary will update on new commits.