@@ -2339,30 +2339,26 @@ static common_chat_params common_chat_params_init_hermes_2_pro(const common_chat
23392339 " ( \" ```\\ n\" | \" ```json\\ n\" | \" ```xml\\ n\" ) space " + wrappable_tool_call + " space \" ```\" space " );
23402340 auto tool_call = builder.add_rule (" tool_call" , string_join (tool_call_alts, " | " ));
23412341
2342- builder.add_rule (" thinking-start" , " \" <think>\" " );
2343- builder.add_rule (" thinking-content" , " ( [^<] | \" <\" [^/] | \" </\" [^t] | \" </t\" [^h] | \" </th\" [^i] | \" </thi\" [^n] | \" </thin\" [^k] | \" </think\" [^>] )*" );
2344- builder.add_rule (" thinking-end" , " \" </think>\" space" );
2345-
2346- // thinking grammar logic depending on if thinking_forced_open was to true (so already opened (and maybe closed)) and if thinking is even allowed
2347- std::string thinking_grammar_logic = " " ; // thinking tag was closed or not supported/wanted
2342+ // thinking grammar logic depending on if thinking_forced_open was to true (so already opened (and maybe closed)) and if thinking is even allowed
23482343 if (extra_context[" enable_thinking" ]) {
23492344 data.grammar_triggers .push_back ({
23502345 COMMON_GRAMMAR_TRIGGER_TYPE_WORD,
23512346 data.thinking_forced_open ? " </think>" : " <think>"
23522347 });
2353- if (data.thinking_forced_open ) {
2354- // thinking tag was already opened by used so we don't need to add it again
2355- thinking_grammar_logic = " (thinking-content thinking-end) " ;
2356- }
2357- else
2358- {
2359- thinking_grammar_logic = " (thinking-start thinking-content thinking-end) " ;
2348+ std::string prelude = " " ;
2349+ if (!data.thinking_forced_open ) {
2350+ prelude = builder.add_rule (" think-start" , " \" <think>\" " );
23602351 }
2352+ prelude += " " ;
2353+ prelude += builder.add_rule (" think-content" , " ( [^<] | \" <\" [^/] | \" </\" [^t] | \" </t\" [^h] | \" </th\" [^i] | \" </thi\" [^n] | \" </thin\" [^k] | \" </think\" [^>] )*" );
2354+ prelude += " " ;
2355+ prelude += builder.add_rule (" think-end" , " \" </think>\" space" );
2356+ prelude += " " ;
2357+ builder.add_rule (" root" , prelude + " (" + tool_call + " )" + (inputs.parallel_tool_calls ? " *" : " ?" ));
2358+ } else {
2359+ builder.add_rule (" root" , inputs.parallel_tool_calls ? " (" + tool_call + " )+" : tool_call);
23612360 }
23622361
2363-
2364- builder.add_rule (" root" , thinking_grammar_logic + (inputs.parallel_tool_calls ? " (" + tool_call + " )+" : tool_call));
2365-
23662362 // Trigger on some common known "good bad" outputs (only from the start and with a json that's about a specific argument name to avoid false positives)
23672363 data.grammar_triggers .push_back ({
23682364 COMMON_GRAMMAR_TRIGGER_TYPE_PATTERN_FULL,
0 commit comments