Skip to content

Commit 83330d8

Browse files
author
Dawid Potocki
authored
main : add --conversation / -cnv flag (#7108)
1 parent 465263d commit 83330d8

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

common/common.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,10 @@ bool gpt_params_find_arg(int argc, char ** argv, const std::string & arg, gpt_pa
911911
params.instruct = true;
912912
return true;
913913
}
914+
if (arg == "-cnv" || arg == "--conversation") {
915+
params.conversation = true;
916+
return true;
917+
}
914918
if (arg == "-cml" || arg == "--chatml") {
915919
params.chatml = true;
916920
return true;
@@ -1417,6 +1421,7 @@ void gpt_print_usage(int /*argc*/, char ** argv, const gpt_params & params) {
14171421
printf(" --version show version and build info\n");
14181422
printf(" -i, --interactive run in interactive mode\n");
14191423
printf(" --interactive-first run in interactive mode and wait for input right away\n");
1424+
printf(" -cnv, --conversation run in conversation mode (does not print special tokens and suffix/prefix)\n");
14201425
printf(" -ins, --instruct run in instruction mode (use with Alpaca models)\n");
14211426
printf(" -cml, --chatml run in chatml mode (use with ChatML-compatible models)\n");
14221427
printf(" --multiline-input allows you to write or paste multiple lines without ending each in '\\'\n");

common/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ struct gpt_params {
140140
bool random_prompt = false; // do not randomize prompt if none provided
141141
bool use_color = false; // use color to distinguish generations and inputs
142142
bool interactive = false; // interactive mode
143+
bool conversation = false; // conversation mode (does not print special tokens and suffix/prefix)
143144
bool chatml = false; // chatml mode (used for models trained on chatml syntax)
144145
bool prompt_cache_all = false; // save user input and generations to prompt cache
145146
bool prompt_cache_ro = false; // open the prompt cache read-only and do not update it

examples/main/main.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ int main(int argc, char ** argv) {
362362
params.interactive_first = true;
363363
params.antiprompt.emplace_back("<|im_start|>user\n");
364364
}
365+
else if (params.conversation) {
366+
params.interactive_first = true;
367+
}
365368

366369
// enable interactive mode if interactive start is specified
367370
if (params.interactive_first) {
@@ -733,7 +736,7 @@ int main(int argc, char ** argv) {
733736
// display text
734737
if (input_echo && display) {
735738
for (auto id : embd) {
736-
const std::string token_str = llama_token_to_piece(ctx, id);
739+
const std::string token_str = llama_token_to_piece(ctx, id, !params.conversation);
737740
printf("%s", token_str.c_str());
738741

739742
if (embd.size() > 1) {
@@ -816,7 +819,7 @@ int main(int argc, char ** argv) {
816819
if (n_past > 0 && is_interacting) {
817820
LOG("waiting for user input\n");
818821

819-
if (params.instruct || params.chatml) {
822+
if (params.conversation || params.instruct || params.chatml) {
820823
printf("\n> ");
821824
}
822825

@@ -826,7 +829,7 @@ int main(int argc, char ** argv) {
826829
}
827830

828831
std::string buffer;
829-
if (!params.input_prefix.empty()) {
832+
if (!params.input_prefix.empty() && !params.conversation) {
830833
LOG("appending input prefix: '%s'\n", params.input_prefix.c_str());
831834
printf("%s", params.input_prefix.c_str());
832835
}
@@ -850,7 +853,7 @@ int main(int argc, char ** argv) {
850853
// Entering a empty line lets the user pass control back
851854
if (buffer.length() > 1) {
852855
// append input suffix if any
853-
if (!params.input_suffix.empty()) {
856+
if (!params.input_suffix.empty() && !params.conversation) {
854857
LOG("appending input suffix: '%s'\n", params.input_suffix.c_str());
855858
printf("%s", params.input_suffix.c_str());
856859
}

0 commit comments

Comments
 (0)