@@ -2249,6 +2249,46 @@ static void test_template_output_peg_parsers(bool detailed_debug) {
22492249 .reasoning_format (COMMON_REASONING_FORMAT_AUTO )
22502250 .expect (message_assist)
22512251 .run ();
2252+
2253+ {
2254+ // additional tests for https://github.com/ggml-org/llama.cpp/pull/21760
2255+ auto tmpls = read_templates (" models/templates/google-gemma-4-31B-it.jinja" );
2256+
2257+ common_chat_msg tool_call_msg = simple_assist_msg (
2258+ " Let me check." , " " , " special_function" , " {\" arg1\" : 1}" ," c0" );
2259+
2260+ common_chat_msg tool_msg;
2261+ tool_msg.role = " tool" ;
2262+ tool_msg.tool_name = " special_function" ;
2263+ tool_msg.tool_call_id = " c0" ;
2264+ tool_msg.content = " {\" r\" :\" ok\" }" ;
2265+
2266+ {
2267+ common_chat_templates_inputs inputs;
2268+ inputs.messages = { message_user, tool_call_msg, tool_msg };
2269+ inputs.tools = { special_function_tool };
2270+ inputs.add_generation_prompt = true ;
2271+
2272+ auto params = common_chat_templates_apply (tmpls.get (), inputs);
2273+
2274+ if (!string_ends_with (params.prompt , " <turn|>\n <|turn>model\n " )) {
2275+ throw std::runtime_error (" Missing generation prompt for Gemma 4" );
2276+ }
2277+ }
2278+
2279+ {
2280+ common_chat_templates_inputs inputs;
2281+ inputs.messages = { message_user, tool_call_msg, tool_msg };
2282+ inputs.tools = { special_function_tool };
2283+ inputs.add_generation_prompt = false ;
2284+
2285+ auto params = common_chat_templates_apply (tmpls.get (), inputs);
2286+
2287+ if (string_ends_with (params.prompt , " <|turn>model\n " )) {
2288+ throw std::runtime_error (" Gemma 4: generation prompt was modified despite add_generation_prompt=false" );
2289+ }
2290+ }
2291+ }
22522292 }
22532293
22542294 {
0 commit comments