Fix/gemma4 reasoning open optional newline#277
Merged
Conversation
- Removed trailing newline from REASONING_OPEN constant for accurate parsing. - Updated reasoning regex to allow for optional newline before content capture. - Trimmed leading whitespace from reasoning content to ensure clean extraction.
- Improved state management for parsing reasoning content, ensuring accurate handling of opening and closing tags. - Added support for capturing content before reasoning and refined buffer management for partial matches. - Streamlined the logic for returning reasoning content and passthrough data, enhancing overall parsing efficiency.
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.
Fix: Make newline after reasoning open tag optional in Gemma4ReasoningParser
Summary
\nfromREASONING_OPEN, making the tag<|channel>thoughtinstead of<|channel>thought\n, and handle the optional newline via regex (\n?) so the parser works regardless of whether the model emits a newline after the tag.extract_reasoning_streamingto process theNORMALstate first (buffering partial open-tag matches) before handling theFOUND_PREFIXstate. This fixes an issue where content arriving before the reasoning open tag could be dropped or misattributed, and ensures partial open-tag overlaps are correctly buffered instead of being emitted as regular content.Changes
app/parsers/gemma4.pyREASONING_OPENno longer includes a trailing newline; the newline is stripped with.lstrip("\n")after matching.\n?between the open tag and captured content.REASONING_OPENoverlaps inNORMALstate, preventing premature passthrough of incomplete tags."content"rather than being silently discarded.