Fix Qwen3 content extraction breaking code formatting#661
Fix Qwen3 content extraction breaking code formatting#661ikawrakow merged 1 commit intoikawrakow:mainfrom
Conversation
Problem: - qwen3::extract_content_during_parsing() used aggressive regex to collapse multiple newlines - This broke proper code formatting (e.g., PEP 8's 2 empty lines between functions) - Affected non-tool-call streaming output where formatting is critical Solution: - Replace aggressive std::regex_replace(R"(\n\s*\n)", "\n") with gentle string_strip() - Follow original llama.cpp patterns: only trim leading/trailing whitespace - Preserve internal formatting including multiple newlines - Add proper include for common.h to access string_strip function Changes: - examples/server/parsers/qwen3_parser.hpp: Replace whitespace cleanup with string_strip() - tests/test-function-calls.cpp: Add test_qwen3_whitespace_preservation() to prevent regression Testing: - ✅ PEP 8 compliance: 2 empty lines between functions preserved - ✅ Tool call parsing: All Qwen3 tests continue to pass - ✅ No regressions: Existing functionality maintained - ✅ Follows original llama.cpp whitespace handling patterns
|
hi i tested this pr in vs code continue extension with recent unsolth quant qwen 30b a3b coder but its still breaking when its calling second time tool and main repo not even working update looks like model itself there is a error let me check again |
|
https://huggingface.co/unsloth/Qwen3-Coder-30B-A3B-Instruct-GGUF/discussions/1 kindly check this discussion update this pull |
|
@gopinath87607 here is my latest branch updates |
|
Apparently qwen3 coder uses a different tool calling structure with XML instead of json, llama.cpp currently ads the functionality here: ggml-org/llama.cpp#15012 |
thanks mate i will check it do we need to use any special tag for tool activation like jinja |
|
Some more discussion on similar qwen with toolcalling stuff here: https://huggingface.co/bartowski/Qwen_Qwen3-235B-A22B-Instruct-2507-GGUF/discussions/1 |
Summary
Fixes a bug in Qwen3 content extraction where aggressive whitespace cleanup was breaking proper code formatting in non-tool-call streaming output.
Problem
The
qwen3::extract_content_during_parsing()function was using an aggressive regex pattern that collapsed multiple newlines:This broke:
Root Cause
The regex
R"(\n\s*\n)"replaces any sequence of newline + whitespace + newline with a single newline, which is overly aggressive for content that should preserve formatting.Solution
✅ Replace aggressive cleanup with gentle trimming
std::regex_replace(content, std::regex(R"(\n\s*\n)"), "\n")string_strip(content)following original llama.cpp patterns✅ Add proper include
#include "../../common/common.h"forstring_stripaccess✅ Add regression test
test_qwen3_whitespace_preservation()validates PEP 8 complianceTesting
Example
Before (broken):
After (fixed):
Files Changed
examples/server/parsers/qwen3_parser.hpp- Fix whitespace handlingtests/test-function-calls.cpp- Add regression testTest Results