@@ -1014,16 +1014,19 @@ bool gpt_params_find_arg(int argc, char ** argv, const std::string & arg, gpt_pa
1014
1014
}
1015
1015
if (arg == " --in-prefix-bos" ) {
1016
1016
params.input_prefix_bos = true ;
1017
+ params.enable_chat_template = false ;
1017
1018
return true ;
1018
1019
}
1019
1020
if (arg == " --in-prefix" ) {
1020
1021
CHECK_ARG
1021
1022
params.input_prefix = argv[i];
1023
+ params.enable_chat_template = false ;
1022
1024
return true ;
1023
1025
}
1024
1026
if (arg == " --in-suffix" ) {
1025
1027
CHECK_ARG
1026
1028
params.input_suffix = argv[i];
1029
+ params.enable_chat_template = false ;
1027
1030
return true ;
1028
1031
}
1029
1032
if (arg == " --spm-infill" ) {
@@ -1406,7 +1409,7 @@ void gpt_params_print_usage(int /*argc*/, char ** argv, const gpt_params & param
1406
1409
" halt generation at PROMPT, return control in interactive mode\n "
1407
1410
" can be specified more than once for multiple prompts" });
1408
1411
options.push_back ({ " main" , " -sp, --special" , " special tokens output enabled (default: %s)" , params.special ? " true" : " false" });
1409
- options.push_back ({ " main" , " -cnv, --conversation" , " run in conversation mode (does not print special tokens and suffix/prefix) (default: %s)" , params.conversation ? " true" : " false" });
1412
+ options.push_back ({ " main" , " -cnv, --conversation" , " run in conversation mode (does not print special tokens and suffix/prefix, use default chat template ) (default: %s)" , params.conversation ? " true" : " false" });
1410
1413
options.push_back ({ " main infill" , " -i, --interactive" , " run in interactive mode (default: %s)" , params.interactive ? " true" : " false" });
1411
1414
options.push_back ({ " main infill" , " -if, --interactive-first" , " run in interactive mode and wait for input right away (default: %s)" , params.interactive_first ? " true" : " false" });
1412
1415
options.push_back ({ " main infill" , " -mli, --multiline-input" , " allows you to write or paste multiple lines without ending each in '\\ '" });
@@ -2668,12 +2671,19 @@ std::string llama_chat_format_single(const struct llama_model * model,
2668
2671
const std::vector<llama_chat_msg> & past_msg,
2669
2672
const llama_chat_msg & new_msg,
2670
2673
bool add_ass) {
2674
+ std::ostringstream ss;
2671
2675
auto fmt_past_msg = llama_chat_apply_template (model, tmpl, past_msg, false );
2672
2676
std::vector<llama_chat_msg> chat_new (past_msg);
2677
+ // if the past_msg ends with a newline, we must preserve it in the formatted version
2678
+ if (add_ass && !fmt_past_msg.empty () && fmt_past_msg.back () == ' \n ' ) {
2679
+ ss << " \n " ;
2680
+ };
2681
+ // format chat with new_msg
2673
2682
chat_new.push_back (new_msg);
2674
2683
auto fmt_new_msg = llama_chat_apply_template (model, tmpl, chat_new, add_ass);
2675
- auto formatted = fmt_new_msg.substr (fmt_past_msg.size (), fmt_new_msg.size () - fmt_past_msg.size ());
2676
- return formatted;
2684
+ // get the diff part
2685
+ ss << fmt_new_msg.substr (fmt_past_msg.size (), fmt_new_msg.size () - fmt_past_msg.size ());
2686
+ return ss.str ();
2677
2687
}
2678
2688
2679
2689
std::string llama_chat_format_example (const struct llama_model * model,
0 commit comments