Add GLM-4 reasoning parser and fix think tag / prefix cache bugs#295
Draft
janhilgard wants to merge 1 commit intowaybarrios:mainfrom
Draft
Add GLM-4 reasoning parser and fix think tag / prefix cache bugs#295janhilgard wants to merge 1 commit intowaybarrios:mainfrom
janhilgard wants to merge 1 commit intowaybarrios:mainfrom
Conversation
- Add Glm4ReasoningParser for GLM-4 models (GLM-4.5-Air, GLM-4.7) that use <think>...</think> tags but don't inject <think> in the prompt — output without tags is normal content, not truncated reasoning. Streaming override emits pre-think deltas as content. - Fix duplicate </think> tag handling in BaseThinkingReasoningParser: some models (e.g. GLM-4.5-Air) generate <think></think></think> with an extra closing tag that leaked into content. - Fix reasoning extraction with tool calls in server.py: always parse reasoning from original output.text so <think> content is preserved even when tool calls are present. - Remove <tool_call> tags from SPECIAL_TOKENS_PATTERN in utils.py: these are structural tags used by GLM-4's tool calling format and must not be stripped as special tokens. - Fix prefix cache corruption on exact match in scheduler.py: trim stored cache by 1 so the last prompt token is reprocessed at the correct position on cache hit. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
7b05a96 to
c32db4e
Compare
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
Glm4ReasoningParser(--reasoning-parser glm4) for GLM-4 models (GLM-4.5-Air, GLM-4.7) that use<think>...</think>tags but don't inject<think>in the prompt. Unlike Qwen3 where no tags = truncated reasoning, GLM-4 no tags = normal content. Streaming override emits pre-think deltas as content.</think>tag inBaseThinkingReasoningParser: some models generate<think></think></think>with an extra closing tag that leaked into content.output.textso<think>content is preserved even when tool calls are present.<tool_call>fromSPECIAL_TOKENS_PATTERN: these are structural tags used by GLM-4's tool calling format (--tool-call-parser glm47) and must not be stripped._prompt_cache_saveso the last prompt token is reprocessed at the correct position on cache hit.Test plan
tool_calls+reasoning_contentin response)Tested with GLM-4.5-Air (106B/12B MoE, mixed 6/8-bit) on Apple M3 Ultra, ~37 tok/s.
🤖 Generated with Claude Code