#pragma once #include "chat.h" #include #include #include #include // Sample config: // MiniMax-M2 (left): \n\nvalue\n...\n... // GLM 4.5 (right): function_name\nkey\nvalue\n struct xml_tool_call_format { std::string scope_start; // \n // \n // can be empty std::string tool_start; // std::string tool_sep; // \">\n // \n // can be empty only for parse_xml_tool_calls std::string key_start; // std::string key_val_sep; // \"> // \n std::string val_end; // \n // \n std::string tool_end; // \n // \n std::string scope_end; // // // can be empty // Set this if there can be dynamic spaces inside key_val_sep. // e.g. key_val_sep= key_val_sep2= for GLM4.5 std::optional key_val_sep2 = std::nullopt; // Set true if argval should only be raw string. e.g. Hello "world" hi // Set false if argval should only be json string. e.g. "Hello \"world\" hi" // Defaults to std::nullopt, both will be allowed. std::optional raw_argval = std::nullopt; std::optional last_val_end = std::nullopt; std::optional last_tool_end = std::nullopt; bool trim_raw_argval = false; bool allow_toolcall_in_think = false; // TODO: UNTESTED!!! }; // make a GBNF that accept any strings except those containing any of the forbidden strings. std::string make_gbnf_excluding(std::vector forbids); /** * Build grammar for xml-style tool call * form.scope_start and form.scope_end can be empty. * Requires data.format for model-specific hacks. */ void build_grammar_xml_tool_call(common_chat_params & data, const nlohmann::ordered_json & tools, const struct xml_tool_call_format & form);