@@ -37,6 +37,8 @@ struct common_chat_msg {
3737 std::string tool_name;
3838 std::string tool_call_id;
3939
40+ template <class T > T to_json_oaicompat () const ;
41+
4042 bool empty () const {
4143 return content.empty () && content_parts.empty () && tool_calls.empty () && reasoning_content.empty () && tool_name.empty () && tool_call_id.empty ();
4244 }
@@ -54,6 +56,21 @@ struct common_chat_msg {
5456 }
5557};
5658
59+ struct common_chat_msg_diff {
60+ // std::string reasoning_content_delta;
61+ std::string content_delta;
62+ size_t tool_call_index = std::string::npos;
63+ common_chat_tool_call tool_call_delta;
64+
65+ static std::vector<common_chat_msg_diff> compute_diffs (const common_chat_msg & previous_msg, const common_chat_msg & new_msg);
66+
67+ bool operator ==(const common_chat_msg_diff & other) const {
68+ return content_delta == other.content_delta
69+ && tool_call_index == other.tool_call_index
70+ && tool_call_delta == other.tool_call_delta ;
71+ }
72+ };
73+
5774struct common_chat_tool {
5875 std::string name;
5976 std::string description;
@@ -73,14 +90,11 @@ enum common_chat_format {
7390 COMMON_CHAT_FORMAT_LLAMA_3_X,
7491 COMMON_CHAT_FORMAT_LLAMA_3_X_WITH_BUILTIN_TOOLS,
7592 COMMON_CHAT_FORMAT_DEEPSEEK_R1,
76- COMMON_CHAT_FORMAT_DEEPSEEK_R1_EXTRACT_REASONING,
7793 COMMON_CHAT_FORMAT_FIREFUNCTION_V2,
7894 COMMON_CHAT_FORMAT_FUNCTIONARY_V3_2,
7995 COMMON_CHAT_FORMAT_FUNCTIONARY_V3_1_LLAMA_3_1,
8096 COMMON_CHAT_FORMAT_HERMES_2_PRO,
81- COMMON_CHAT_FORMAT_HERMES_2_PRO_EXTRACT_REASONING,
8297 COMMON_CHAT_FORMAT_COMMAND_R7B,
83- COMMON_CHAT_FORMAT_COMMAND_R7B_EXTRACT_REASONING,
8498
8599 COMMON_CHAT_FORMAT_COUNT, // Not a format, just the # formats
86100};
@@ -95,19 +109,26 @@ struct common_chat_templates_inputs {
95109 std::vector<common_chat_tool> tools;
96110 common_chat_tool_choice tool_choice = COMMON_CHAT_TOOL_CHOICE_AUTO;
97111 bool parallel_tool_calls = false ;
98- bool extract_reasoning = true ;
112+ common_reasoning_format reasoning_format = COMMON_REASONING_FORMAT_NONE ;
99113};
100114
101115struct common_chat_params {
102116 common_chat_format format = COMMON_CHAT_FORMAT_CONTENT_ONLY;
103117 std::string prompt;
104118 std::string grammar;
105119 bool grammar_lazy = false ;
120+ bool thinking_forced_open = false ;
106121 std::vector<common_grammar_trigger> grammar_triggers;
107122 std::vector<std::string> preserved_tokens;
108123 std::vector<std::string> additional_stops;
109124};
110125
126+ struct common_chat_reasoning_syntax {
127+ common_reasoning_format format = COMMON_REASONING_FORMAT_NONE;
128+ bool inlined_in_content = false ;
129+ bool thinking_forced_open = false ;
130+ };
131+
111132// Check if the template supplied via "--chat-template" is supported or not. Returns true if it's valid
112133bool common_chat_verify_template (const std::string & tmpl, bool use_jinja);
113134
@@ -145,7 +166,7 @@ std::string common_chat_format_example(
145166 bool use_jinja);
146167
147168std::string common_chat_format_name (common_chat_format format);
148- common_chat_msg common_chat_parse (const std::string & input, common_chat_format format, bool is_partial = false );
169+ common_chat_msg common_chat_parse (const std::string & input, common_chat_format format, bool is_partial = false , const common_chat_reasoning_syntax & reasoning_syntax = {} );
149170
150171common_chat_tool_choice common_chat_tool_choice_parse_oaicompat (const std::string & tool_choice);
151172
@@ -158,18 +179,3 @@ template <class T> T common_chat_msgs_to_json_oaicompat(const std::vector<common
158179// T can be std::string containing JSON or nlohmann::ordered_json
159180template <class T > std::vector<common_chat_tool> common_chat_tools_parse_oaicompat (const T & tools);
160181template <class T > T common_chat_tools_to_json_oaicompat (const std::vector<common_chat_tool> & tools);
161-
162- struct common_chat_msg_diff {
163- // std::string reasoning_content_delta;
164- std::string content_delta;
165- size_t tool_call_index = std::string::npos;
166- common_chat_tool_call tool_call_delta;
167-
168- static std::vector<common_chat_msg_diff> compute_diffs (const common_chat_msg & previous_msg, const common_chat_msg & new_msg);
169-
170- bool operator ==(const common_chat_msg_diff & other) const {
171- return content_delta == other.content_delta
172- && tool_call_index == other.tool_call_index
173- && tool_call_delta == other.tool_call_delta ;
174- }
175- };
0 commit comments