chat : implement minicpm5 parser (#24889)

* Add minicpm5 tool call parser

* Refactor MiniCPM5 PEG parser per review feedback

* Fix jinja min/max API to match Jinja2

* modify by review

* MiniCPM5: use autoparser for XML tool calls and fix grammar preserved-token triggers

* MiniCPM5: fix streaming tool-arg placeholder and remove alt XML markers

* skip min/max attribute tests in -py mode

* test-jinja: use real expected output for min/max attribute tests

* MiniCPM5: revert shared mapper and history fallbacks per review

Drop streaming tool-arg placeholder workarounds from the generic PEG
mapper and restore strict tool-call argument JSON parsing so MiniCPM5
support stays limited to autoparser/diff-analyzer changes.

* chat : refactor minicpm5 back to dedicated parser

* cont : simplify grammar

* cont : refactor

* cont : fixes

* cont : rename template to openbmb-MiniCPM5-1B.jinja

* cont : add message delimiters

* cont : fix tests

---------

Co-authored-by: zhangtao <zhangtao2@modelbest.cn>
Co-authored-by: 张涛 <>
This commit is contained in:
Aldehir Rojas
2026-06-28 09:53:32 -05:00
committed by GitHub
parent f68a788b0b
commit c818263f2a
5 changed files with 482 additions and 0 deletions

View File

@@ -5593,6 +5593,77 @@ static void test_template_output_peg_parsers(bool detailed_debug) {
.expect_content("Hello, world!\nWhat's up?")
.run();
}
// MiniCPM5 - XML tool calls with <function name="..."><param name="...">...</param></function>
{
auto tst = peg_tester("models/templates/openbmb-MiniCPM5-1B.jinja", detailed_debug);
tst.test("Hello, world!\nWhat's up?")
.enable_thinking(false)
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
.expect(message_assist)
.run();
tst.test(R"(<function name="python"><param name="code">print('Hello, World!')</param></function>)")
.enable_thinking(false)
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
.tools({ python_tool })
.expect_tool_calls({ { "python", R"#({"code": "print('Hello, World!')"})#", {} } })
.run();
tst.test(R"(<function name="empty_args"></function>)")
.enable_thinking(false)
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
.tools({ empty_args_tool })
.expect(simple_assist_msg("", "", "empty_args", "{}"))
.run();
tst.test(R"(<function name="python"><param name="code">print('x')</param></function>)")
.enable_thinking(false)
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
.parallel_tool_calls(true)
.tools({ python_tool })
.expect_tool_calls({ { "python", R"#({"code": "print('x')"})#", {} } })
.run();
// CDATA lets a string value carry characters that would otherwise close the tag.
tst.test(R"(<function name="html"><param name="markup"><![CDATA[<a href="/x">hi</a> </param>]]></param></function>)")
.enable_thinking(false)
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
.tools({ html_tool })
.expect_tool_calls({ { "html", R"#({"markup": "<a href=\"/x\">hi</a> </param>"})#", {} } })
.run();
tst.test(R"(I'm thinking</think><function name="python"><param name="code">print('hey')</param></function>)")
.enable_thinking(true)
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
.tools({ python_tool })
.expect_reasoning("I'm thinking")
.expect_tool_calls({ { "python", R"#({"code": "print('hey')"})#", {} } })
.run();
tst.test(R"(<function name="python"><param name="code">print('x')</param></function>
<function name="python"><param name="code">print('y')</param></function>)")
.enable_thinking(false)
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
.parallel_tool_calls(true)
.tools({ python_tool })
.expect_tool_calls({
{ "python", R"#({"code": "print('x')"})#", {} },
{ "python", R"#({"code": "print('y')"})#", {} },
})
.run();
tst.test(" thinking</think>Hello, world!\nWhat's up?")
.enable_thinking(true)
.reasoning_format(COMMON_REASONING_FORMAT_AUTO)
.messages({ message_user, message_assist_prefill_reasoning })
.add_generation_prompt(false)
.continue_final_message(COMMON_CHAT_CONTINUATION_REASONING)
.expect_reasoning("I'm thinking")
.expect_content("Hello, world!\nWhat's up?")
.run();
}
}
static void test_template_generation_prompt() {
@@ -5740,6 +5811,13 @@ static void test_template_generation_prompt() {
check(tmpls, continuation_content(), "<Assistant><think>I'm thinking</think>Hello, ");
check(tmpls, continuation_reasoning(), "<Assistant><think>I'm");
}
{
auto tmpls = read_templates("models/templates/openbmb-MiniCPM5-1B.jinja");
check(tmpls, basic(), "<|im_start|>assistant\n<think>\n");
check(tmpls, continuation_content(), "<|im_start|>assistant\n<think>\nI'm thinking\n</think>\n\nHello, ");
check(tmpls, continuation_reasoning(), "<|im_start|>assistant\n<think>\nI'm");
}
}
// Test the developer role to system workaround with a simple mock template