fix(chat_templates): extract reasoning_content before reassigning content in qwen3_5 template#3725
Conversation
…tent in qwen3_5 template The inline-<think> assistant branch reassigned content (stripping it to the post-</think> answer) before reasoning_content was extracted from it. Since reasoning_content reads from the already-truncated content, the reasoning trace was dropped and the answer leaked into the <think> block. Swap the two set statements to match the official Qwen3.5 template order.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR fixes a bug in the Qwen3.5 chat template where inline ChangesQwen3.5 Template Reasoning Parsing Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Ooh, this was the same comment I had on your PR @ved1beta . I think you can choose whichever to merge first |
Summary
Fixes #3724.
The bundled
qwen3_5.jinjatemplate parses inline<think>...</think>reasoning incorrectly for assistant messages. In theelsebranch that handles inline reasoning, the two{%- set %}statements were in the wrong order relative to the official Qwen3.5 template:contentwas mutated beforereasoning_contentwas extracted from it.Both assignments read
content, so they are order-dependent:After the first line,
contentno longer contains</think>(or<think>), so the second line'scontent.split('</think>')[0].split('<think>')[-1]just returns the already-truncated answer. The result: the reasoning trace is silently dropped and the answer is duplicated into the<think>block of the rendered prompt.Fix
Swap the two statements so
reasoning_contentis extracted from the originalcontentbeforecontentis reassigned, matching the official Qwen3.5 template:Test plan
contentcontains an inline<think>...</think>block (and no separatemessage.reasoning_contentfield) and confirm the reasoning text lands in the<think>block and the answer follows after</think>.🤖 Generated with Claude Code
Summary by CodeRabbit