Skip to content

Commit 6e1fb00

Browse files
committed
Fix for test
1 parent dc6c4f2 commit 6e1fb00

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

common/chat.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,12 @@ static void common_chat_parse_qwen3_coder_xml(common_chat_msg_parser & builder)
931931
// For now, use empty tools vector - we'll need to pass tools differently
932932
std::vector<common_chat_tool> empty_tools;
933933
if (builder.parse_qwen3_xml_tool_call(content, empty_tools)) {
934-
// Successfully parsed XML tool call
934+
// Only treat as parsed if at least one tool call was actually added.
935+
// On malformed or incomplete XML, fall back to plain content.
936+
const auto & parsed = builder.result();
937+
if (parsed.tool_calls.empty() && parsed.content.empty()) {
938+
builder.add_content(content);
939+
}
935940
return;
936941
}
937942

@@ -2237,9 +2242,11 @@ static common_chat_params common_chat_templates_apply_jinja(
22372242
}
22382243

22392244
// Qwen3-Coder XML format detection (must come before Hermes 2 Pro)
2240-
// Look for unique patterns that distinguish Qwen3-Coder from other formats
2241-
if (src.find("Function calls MUST follow the specified format") != std::string::npos ||
2242-
src.find("<function=...></function> block must be nested within <tool_call></tool_call>") != std::string::npos) {
2245+
// Detect via explicit XML markers unique to Qwen3-Coder to avoid false positives in other templates.
2246+
// Require presence of <tool_call>, <function=...>, and <parameter=...> blocks.
2247+
if (src.find("<tool_call>") != std::string::npos &&
2248+
src.find("<function=") != std::string::npos &&
2249+
src.find("<parameter=") != std::string::npos) {
22432250
return common_chat_params_init_qwen3_coder_xml(tmpl, params);
22442251
}
22452252

tests/test-chat.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,8 @@ static void test_template_output_parsers() {
20342034
{COMMON_CHAT_FORMAT_QWEN3_CODER_XML}));
20352035

20362036
printf("✅ All Qwen3-Coder XML error handling and edge case tests passed!\n");
2037-
2037+
}
2038+
20382039
{
20392040
auto tmpls = read_templates("models/templates/ibm-granite-granite-3.3-2B-Instruct.jinja");
20402041
std::vector<std::string> end_tokens{ "<|end_of_text|>" };
@@ -2270,7 +2271,6 @@ static void test_template_output_parsers() {
22702271
/* .reasoning_format = */ COMMON_REASONING_FORMAT_AUTO,
22712272
}));
22722273
}
2273-
}
22742274
}
22752275

22762276

0 commit comments

Comments
 (0)