diff --git a/common/chat.cpp b/common/chat.cpp index 694e93c4d4..2ed543df43 100644 --- a/common/chat.cpp +++ b/common/chat.cpp @@ -1617,6 +1617,175 @@ static common_chat_params common_chat_params_init_deepseek_v3_1(const common_cha return data; } +static common_chat_params common_chat_params_init_gigachat_v3( + const common_chat_template & tmpl, + const struct templates_params & inputs) { + + common_chat_params data; + + auto prompt = apply(tmpl, inputs); + data.prompt = prompt; + data.format = COMMON_CHAT_FORMAT_GIGACHAT_V3; + + data.preserved_tokens = { + "<|message_sep|>\n\n", + "<|role_sep|>\n", + }; + + if (inputs.tools.is_array() && !inputs.tools.empty()) { + data.grammar_lazy = inputs.tool_choice != COMMON_CHAT_TOOL_CHOICE_REQUIRED && inputs.json_schema.is_null(); + + data.grammar = build_grammar([&](const common_grammar_builder & builder) { + std::vector rules; + + + foreach_function(inputs.tools, [&](const json & tool) { + const auto & function = tool.at("function"); + std::string name = function.at("name"); + auto parameters = function.at("parameters"); + builder.resolve_refs(parameters); + + // JSON schema for this tool + json schema = { + {"type", "object"}, + {"properties", { + {"name", {{"type", "string"}, {"const", name}}}, + {"arguments", parameters} + }}, + {"required", json::array({"name", "arguments"})} + }; + + // Add a rule for this tool + rules.push_back( + R"("<|message_sep|>\n\nfunction call<|role_sep|>\n")" + + builder.add_schema(name + "-call", schema) + ); + }); + + builder.add_rule("root", + "(" + string_join(rules, " | ") + ")" + + (inputs.parallel_tool_calls ? "*" : "") + ); + + data.grammar_triggers.push_back({ + COMMON_GRAMMAR_TRIGGER_TYPE_WORD, + "<|message_sep|>\n\nfunction call<|role_sep|>\n" + }); + }); + } + + return data; +} + +static void common_chat_parse_gigachat_v3(common_chat_msg_parser & builder) { + if (!builder.syntax().parse_tool_calls) { + builder.add_content(builder.consume_rest()); + return; + } + + // Regex to capture function name from JSON after "function call<|role_sep|\n" + static const common_regex function_regex( + R"(<\|message_sep\|>\n\nfunction call<\|role_sep\|>\n\s*\{\s*\"name\"\s*:\s*\"([^\"]+)\"\s*,\s*\"arguments\"\s*:)" + ); + + // Closing token of a tool call + static const common_regex close_regex( + R"(\}\s*)" + ); + + parse_json_tool_calls( + builder, + /* block_open = */ std::nullopt, + /* function_regex_start_only = */ std::nullopt, + /* function_regex = */ function_regex, + close_regex, + /* block_close = */ std::nullopt + ); +} + + +static void common_chat_parse_deepseek_r1(common_chat_msg_parser & builder) { + builder.try_parse_reasoning("", ""); + if (!builder.syntax().parse_tool_calls) { + builder.add_content(builder.consume_rest()); + return; + } + + static const common_regex tool_calls_begin("(?:<|tool▁calls▁begin|>|<|tool_calls_begin|>|<|tool calls begin|>|<|tool\\\\_calls\\\\_begin|>|<|tool▁calls|>)"); + static const common_regex tool_calls_end("<|tool▁calls▁end|>"); + static const common_regex function_regex("(?:<|tool▁call▁begin|>)?function<|tool▁sep|>([^\n]+)\n```json\n"); + static const common_regex close_regex("```[\\s\\r\\n]*<|tool▁call▁end|>"); + + parse_json_tool_calls( + builder, + /* block_open= */ tool_calls_begin, + /* function_regex_start_only= */ std::nullopt, + function_regex, + close_regex, + tool_calls_end); +} + +static void common_chat_parse_deepseek_v3_1_content(common_chat_msg_parser & builder) { + static const common_regex function_regex("(?:<|tool▁call▁begin|>)?([^\\n<]+)(?:<|tool▁sep|>)"); + + static const common_regex close_regex("(?:[\\s]*)?<|tool▁call▁end|>"); + static const common_regex tool_calls_begin("(?:<|tool▁calls▁begin|>|<|tool_calls_begin|>|<|tool calls begin|>|<|tool\\\\_calls\\\\_begin|>|<|tool▁calls|>)"); + static const common_regex tool_calls_end("<|tool▁calls▁end|>"); + + if (!builder.syntax().parse_tool_calls) { + LOG_DBG("%s: not parse_tool_calls\n", __func__); + builder.add_content(builder.consume_rest()); + return; + } + + LOG_DBG("%s: parse_tool_calls\n", __func__); + + parse_json_tool_calls( + builder, + /* block_open= */ tool_calls_begin, + /* function_regex_start_only= */ std::nullopt, + function_regex, + close_regex, + tool_calls_end); +} + +static void common_chat_parse_deepseek_v3_1(common_chat_msg_parser & builder) { + // DeepSeek V3.1 outputs reasoning content between "" and "" tags, followed by regular content + // First try to parse using the standard reasoning parsing method + LOG_DBG("%s: thinking_forced_open: %s\n", __func__, std::to_string(builder.syntax().thinking_forced_open).c_str()); + + auto start_pos = builder.pos(); + auto found_end_think = builder.try_find_literal(""); + builder.move_to(start_pos); + + if (builder.syntax().thinking_forced_open && !builder.is_partial() && !found_end_think) { + LOG_DBG("%s: no end_think, not partial, adding content\n", __func__); + common_chat_parse_deepseek_v3_1_content(builder); + } else if (builder.try_parse_reasoning("", "")) { + // If reasoning was parsed successfully, the remaining content is regular content + LOG_DBG("%s: parsed reasoning, adding content\n", __func__); + // <|tool▁calls▁begin|><|tool▁call▁begin|>function<|tool▁sep|>NAME\n```json\nJSON\n```<|tool▁call▁end|><|tool▁calls▁end|> + common_chat_parse_deepseek_v3_1_content(builder); + } else { + if (builder.syntax().reasoning_format == COMMON_REASONING_FORMAT_NONE) { + LOG_DBG("%s: reasoning_format none, adding content\n", __func__); + common_chat_parse_deepseek_v3_1_content(builder); + return; + } + // If no reasoning tags found, check if we should treat everything as reasoning + if (builder.syntax().thinking_forced_open) { + // If thinking is forced open but no tags found, treat everything as reasoning + LOG_DBG("%s: thinking_forced_open, adding reasoning content\n", __func__); + builder.add_reasoning_content(builder.consume_rest()); + } else { + LOG_DBG("%s: no thinking_forced_open, adding content\n", __func__); + // <|tool▁call▁begin|>NAME<|tool▁sep|>JSON<|tool▁call▁end|> + common_chat_parse_deepseek_v3_1_content(builder); + } + } +} + + static common_chat_params common_chat_params_init_minimax_m2(const common_chat_template & tmpl, const struct templates_params & params) { common_chat_params data; data.grammar_lazy = params.tools.is_array() && !params.tools.empty() && params.tool_choice != COMMON_CHAT_TOOL_CHOICE_REQUIRED; @@ -2452,10 +2621,6 @@ static common_chat_params common_chat_params_init_seed_oss( return data; } - -common_chat_params_init_gigachat_v3 -common_chat_params_parse_gigachat_v3 - static common_chat_params common_chat_templates_apply_jinja( const struct common_chat_templates * tmpls, const struct common_chat_templates_inputs & inputs) @@ -2607,7 +2772,7 @@ static common_chat_params common_chat_templates_apply_jinja( } // GigaChatV3 format detection - if (src.find("<|role_sep|>\n") != std::string::npos && src.find("<|message_sep|>\n\n") != std::string::npos) { + if (src.find("<|role_sep|>") != std::string::npos && src.find("<|message_sep|>") != std::string::npos) { return common_chat_params_init_gigachat_v3(tmpl, params); } diff --git a/models/templates/GigaChat3-10B-A1.8B.jinja b/models/templates/GigaChat3-10B-A1.8B.jinja new file mode 100644 index 0000000000..5de72822f7 --- /dev/null +++ b/models/templates/GigaChat3-10B-A1.8B.jinja @@ -0,0 +1,357 @@ +{#--------TOOL RENDERING FUNCTIONS---------#} + +{#--------------------------------------------------------------- + Converts JSON Schema (dict) to a TypeScript type definition +----------------------------------------------------------------#} +{%- macro json_schema_to_typescript(schema, indent="", indent_factor=2) -%} + {%- set ADDITIONAL_JSON_KEYS = ['format', 'maxItems', 'maximum', 'minItems', 'minimum', 'pattern'] -%} + {%- set ty = schema.get("type") -%} + + {# ---------------- OBJECT ---------------- #} + {%- if ty == "object" -%} + {{- "{\n" -}} + + {# Start building property list #} + {%- set props = schema.get("properties", {}) -%} + {%- set required = schema.get("required", []) -%} + {%- set has_additional_props = schema.get("additionalProperties") is defined -%} + {%- set additional_props_type = none -%} + {%- if has_additional_props -%} + {%- if schema.additionalProperties == true -%} + {%- set additional_props_type = {'type': 'any'} -%} + {%- elif schema.additionalProperties is mapping -%} + {%- set additional_props_type = schema.additionalProperties -%} + {%- endif -%} + {%- endif -%} + + {%- for key, val in props.items() -%} + {# ---------- Description Comments ---------- #} + {%- if "description" in val -%} + {%- for line in val['description'].split('\n') -%} + {%- if line.strip() -%} + {{- indent + '// ' + line + '\n' -}} + {%- endif -%} + {%- endfor -%} + {%- endif -%} + + {# ---------- Additional JSON Keys ---------- #} + {%- for add_key, add_val in val.items() -%} + {%- if add_key in ADDITIONAL_JSON_KEYS -%} + {%- if add_val is string -%} + {{- indent + '// ' + add_key + ': "' + add_val + '"' + '\n' -}} + {%- else -%} + {{- indent + '// ' + add_key + ': ' ~ add_val ~ '\n' -}} + {%- endif -%} + {%- endif -%} + {%- endfor -%} + + {# ---------- Property Definition ---------- #} + {%- set type_str = json_schema_to_typescript( + val, + indent + (' ' * indent_factor), + indent_factor + ) -%} + + {{- indent + key + ('' if key in required else '?') + ': ' + type_str + ',' -}} + + {%- if "default" in val or "defalut_value" in val -%} + {%- set default = val.get("default", val.get("defalut_value")) -%} + {%- if default is string -%} + {{- ' // default: "' + default + '"' -}} + {%- else -%} + {{- ' // default: ' ~ default -}} + {%- endif -%} + {%- endif -%} + + {{- "\n" -}} + {%- endfor -%} + + {# Handle additionalProperties as index signature #} + {%- if has_additional_props and additional_props_type is not none -%} + {%- set additional_type_str = json_schema_to_typescript( + additional_props_type, + indent + (' ' * indent_factor), + indent_factor + ) -%} + {{- indent + '[key: string]: ' + additional_type_str + '\n' -}} + {%- endif -%} + + {{- indent[:-indent_factor] + '}' -}} + + {# ---------------- STRING ---------------- #} + {%- elif ty == "string" -%} + {%- if schema.get("enum") -%} + {%- set ns = namespace(enum = []) -%} + {%- for en in schema['enum'] -%} + {%- set ns.enum = ns.enum + ['"' ~ en ~ '"'] -%} + {%- endfor -%} + {{- ns.enum | join(' | ') -}} + {%- elif schema.get("format") in ['date-time', 'date'] -%} + {{- 'Date' -}} + {%- else -%} + {{- 'string' -}} + {%- endif -%} + + {# ---------------- NUMBER / INTEGER ---------------- #} + {%- elif ty in ["number", "integer"] -%} + {%- if schema.get("enum") -%} + {{- schema.enum | join(' | ') -}} + {%- else -%} + {{- 'number' -}} + {%- endif -%} + + {# ---------------- BOOLEAN ---------------- #} + {%- elif ty == "boolean" -%} + {{- 'boolean' -}} + + {# ---------------- ARRAY ---------------- #} + {%- elif ty == "array" -%} + {%- if "items" in schema -%} + {{- json_schema_to_typescript(schema['items'], indent, indent_factor) + '[]' -}} + {%- else -%} + {{- 'Array' -}} + {%- endif -%} + + {# ---------------- FALLBACK ---------------- #} + {%- else -%} + {{- 'any' -}} + {%- endif -%} +{%- endmacro -%} + +{#--------------------------------------------------------------- + Renders a namespace and its tool definitions in TypeScript style +----------------------------------------------------------------#} + +{%- macro render_tool_namespace(namespace_name, tools) -%} + {%- set ns = namespace(sections = ['namespace ' ~ namespace_name ~ ' {']) -%} + + {%- for tool in tools -%} + {%- if tool.function -%} + {%- set tool = tool.function -%} + {%- endif -%} + + {%- set ns_tool = namespace(content_lines=[]) -%} + + {# ---------- TOOL DESCRIPTION ---------- #} + {%- if tool.get('description') -%} + {%- for line in tool['description'].split('\n') -%} + {%- if line.strip() -%} + {%- set ns_tool.content_lines = ns_tool.content_lines + ['// ' ~ line] -%} + {%- endif -%} + {%- endfor -%} + {%- endif -%} + + {# ---------- TOOL SIGNATURE ---------- #} + {%- set main_body = "" -%} + {%- set params = tool.get("parameters") -%} + {%- if params and params.get("properties") -%} + {%- set param_type = json_schema_to_typescript(params, " ") -%} + {%- set main_body = 'type ' ~ tool.name ~ ' = (_: ' ~ param_type ~ ') => ' -%} + {%- else -%} + {%- set main_body = 'type ' ~ tool.name ~ ' = () => ' -%} + {%- endif -%} + + {# ---------- RETURN TYPE ---------- #} + {%- set return_params = tool.get("return_parameters") -%} + {%- if return_params and return_params.get("properties") -%} + {%- set return_type = json_schema_to_typescript(return_params, " ") -%} + {%- set main_body = main_body ~ return_type -%} + {%- else -%} + {%- set main_body = main_body ~ 'any' -%} + {%- endif -%} + + {%- set main_body = main_body ~ ';\n' -%} + + {%- set ns_tool.content_lines = ns_tool.content_lines + [main_body] -%} + + {# ---------- ADD TOOL TO SECTIONS ---------- #} + {%- set ns.sections = ns.sections + [ns_tool.content_lines | join('\n')] -%} + {%- endfor -%} + + {%- set ns.sections = ns.sections + ['} // namespace ' ~ namespace_name] -%} + + {{- ns.sections | join('\n') -}} +{%- endmacro -%} + + +{# ----------- MESSAGE RENDERING HELPER FUNCTIONS ------------ #} + +{%- macro render_role_message(message, role=None) -%} + {%- if not role -%} + {%- set role = message["role"] -%} + {%- endif -%} + + {%- set message_content = message['content'] or '' -%} + {%- if message_content is not string -%} + {%- set message_content = message_content | tojson(ensure_ascii=False) -%} + {%- endif -%} + + {{- role + add_tokens.role_sep + message_content + add_tokens.message_sep -}} + +{%- endmacro -%} + + +{%- macro render_function_call(message) -%} + {%- set call = message['content'] -%} + {%- if call.function -%} + {%- set call = call.function -%} + {%- endif -%} + + {%- set arguments = call['arguments'] -%} + {%- if arguments is not string -%} + {%- set arguments = arguments| tojson(ensure_ascii=False) -%} + {%- endif -%} + + {{- render_role_message( + { + 'role': 'function call', + 'content': '{"name": "' ~ call['name'] ~ '", "arguments": ' ~ arguments ~ '}' + } + ) -}} +{%- endmacro -%} + +{# ----- SPECIAL TOKENS ----- #} + +{%- set add_tokens = namespace( + role_sep="<|role_sep|>\n", + message_sep="<|message_sep|>\n\n" +) -%} + +{# ----- DEFAULT DEVSYSTEM ----- #} + +{%- set DEVSYSTEM -%} + +Description of the roles available in the dialog. + +`developer system` +A message added by Sber before the main dialog. It has the highest priority and sets global, non-overridable conditions (for example, conversation rules, the safety policy, the assistant's overall response style, etc.). + +`system` +A system instruction added by developers or by the user, but with a lower priority than `developer system`. It usually describes the assistant's instructions, a specific response style, and other conditions for this particular dialog. + +`user` +A message or request from the user. The assistant follows it if it does not conflict with higher-priority instructions (see ). + +`user memory` +A sequence of the most up-to-date long-term facts about the user at the time of their request, presented as a JSON list of strings. Facts are listed in chronological order, meaning newer facts are appended to the end of the sequence. When facts are changed or deleted, records of previous facts remain in the sequence. The assistant saves facts using a function and uses them in accordance with the block below. + +`added files` +Metadata about files available for use in the dialog, presented in JSON format. It contains the following keys: id (a unique file identifier), name (file name), type (file type). + +`assistant` +The assistant's reply to the user's request. If the system instruction or the user does not set additional rules for `assistant`, this reply must comply with the instructions in the block below. The list of functions available to call is contained in `function descriptions`. The name of the required function and its arguments will be generated next by the `function call` role. In its replies, the assistant follows the instructions in accordance with . + +`function descriptions` +Function descriptions in TypeScript format. A function is a special tool (or a set of instructions) that the assistant can call to perform specific actions, computations, or obtain data needed to solve the user's task. Each function description contains blocks with the name, description, and arguments. Sometimes the description contains separate blocks with return parameters and usage examples that illustrate the correct call and arguments. + +`function call` +The function that `assistant` calls based on the dialog context, and its arguments. The function is invoked in strict accordance with the instructions in the block. + +`function result` +The result of the last function call. + + + +The assistant can work with the following modalities: text, available functions. + + + +If instructions from different roles conflict within the dialog context, observe the following priorities: +`developer system` > `system` > `user` > `function descriptions` > `function result` > `user memory` + + + +Basic instructions for working with functions. + +Only call those functions that are described in `function descriptions`. + +Call available functions when, according to their description, such a call will help provide a more complete and/or accurate answer to the user's request. Fill in function arguments using information from the dialog context. If a function could help answer the request but a required argument is missing from the context, ask the user for the missing data before calling the function. If a necessary function is unavailable or an error occurs, briefly inform the user and, if possible, suggest an alternative. + + + +Rules for using facts in long-term memory: + +If there is no message under the `user memory` role in the dialog, this is equivalent to the absence of long-term facts about the user in memory. In that case, information about the user is limited to the current dialog, and no new facts should be saved. + + + +You are a helpful assistant. + +# Instructions +- Strictly follow the instruction priority. +- Maintain a logical chain of reasoning when answering the user's question. +- For complex questions (for example, STEM), try to answer in detail unless the system message or dialog context limits the response length. +- Be helpful, truthful, and avoid unsafe or prohibited content in your responses. +- Try to reply in the language in which the user asked their question. + + +A dialog will follow below. +The dialog may include various roles described in the block. +Each turn begins with the role name and a special token that marks the end of the role's full name, and ends with a special end-of-turn token. +Your task is to continue the dialog from the last specified role in accordance with the dialog context. +{%- endset -%} + + +{#- ---------------------- RENDERING STARTS HERE ---------------------- -#} + + +{# ----- RENDER BOS TOKEN ----- #} +{{- bos_token -}} + + +{# ----- RENDER DEVSYSTEM ----- #} +{{- render_role_message({"role": "developer system", "content": DEVSYSTEM}) -}} + +{# ----- RENDER SYSTEM IF PRESENT ----- #} +{%- if messages and messages[0]['role'] == 'system' -%} + {{- render_role_message(messages[0]) -}} + {%- set messages = messages[1:] -%} +{%- endif -%} + +{# ----- RENDER TOOLS ----- #} +{%- if tools -%} + {%- set tools_content = ( + render_tool_namespace('functions', tools) + + "\n\n" + ) -%} + {{- render_role_message({'role': 'function descriptions', 'content': tools_content}) -}} +{%- endif -%} + +{# ----- MAIN MESSAGE LOOP ----- #} +{%- for message in messages -%} + + {# ----- TOOL MESSAGE -------#} + {%- if message['role'] == 'tool' -%} + {{- render_role_message(message, role='function result') -}} + + + {# ----- ASSISTANT MESSAGE ----- #} + {%- elif message['role'] == 'assistant' -%} + + {# ----- FUNCTION CALL PART CHECKING: SINGLE CALL SETUP ----- #} + {%- if message.tool_calls is defined and message.tool_calls -%} + {%- set function_call = message.tool_calls[0] -%} + {%- else -%} + {%- set function_call = None -%} + {%- endif -%} + + {# ----- MAIN ASSISTANT RENDERING ----- #} + + {{- render_role_message({'role': 'assistant', 'content': message.content}) -}} + {%- if function_call -%} + {{- render_function_call({'role': 'function call', 'content': function_call}) -}} + {%- endif -%} + + + {# ----- OTHER MESSAGES ----- #} + {%- else -%} + {{- render_role_message(message) -}} + {%- endif -%} + + {# ----- ADDING GENERATION PROMPT ----- #} + + {%- if loop.last and add_generation_prompt and message['role'] != 'assistant' -%} + {{- 'assistant' + add_tokens.role_sep -}} + {%- endif -%} + +{%- endfor -%} diff --git a/tests/test-chat.cpp b/tests/test-chat.cpp index 007929f517..9408b54541 100644 --- a/tests/test-chat.cpp +++ b/tests/test-chat.cpp @@ -3501,6 +3501,7 @@ Hey there!<|im_end|> } } +<<<<<<< HEAD static void test_template_output_peg_parsers() { printf("[%s]\n", __func__); @@ -3588,6 +3589,76 @@ static void test_template_output_peg_parsers() { t.expect.content =R"({"amount": 123.45, "date": "2025-12-03"})"; }); } +======= + { + auto tmpls = read_templates("models/templates/GigaChat3-10B-A1.8B.jinja"); + std::vector end_tokens{ "", "<|message_sep|>\n\n" }; + + assert_equals(COMMON_CHAT_FORMAT_GIGACHAT_V3, common_chat_templates_apply(tmpls.get(), inputs_no_tools).format); + assert_equals(COMMON_CHAT_FORMAT_GIGACHAT_V3, common_chat_templates_apply(tmpls.get(), inputs_tools).format); + + // Test parsing regular content + assert_msg_equals(message_assist, + common_chat_parse( + "Hello, world!\nWhat's up?", + /* is_partial= */ false, + {COMMON_CHAT_FORMAT_GIGACHAT_V3})); + + // Test parsing tool calls + assert_msg_equals(message_assist_call, + common_chat_parse( + "<|message_sep|>\n\nfunction call<|role_sep|>\n{\"name\": \"special_function\", \"arguments\": {\"arg1\": 1}}", + /* is_partial= */ false, + {COMMON_CHAT_FORMAT_GIGACHAT_V3})); + + // Test tool calls with extra content + assert_msg_equals(message_assist_call_content, + common_chat_parse( + "Hello, world!\nWhat's up?<|message_sep|>\n\nfunction call<|role_sep|>\n{\"name\": \"special_function\", \"arguments\": {\"arg1\": 1}}", + /* is_partial= */ false, + {COMMON_CHAT_FORMAT_GIGACHAT_V3} + )); + + // Test streaming + test_parser_with_streaming(message_assist_call_withopt, + "<|message_sep|>\n\nfunction call<|role_sep|>\n{\"name\": \"special_function_with_opt\", \"arguments\": {\"arg1\": 1, \"arg2\": 2}}", + [&](const std::string &msg) { return common_chat_parse(msg, /* is_partial= */ true, { + /* .format = */ COMMON_CHAT_FORMAT_GIGACHAT_V3, + /* .reasoning_format = */ COMMON_REASONING_FORMAT_NONE + }); }); + + // Test template generation for regular content + test_templates(tmpls.get(), end_tokens, message_assist, tools, + "Hello, world!\nWhat's up?", + /* expect_grammar_triggered= */ false); + + // Test template generation for tool calls + test_templates(tmpls.get(), end_tokens, message_assist_call, tools, + "<|message_sep|>\n\nfunction call<|role_sep|>\n{\"name\": \"special_function\", \"arguments\": {\"arg1\": 1}}", + /* expect_grammar_triggered= */ true, + /* test_grammar_if_triggered= */ true, + /* common_reasoning_format= */ COMMON_REASONING_FORMAT_NONE, + /* ignore_whitespace_differences= */ true + ); + + // Test template generation for tools with optional parameters + test_templates(tmpls.get(), end_tokens, message_assist_call_noopt, tools, + "<|message_sep|>\n\nfunction call<|role_sep|>\n{\"name\": \"special_function_with_opt\", \"arguments\": {\"arg1\": 1}}", + /* expect_grammar_triggered= */ true, + /* test_grammar_if_triggered= */ true, + /* common_reasoning_format= */ COMMON_REASONING_FORMAT_NONE, + /* ignore_whitespace_differences= */ true + ); + test_templates(tmpls.get(), end_tokens, message_assist_call_withopt, tools, + "<|message_sep|>\n\nfunction call<|role_sep|>\n{\"name\": \"special_function_with_opt\", \"arguments\": {\"arg1\": 1, \"arg2\": 2}}", + /* expect_grammar_triggered= */ true, + /* test_grammar_if_triggered= */ true, + /* common_reasoning_format= */ COMMON_REASONING_FORMAT_NONE, + /* ignore_whitespace_differences= */ true + ); + } + +>>>>>>> 6f9ffbd9d (implement gigachat v3 toolcall parser) } static void test_msg_diffs_compute() {