@@ -198,6 +198,24 @@ common_chat_tool special_function_tool {
198198 "required": ["arg1"]
199199 })" ,
200200};
201+ common_chat_tool special_function_tool_with_optional_param {
202+ /* .name = */ " special_function_with_opt" ,
203+ /* .description = */ " I'm special but have optional stuff" ,
204+ /* .parameters = */ R"( {
205+ "type": "object",
206+ "properties": {
207+ "arg1": {
208+ "type": "integer",
209+ "description": "The arg."
210+ },
211+ "arg2": {
212+ "type": "integer",
213+ "description": "The optional arg."
214+ }
215+ },
216+ "required": ["arg1"]
217+ })" ,
218+ };
201219common_chat_tool python_tool {
202220 /* .name = */ " python" ,
203221 /* .description = */ " an ipython interpreter" ,
@@ -226,7 +244,7 @@ common_chat_tool code_interpreter_tool {
226244 "required": ["code"]
227245 })" ,
228246};
229- std::vector<common_chat_tool> tools { special_function_tool, python_tool };
247+ std::vector<common_chat_tool> tools { special_function_tool, special_function_tool_with_optional_param, python_tool };
230248std::vector<common_chat_tool> llama_3_1_tools { special_function_tool, code_interpreter_tool };
231249
232250struct delta_data {
@@ -437,6 +455,8 @@ const common_chat_msg message_assist_thoughts = simple_assist
437455const common_chat_msg message_assist_thoughts_unopened_unparsed = simple_assist_msg(" I'm\n thinking</think>Hello, world!\n What's up?" );
438456const common_chat_msg message_assist_thoughts_no_content = simple_assist_msg(" " , " I'm\n thinking" );
439457const common_chat_msg message_assist_call = simple_assist_msg(" " , " " , " special_function" , " {\" arg1\" : 1}" );
458+ const common_chat_msg message_assist_call_noopt = simple_assist_msg(" " , " " , " special_function_with_opt" , " {\" arg1\" : 1}" );
459+ const common_chat_msg message_assist_call_withopt = simple_assist_msg(" " , " " , " special_function_with_opt" , " {\" arg1\" : 1, \" arg2\" : 2}" );
440460const common_chat_msg message_assist_call_content = simple_assist_msg(" Hello, world!\n What's up?" , " " , " special_function" , " {\" arg1\" :1}" );
441461const common_chat_msg message_assist_call_empty_args = simple_assist_msg(" " , " " , " special_function" );
442462const common_chat_msg message_assist_call_cutoff_args = simple_assist_msg(" " , " " , " special_function" , " {\" arg" );
@@ -2381,6 +2401,21 @@ Hey there!<|im_end|>
23812401 /* ignore_whitespace_differences= */ true
23822402 );
23832403
2404+ // Test template generation for tools with optional parameters
2405+ test_templates (tmpls.get (), end_tokens, message_assist_call_noopt, tools,
2406+ " <minimax:tool_call>\n <invoke name=\" special_function_with_opt\" >\n <parameter name=\" arg1\" >1</parameter>\n </invoke>\n </minimax:tool_call>" ,
2407+ /* expect_grammar_triggered= */ true ,
2408+ /* test_grammar_if_triggered= */ true ,
2409+ /* common_reasoning_format= */ COMMON_REASONING_FORMAT_NONE,
2410+ /* ignore_whitespace_differences= */ true
2411+ );
2412+ test_templates (tmpls.get (), end_tokens, message_assist_call_withopt, tools,
2413+ " <minimax:tool_call>\n <invoke name=\" special_function_with_opt\" >\n <parameter name=\" arg1\" >1</parameter>\n <parameter name=\" arg2\" >2</parameter>\n </invoke>\n </minimax:tool_call>" ,
2414+ /* expect_grammar_triggered= */ true ,
2415+ /* test_grammar_if_triggered= */ true ,
2416+ /* common_reasoning_format= */ COMMON_REASONING_FORMAT_NONE,
2417+ /* ignore_whitespace_differences= */ true
2418+ );
23842419 }
23852420
23862421}
0 commit comments