Skip to content

Commit 85d482e

Browse files
authored
parser: fix MiniMax handling (#21573)
1 parent ae65fbd commit 85d482e

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

common/chat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1963,7 +1963,7 @@ static common_chat_params common_chat_templates_apply_jinja(const struct common_
19631963
params.add_generation_prompt = true;
19641964
std::string gen_prompt = common_chat_template_direct_apply_impl(tmpl, params);
19651965
auto diff = calculate_diff_split(no_gen_prompt, gen_prompt);
1966-
params.generation_prompt = diff.right;
1966+
params.generation_prompt = diff.right + diff.suffix;
19671967

19681968
params.add_generation_prompt = inputs.add_generation_prompt;
19691969

tests/test-chat.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,7 @@ static void test_peg_parser(common_chat_templates * tmpls,
998998
auto parser = make_peg_parser(tmpls, tc.params, detailed_debug);
999999
if (detailed_debug) {
10001000
LOG_DBG("Using parser: \n%s\n", parser.arena_.dump(parser.arena_.root()).c_str());
1001+
LOG_DBG("Generation prompt: '%s'\n", parser.params_.generation_prompt.c_str());
10011002
}
10021003

10031004
common_chat_msg msg_accum;
@@ -3102,8 +3103,19 @@ static void test_template_output_peg_parsers(bool detailed_debug) {
31023103
// Format: <minimax:tool_call><invoke name="func"><parameter name="key">value</parameter></invoke></minimax:tool_call>
31033104
{
31043105
auto tst = peg_tester("models/templates/MiniMax-M2.jinja", detailed_debug);
3106+
tst.test("</think>Hello, world!\nWhat's up?").enable_thinking(true).reasoning_format(COMMON_REASONING_FORMAT_AUTO).expect(message_assist).run();
3107+
3108+
tst.test("I'm\nthinking</think>Hello, world!\nWhat's up?").enable_thinking(true).reasoning_format(COMMON_REASONING_FORMAT_AUTO).expect(message_assist_thoughts).run();
3109+
3110+
tst.test("Let's call a tool:</think><minimax:tool_call>\n<invoke name=\"empty_args\">\n</invoke>\n</minimax:tool_call>").
3111+
enable_thinking(true).
3112+
reasoning_format(COMMON_REASONING_FORMAT_AUTO).
3113+
tools({ empty_args_tool }).
3114+
expect(message_with_reasoning_and_tool_call("Let's call a tool:", "empty_args", "{}")).
3115+
run();
3116+
31053117
tst.test(
3106-
"<minimax:tool_call>\n<invoke name=\"special_function\">\n<parameter "
3118+
"</think><minimax:tool_call>\n<invoke name=\"special_function\">\n<parameter "
31073119
"name=\"arg1\">1</parameter>\n</invoke>\n</minimax:tool_call>")
31083120
.tools({ special_function_tool })
31093121
.expect(message_assist_call)

0 commit comments

Comments
 (0)