diff --git a/common/chat.cpp b/common/chat.cpp
index 5b93c58873..1de8a3ba8f 100644
--- a/common/chat.cpp
+++ b/common/chat.cpp
@@ -1963,7 +1963,7 @@ static common_chat_params common_chat_templates_apply_jinja(const struct common_
params.add_generation_prompt = true;
std::string gen_prompt = common_chat_template_direct_apply_impl(tmpl, params);
auto diff = calculate_diff_split(no_gen_prompt, gen_prompt);
- params.generation_prompt = diff.right;
+ params.generation_prompt = diff.right + diff.suffix;
params.add_generation_prompt = inputs.add_generation_prompt;
diff --git a/tests/test-chat.cpp b/tests/test-chat.cpp
index 72deeeab3c..814faa43ca 100644
--- a/tests/test-chat.cpp
+++ b/tests/test-chat.cpp
@@ -998,6 +998,7 @@ static void test_peg_parser(common_chat_templates * tmpls,
auto parser = make_peg_parser(tmpls, tc.params, detailed_debug);
if (detailed_debug) {
LOG_DBG("Using parser: \n%s\n", parser.arena_.dump(parser.arena_.root()).c_str());
+ LOG_DBG("Generation prompt: '%s'\n", parser.params_.generation_prompt.c_str());
}
common_chat_msg msg_accum;
@@ -3102,8 +3103,19 @@ static void test_template_output_peg_parsers(bool detailed_debug) {
// Format: value
{
auto tst = peg_tester("models/templates/MiniMax-M2.jinja", detailed_debug);
+ tst.test("Hello, world!\nWhat's up?").enable_thinking(true).reasoning_format(COMMON_REASONING_FORMAT_AUTO).expect(message_assist).run();
+
+ tst.test("I'm\nthinkingHello, world!\nWhat's up?").enable_thinking(true).reasoning_format(COMMON_REASONING_FORMAT_AUTO).expect(message_assist_thoughts).run();
+
+ tst.test("Let's call a tool:\n\n\n").
+ enable_thinking(true).
+ reasoning_format(COMMON_REASONING_FORMAT_AUTO).
+ tools({ empty_args_tool }).
+ expect(message_with_reasoning_and_tool_call("Let's call a tool:", "empty_args", "{}")).
+ run();
+
tst.test(
- "\n\n\n\n1\n\n")
.tools({ special_function_tool })
.expect(message_assist_call)