1616#include < vector>
1717
1818
19- static const common_regex default_start_think_regex (" <think>" , /* at_start= */ true );
19+ static const common_regex default_start_think_regex (" <think>" );
2020static const common_regex default_end_think_regex (" </think>" );
2121
2222static std::string string_diff (const std::string & last, const std::string & current) {
@@ -915,13 +915,13 @@ static common_chat_params common_chat_params_init_command_r7b(const common_chat_
915915}
916916
917917static void common_chat_parse_command_r7b (common_chat_msg_parser & builder) {
918- static const common_regex start_thinking_regex (" <\\ |START_THINKING\\ |>" , /* at_start= */ true );
918+ static const common_regex start_thinking_regex (" <\\ |START_THINKING\\ |>" );
919919 static const common_regex end_thinking_regex (" <\\ |END_THINKING\\ |>" );
920920
921921 builder.try_consume_think_tags (start_thinking_regex, end_thinking_regex);
922922
923923 static const common_regex start_action_regex (" <\\ |START_ACTION\\ |>" );
924- static const common_regex end_action_regex (" <\\ |END_ACTION\\ |>" , /* at_start= */ true );
924+ static const common_regex end_action_regex (" <\\ |END_ACTION\\ |>" );
925925 static const common_regex start_response_regex (" <\\ |START_RESPONSE\\ |>" );
926926 static const common_regex end_response_regex (" <\\ |END_RESPONSE\\ |>" );
927927
@@ -1048,12 +1048,12 @@ static common_chat_params common_chat_params_init_llama_3_1_tool_calls(const com
10481048}
10491049static void common_chat_parse_llama_3_1 (common_chat_msg_parser & builder, bool with_builtin_tools = false ) {
10501050 static const common_regex function_regex (
1051- " \\ s*\\ {\\ s*(?:\" type\"\\ s*:\\ s*\" function\"\\ s*,\\ s*)?\" name\"\\ s*:\\ s*\" ([^\" ]+)\"\\ s*,\\ s*\" parameters\"\\ s*: " , /* at_start= */ true );
1052- static const common_regex close_regex (" \\ }\\ s*" , /* at_start= */ true );
1053- static const common_regex builtin_call_regex (" <\\ |python_tag\\ |>" , /* at_start= */ true );
1051+ " \\ s*\\ {\\ s*(?:\" type\"\\ s*:\\ s*\" function\"\\ s*,\\ s*)?\" name\"\\ s*:\\ s*\" ([^\" ]+)\"\\ s*,\\ s*\" parameters\"\\ s*: " );
1052+ static const common_regex close_regex (" \\ }\\ s*" );
1053+ static const common_regex builtin_call_regex (" <\\ |python_tag\\ |>" );
10541054
1055- static const common_regex function_name_regex (" \\ s*(\\ w+)\\ s*\\ .\\ s*call\\ (" , /* at_start= */ true );
1056- static const common_regex arg_name_regex (" \\ s*(\\ w+)\\ s*=\\ s*" , /* at_start= */ true );
1055+ static const common_regex function_name_regex (" \\ s*(\\ w+)\\ s*\\ .\\ s*call\\ (" );
1056+ static const common_regex arg_name_regex (" \\ s*(\\ w+)\\ s*=\\ s*" );
10571057
10581058 if (with_builtin_tools) {
10591059 if (auto res = builder.try_find_regex (builtin_call_regex)) {
@@ -1164,9 +1164,9 @@ static void common_chat_parse_deepseek_r1(common_chat_msg_parser & builder) {
11641164 builder.try_consume_think_tags (default_start_think_regex, default_end_think_regex);
11651165
11661166 static const common_regex tool_calls_begin (" [\\ s\\ r\\ n]*(?:<|tool▁calls▁begin|>|<|tool_calls_begin|>|<|tool calls begin|>|<|tool\\\\ _calls\\\\ _begin|>)" );
1167- static const common_regex tool_calls_end (" <|tool▁calls▁end|>" , /* at_start= */ true );
1168- static const common_regex function_regex (" <|tool▁call▁begin|>function<|tool▁sep|>([^\n ]+)\n ```json\n " , /* at_start= */ true );
1169- static const common_regex close_regex (" ```[\\ s\\ r\\ n]*<|tool▁call▁end|>" , /* at_start= */ true );
1167+ 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 " );
1169+ 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);
11721172}
@@ -1272,7 +1272,7 @@ static common_chat_params common_chat_params_init_functionary_v3_2(const common_
12721272}
12731273static void common_chat_parse_functionary_v3_2 (common_chat_msg_parser & builder) {
12741274 static const common_regex function_regex (R"( (>>>)?(\w+\n\{|python\n|all\n))" );
1275- static const common_regex close_regex (R"( \s*)" , /* at_start= */ true );
1275+ static const common_regex close_regex (R"( \s*)" );
12761276
12771277 parse_json_tool_calls (builder, std::nullopt , function_regex, close_regex, std::nullopt , /* allow_raw_python= */ true ,
12781278 /* get_function_name= */ [&](const auto & res) -> std::string {
@@ -1351,7 +1351,7 @@ static common_chat_params common_chat_params_init_functionary_v3_1_llama_3_1(con
13511351}
13521352static void common_chat_parse_functionary_v3_1_llama_3_1 (common_chat_msg_parser & builder) {
13531353 // This version of Functionary still supports the llama 3.1 tool call format for the python tool.
1354- static const common_regex python_tag_regex (regex_escape (" <|python_tag|>" ), /* at_start= */ true );
1354+ static const common_regex python_tag_regex (regex_escape (" <|python_tag|>" ));
13551355
13561356 if (auto res = builder.try_find_regex (python_tag_regex)) {
13571357 builder.add_content (res->prelude );
@@ -1368,8 +1368,8 @@ static void common_chat_parse_functionary_v3_1_llama_3_1(common_chat_msg_parser
13681368 return ;
13691369 }
13701370
1371- static const common_regex function_regex (R"( <function=(\w+)>)" , /* at_start= */ true );
1372- static const common_regex close_regex (R"( </function>)" , /* at_start= */ true );
1371+ static const common_regex function_regex (R"( <function=(\w+)>)" );
1372+ static const common_regex close_regex (R"( </function>)" );
13731373
13741374 parse_json_tool_calls (builder, std::nullopt , function_regex, close_regex, std::nullopt );
13751375}
@@ -1490,9 +1490,8 @@ static void common_chat_parse_hermes_2_pro(common_chat_msg_parser & builder) {
14901490 " )"
14911491 " |"
14921492 " (?:<function=([^>]+)>" // match 4 (function name)
1493- " |<function name=\" ([^\" ]+)\" >)" // match 5 (function name again)
1494- " ([\\ s\\ S]*)" , // match 6 (function arguments + rest)})"
1495- /* at_start= */ true
1493+ " |<function name=\" ([^\" ]+)\" >)" // match 5 (function name again)
1494+ " ([\\ s\\ S]*)" // match 6 (function arguments + rest)})"
14961495 );
14971496
14981497 if (auto res = builder.try_find_regex (open_regex)) {
0 commit comments