@@ -1130,22 +1130,22 @@ static common_chat_params common_chat_params_init_deepseek_r1(const common_chat_
11301130 auto parameters = function.at (" parameters" );
11311131 builder.resolve_refs (parameters);
11321132 tool_rules.push_back (builder.add_rule (name + " -call" ,
1133- " \" <|tool▁call▁begin|>function<|tool▁sep|>" + name + " \\ n"
1133+ " ( \" <|tool▁call▁begin|>\" )? \" function<|tool▁sep|>" + name + " \\ n"
11341134 " ```json\\ n\" " + builder.add_schema (name + " -args" , parameters) + " "
11351135 " \" ```<|tool▁call▁end|>\" " ));
11361136 });
11371137 // Distill Qwen 7B & 32B models seem confused re/ syntax of their tool call opening tag,
11381138 // so we accept common variants (then it's all constrained)
11391139 builder.add_rule (" root" ,
11401140 std::string (data.thinking_forced_open ? " \" </think>\" space " : " " ) +
1141- " ( \" <|tool▁calls▁begin|>\" | \" <|tool_calls_begin|>\" | \" <|tool calls begin|>\" | \" <|tool\\\\ _calls\\\\ _begin|>\" ) "
1141+ " ( \" <|tool▁calls▁begin|>\" | \" <|tool_calls_begin|>\" | \" <|tool calls begin|>\" | \" <|tool\\\\ _calls\\\\ _begin|>\" | \" <|tool▁calls|> \" ) "
11421142 " (" + string_join (tool_rules, " | " ) + " )" + (inputs.parallel_tool_calls ? " *" : " " ) + " "
11431143 " \" <|tool▁calls▁end|>\" "
11441144 " space" );
11451145 data.grammar_triggers .push_back ({
11461146 COMMON_GRAMMAR_TRIGGER_TYPE_PATTERN_FULL,
11471147 std::string (data.thinking_forced_open ? " [\\ s\\ S]*?</think>" : " (?:<think>[\\ s\\ S]*?</think>)?" ) +
1148- " \\ s*(<|tool▁calls▁begin|>|<|tool_calls_begin|>|<|tool calls begin|>|<|tool\\\\ _calls\\\\ _begin|>)[\\ s\\ S]*"
1148+ " \\ s*(<|tool▁calls▁begin|>|<|tool_calls_begin|>|<|tool calls begin|>|<|tool\\\\ _calls\\\\ _begin|>|<|tool▁calls|> )[\\ s\\ S]*"
11491149 });
11501150 data.preserved_tokens = {
11511151 " <think>" ,
@@ -1163,9 +1163,9 @@ static common_chat_params common_chat_params_init_deepseek_r1(const common_chat_
11631163static void common_chat_parse_deepseek_r1 (common_chat_msg_parser & builder) {
11641164 builder.try_parse_reasoning (" <think>" , " </think>" );
11651165
1166- static const common_regex tool_calls_begin (" [\\ s\\ r\\ n]*(?:<|tool▁calls▁begin|>|<|tool_calls_begin|>|<|tool calls begin|>|<|tool\\\\ _calls\\\\ _begin|>)" );
1166+ static const common_regex tool_calls_begin (" [\\ s\\ r\\ n]*(?:<|tool▁calls▁begin|>|<|tool_calls_begin|>|<|tool calls begin|>|<|tool\\\\ _calls\\\\ _begin|>|<|tool▁calls|> )" );
11671167 static const common_regex tool_calls_end (" <|tool▁calls▁end|>" );
1168- static const common_regex function_regex (" <|tool▁call▁begin|>function<|tool▁sep|>([^\n ]+)\n ```json\n " );
1168+ static const common_regex function_regex (" (?: <|tool▁call▁begin|>)? function<|tool▁sep|>([^\n ]+)\n ```json\n " );
11691169 static const common_regex close_regex (" ```[\\ s\\ r\\ n]*<|tool▁call▁end|>" );
11701170
11711171 parse_json_tool_calls (builder, tool_calls_begin, function_regex, close_regex, tool_calls_end);
0 commit comments