@@ -95,34 +95,34 @@ class partial_formatter {
9595 output_type type;
9696 };
9797
98- partial_formatter (const common_chat_syntax & syntax) : syntax_ (syntax), had_reasoning_ (false ) {}
98+ partial_formatter (const common_chat_syntax & syntax) : syntax (syntax), had_reasoning (false ) {}
9999
100100 std::vector<output> operator ()(const std::string & accumulated) {
101- common_chat_msg next = common_chat_parse (accumulated, true , syntax_ );
101+ common_chat_msg next = common_chat_parse (accumulated, true , syntax );
102102
103- auto diffs = common_chat_msg_diff::compute_diffs (previous_ , next);
103+ auto diffs = common_chat_msg_diff::compute_diffs (previous , next);
104104 std::vector<output> result;
105105 for (const auto & diff : diffs) {
106106 if (!diff.reasoning_content_delta .empty ()) {
107107 result.push_back ({diff.reasoning_content_delta , REASONING});
108- had_reasoning_ = true ;
108+ had_reasoning = true ;
109109 }
110110 if (!diff.content_delta .empty ()) {
111- if (had_reasoning_ ) {
111+ if (had_reasoning ) {
112112 result.push_back ({" \n " , REASONING});
113- had_reasoning_ = false ;
113+ had_reasoning = false ;
114114 }
115115 result.push_back ({diff.content_delta , CONTENT});
116116 }
117117 }
118- previous_ = next;
118+ previous = next;
119119 return result;
120120 }
121121
122122private:
123- common_chat_syntax syntax_ ;
124- common_chat_msg previous_ ;
125- bool had_reasoning_ ;
123+ common_chat_syntax syntax ;
124+ common_chat_msg previous ;
125+ bool had_reasoning ;
126126};
127127
128128class chat_formatter {
@@ -131,77 +131,77 @@ class chat_formatter {
131131 std::vector<common_chat_msg> & chat_msgs,
132132 const common_chat_templates_ptr & chat_templates,
133133 const common_params & params)
134- : chat_msgs_ (chat_msgs),
135- chat_templates_ (chat_templates),
136- params_ (params) {}
134+ : chat_msgs (chat_msgs),
135+ chat_templates (chat_templates),
136+ params (params) {}
137137
138138 std::string operator ()(const std::string & role, const std::string & content) {
139139 if (role == " user" ) {
140- formatted_cumulative_ .clear (); // Needed if template strips reasoning
140+ formatted_cumulative .clear (); // Needed if template strips reasoning
141141 }
142142
143143 common_chat_msg new_msg;
144- if (syntax_ ) {
145- new_msg = common_chat_parse (content, false , *syntax_ );
144+ if (syntax ) {
145+ new_msg = common_chat_parse (content, false , *syntax );
146146 } else {
147147 new_msg.content = content;
148148 }
149149 new_msg.role = role;
150150
151- chat_msgs_ .push_back (new_msg);
151+ chat_msgs .push_back (new_msg);
152152
153153 common_chat_templates_inputs cinputs;
154- cinputs.messages .assign (chat_msgs_ .cbegin (), chat_msgs_ .cend ());
155- cinputs.use_jinja = params_ .use_jinja ;
154+ cinputs.messages .assign (chat_msgs .cbegin (), chat_msgs .cend ());
155+ cinputs.use_jinja = params .use_jinja ;
156156 cinputs.add_generation_prompt = (role == " user" );
157- cinputs.reasoning_format = params_ .reasoning_format ;
157+ cinputs.reasoning_format = params .reasoning_format ;
158158
159159 cinputs.enable_thinking =
160- params_ .use_jinja &&
161- params_ .reasoning_budget != 0 &&
162- common_chat_templates_support_enable_thinking (chat_templates_ .get ());
163-
164- common_chat_params cparams = common_chat_templates_apply (chat_templates_ .get (), cinputs);
165-
166- if (!syntax_ ) {
167- syntax_ .reset (new common_chat_syntax);
168- syntax_ ->format = cparams.format ;
169- syntax_ ->reasoning_format = params_ .reasoning_format ;
170- syntax_ ->thinking_forced_open = cparams.thinking_forced_open ;
171- syntax_ ->parse_tool_calls = false ;
160+ params .use_jinja &&
161+ params .reasoning_budget != 0 &&
162+ common_chat_templates_support_enable_thinking (chat_templates .get ());
163+
164+ common_chat_params cparams = common_chat_templates_apply (chat_templates .get (), cinputs);
165+
166+ if (!syntax ) {
167+ syntax .reset (new common_chat_syntax);
168+ syntax ->format = cparams.format ;
169+ syntax ->reasoning_format = params .reasoning_format ;
170+ syntax ->thinking_forced_open = cparams.thinking_forced_open ;
171+ syntax ->parse_tool_calls = false ;
172172 }
173173
174- bool use_partial_formatter = params_ .reasoning_format != COMMON_REASONING_FORMAT_NONE;
175- if (!partial_formatter_ptr_ && use_partial_formatter) {
176- partial_formatter_ptr_ = std::make_unique<partial_formatter>(*syntax_ );
174+ bool use_partial_formatter = params .reasoning_format != COMMON_REASONING_FORMAT_NONE;
175+ if (!partial_formatter_ptr && use_partial_formatter) {
176+ partial_formatter_ptr = std::make_unique<partial_formatter>(*syntax );
177177 }
178178
179179 std::string formatted;
180- if (formatted_cumulative_ .size () > cparams.prompt .size ()) {
180+ if (formatted_cumulative .size () > cparams.prompt .size ()) {
181181 LOG_WRN (" template cumulative size was reduced from \" %zu\" to \" %zu\" "
182182 " likely due to template's removal of message reasoning.\n " ,
183- formatted_cumulative_ .size (), cparams.prompt .size ());
183+ formatted_cumulative .size (), cparams.prompt .size ());
184184
185185 } else {
186- formatted = cparams.prompt .substr (formatted_cumulative_ .size ());
186+ formatted = cparams.prompt .substr (formatted_cumulative .size ());
187187 }
188188
189- formatted_cumulative_ = cparams.prompt ;
189+ formatted_cumulative = cparams.prompt ;
190190
191191 LOG_DBG (" formatted: '%s'\n " , formatted.c_str ());
192192 return formatted;
193193 }
194194
195- partial_formatter * get_partial_formatter () { return partial_formatter_ptr_ .get (); }
196- const std::string & get_full_prompt () const { return formatted_cumulative_ ; }
195+ partial_formatter * get_partial_formatter () { return partial_formatter_ptr .get (); }
196+ const std::string & get_full_prompt () const { return formatted_cumulative ; }
197197
198198private:
199- std::vector<common_chat_msg> & chat_msgs_ ;
200- const common_chat_templates_ptr & chat_templates_ ;
201- const common_params & params_ ;
202- std::unique_ptr<common_chat_syntax> syntax_ ;
203- std::unique_ptr<partial_formatter> partial_formatter_ptr_ ;
204- std::string formatted_cumulative_ ;
199+ std::vector<common_chat_msg> & chat_msgs ;
200+ const common_chat_templates_ptr & chat_templates ;
201+ const common_params & params ;
202+ std::unique_ptr<common_chat_syntax> syntax ;
203+ std::unique_ptr<partial_formatter> partial_formatter_ptr ;
204+ std::string formatted_cumulative ;
205205};
206206
207207int main (int argc, char ** argv) {
0 commit comments