Skip to content

Commit

Permalink
add the parameter : --no-display-prompt , combine with --log-disable …
Browse files Browse the repository at this point in the history
…it will display only the generated tokens
  • Loading branch information
YannFollet committed Dec 20, 2023
1 parent 328b83d commit 4ab3f47
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,8 @@ bool gpt_params_parse_ex(int argc, char ** argv, gpt_params & params) {
params.numa = true;
} else if (arg == "--verbose-prompt") {
params.verbose_prompt = true;
} else if (arg == "--no-display-prompt") {
params.display_prompt = false;
} else if (arg == "-r" || arg == "--reverse-prompt") {
if (++i >= argc) {
invalid_param = true;
Expand Down Expand Up @@ -904,7 +906,8 @@ void gpt_print_usage(int /*argc*/, char ** argv, const gpt_params & params) {
printf(" Not recommended since this is both slower and uses more VRAM.\n");
#endif // GGML_USE_CUBLAS
#endif
printf(" --verbose-prompt print prompt before generation\n");
printf(" --verbose-prompt print a verbose prompt before generation (default: %s)\n", params.verbose_prompt ? "true" : "false");
printf(" --no-display-prompt don't print prompt at generation (default: %s)\n", !params.display_prompt ? "true" : "false");
printf(" -dkvc, --dump-kv-cache\n");
printf(" verbose print of the KV cache\n");
printf(" -nkvo, --no-kv-offload\n");
Expand Down Expand Up @@ -1539,6 +1542,7 @@ void dump_non_result_info_yaml(FILE * stream, const gpt_params & params, const l
fprintf(stream, "min_p: %f # default: 0.0\n", sparams.min_p);
fprintf(stream, "typical_p: %f # default: 1.0\n", sparams.typical_p);
fprintf(stream, "verbose_prompt: %s # default: false\n", params.verbose_prompt ? "true" : "false");
fprintf(stream, "display_prompt: %s # default: true\n", params.display_prompt ? "true" : "false");
}

//
Expand Down
1 change: 1 addition & 0 deletions common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ struct gpt_params {
bool use_mlock = false; // use mlock to keep model in memory
bool numa = false; // attempt optimizations that help on some NUMA systems
bool verbose_prompt = false; // print prompt tokens before generation
bool display_prompt = true; // print prompt before generation
bool infill = false; // use infill mode
bool dump_kv_cache = false; // dump the KV cache contents for debugging purposes
bool no_kv_offload = false; // disable KV offloading
Expand Down
8 changes: 7 additions & 1 deletion examples/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ int main(int argc, char ** argv) {

bool is_antiprompt = false;
bool input_echo = true;
bool display = true;
bool need_to_save_session = !path_session.empty() && n_matching_session_tokens < embd_inp.size();

int n_past = 0;
Expand All @@ -476,6 +477,7 @@ int main(int argc, char ** argv) {

// the first thing we will do is to output the prompt, so set color accordingly
console::set_display(console::prompt);
display = params.display_prompt;

std::vector<llama_token> embd;
std::vector<llama_token> embd_guidance;
Expand Down Expand Up @@ -664,7 +666,7 @@ int main(int argc, char ** argv) {
}

// display text
if (input_echo) {
if (input_echo && display) {
for (auto id : embd) {
const std::string token_str = llama_token_to_piece(ctx, id);
printf("%s", token_str.c_str());
Expand All @@ -681,6 +683,8 @@ int main(int argc, char ** argv) {
// reset color to default if there is no pending user input
if (input_echo && (int) embd_inp.size() == n_consumed) {
console::set_display(console::reset);
display = true;

}

// if not currently processing queued inputs;
Expand Down Expand Up @@ -753,6 +757,7 @@ int main(int argc, char ** argv) {

// color user input only
console::set_display(console::user_input);
display = params.display_prompt;

std::string line;
bool another_line = true;
Expand All @@ -763,6 +768,7 @@ int main(int argc, char ** argv) {

// done taking input, reset color
console::set_display(console::reset);
display = true;

// Add tokens to embd only if the input buffer is non-empty
// Entering a empty line lets the user pass control back
Expand Down

0 comments on commit 4ab3f47

Please sign in to comment.