@@ -304,7 +304,7 @@ inline std::string format_chat(const struct llama_model * model, const std::stri
304304 std::vector<common_chat_msg> chat;
305305 std::string formatted_chat;
306306
307- bool is_custom = !prefix.empty () || !suffix.empty ();
307+ bool is_custom = tmpl. empty () && ( !prefix.empty () || !suffix.empty () );
308308
309309 for (size_t i = 0 ; i < messages.size (); ++i) {
310310 const auto & curr_msg = messages[i];
@@ -337,7 +337,13 @@ inline std::string format_chat(const struct llama_model * model, const std::stri
337337 }
338338 }
339339
340- if (!is_custom) formatted_chat = common_chat_apply_template (model, tmpl, chat, true );
340+ if (!is_custom) {
341+ LOG_WRN (" Using '%s' template, prefix and suffix are ignored.\n " , tmpl.c_str ());
342+ formatted_chat = common_chat_apply_template (model, tmpl, chat, true );
343+ } else {
344+ LOG_WRN (" Used prefix '%s' and suffix '%s'.\n " , prefix.c_str (), suffix.c_str ());
345+ }
346+
341347 LOG_DBG (" formatted_chat using '%s': '%s'\n " , tmpl.c_str (), formatted_chat.c_str ());
342348
343349 return formatted_chat;
@@ -353,7 +359,7 @@ inline std::string format_chat_example(const struct llama_model * model, const s
353359
354360 std::string formatted_example;
355361
356- if (!prefix.empty () || !suffix.empty ()) {
362+ if (tmpl. empty () && ( !prefix.empty () || !suffix.empty () )) {
357363 for (auto message : msgs) {
358364 if (message.role == " user" ) formatted_example += prefix + message.content + suffix;
359365 else formatted_example += message.content ;
@@ -640,20 +646,12 @@ static json oaicompat_completion_params_parse(
640646 std::string prefix = (body.contains (" input_prefix" ) ? body.at (" input_prefix" ).get <std::string>() : " " );
641647 std::string suffix = (body.contains (" input_suffix" ) ? body.at (" input_suffix" ).get <std::string>() : " " );
642648
643- // if template is sent in data, ignore prefix and suffix
644- if (!chat_tmpl.empty ()) {
645- LOG_WRN (" \n Using '%s' template, prefix and suffix are ignored.\n " , chat_tmpl.c_str ());
646- prefix = " " ;
647- suffix = " " ;
648- } else {
649- if (prefix.empty ()) {
650- prefix = input_prefix;
651- }
649+ if (prefix.empty ()) {
650+ prefix = input_prefix;
651+ }
652652
653- if (suffix.empty ()) {
654- suffix = input_suffix;
655- }
656- LOG_WRN (" \n Using prefix '%s' and suffix '%s'.\n " , prefix.c_str (), suffix.c_str ());
653+ if (suffix.empty ()) {
654+ suffix = input_suffix;
657655 }
658656
659657 llama_params[" prompt" ] = format_chat (model, chat_tmpl, prefix, suffix, body.at (" messages" ));
0 commit comments