@@ -953,6 +953,33 @@ static void test_template_output_parsers() {
953953 /* is_partial= */ false ,
954954 {COMMON_CHAT_FORMAT_HERMES_2_PRO}));
955955
956+ // Test multiple tool calls
957+ common_chat_msg message_assist_multiple_calls;
958+ message_assist_multiple_calls.role = " assistant" ;
959+ message_assist_multiple_calls.content = " " ;
960+ message_assist_multiple_calls.tool_calls .push_back ({" special_function" , " {\" arg1\" : 1}" , " " });
961+ message_assist_multiple_calls.tool_calls .push_back ({" python" , " {\" code\" :\" print('hello')\" }" , " " });
962+
963+ assert_msg_equals (
964+ message_assist_multiple_calls,
965+ common_chat_parse (
966+ " <tool_call>\n "
967+ " {\" name\" : \" special_function\" , \" arguments\" : {\" arg1\" : 1}}\n "
968+ " </tool_call>\n "
969+ " <tool_call>\n "
970+ " {\" name\" : \" python\" , \" arguments\" : {\" code\" :\" print('hello')\" }}\n "
971+ " </tool_call>" ,
972+ /* is_partial= */ false ,
973+ {COMMON_CHAT_FORMAT_HERMES_2_PRO}));
974+
975+ assert_msg_equals (
976+ message_assist_multiple_calls,
977+ common_chat_parse (
978+ " <function=special_function>{\" arg1\" : 1}</function>\n "
979+ " <function=python>{\" code\" :\" print('hello')\" }</function>" ,
980+ /* is_partial= */ false ,
981+ {COMMON_CHAT_FORMAT_HERMES_2_PRO}));
982+
956983 assert_msg_equals (
957984 simple_assist_msg (
958985 " This is not a tool call:" ,
@@ -1039,6 +1066,22 @@ static void test_template_output_parsers() {
10391066 " <tool_call>\n "
10401067 " {\" name\" : \" special_function\" , \" arguments\" : {\" arg1\" : 1}}\n "
10411068 " </tool_call>" );
1069+
1070+ // Test multiple tool calls with template
1071+ common_chat_msg message_assist_multiple_calls_template;
1072+ message_assist_multiple_calls_template.role = " assistant" ;
1073+ message_assist_multiple_calls_template.content = " " ;
1074+ message_assist_multiple_calls_template.tool_calls .push_back ({" special_function" , " {\" arg1\" : 1}" , " " });
1075+ message_assist_multiple_calls_template.tool_calls .push_back ({" python" , " {\" code\" :\" print('test')\" }" , " " });
1076+
1077+ test_templates (tmpls.get (), end_tokens, message_assist_multiple_calls_template, tools,
1078+ " <tool_call>\n "
1079+ " {\" name\" : \" special_function\" , \" arguments\" : {\" arg1\" : 1}}\n "
1080+ " </tool_call>\n "
1081+ " <tool_call>\n "
1082+ " {\" name\" : \" python\" , \" arguments\" : {\" code\" :\" print('test')\" }}\n "
1083+ " </tool_call>" );
1084+
10421085 test_templates (tmpls.get (), end_tokens, message_assist_call_python_lines, tools,
10431086 " <tool_call>\n "
10441087 " {\" name\" : \" python\" , \" arguments\" : {\" code\" :\" # This is a program:\\ nprint('hey')\" }}\n "
0 commit comments