From c55eb784cb5b7eb0a26a029e5e7f3a98eee03a30 Mon Sep 17 00:00:00 2001 From: wbpxre150 Date: Wed, 12 Apr 2023 15:29:59 +0800 Subject: [PATCH 1/2] add exit call to interactive mode. --- examples/main/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/main/main.cpp b/examples/main/main.cpp index ba153cb82dcf6..b53d04713d332 100644 --- a/examples/main/main.cpp +++ b/examples/main/main.cpp @@ -437,6 +437,15 @@ int main(int argc, char ** argv) { n_remain -= line_inp.size(); } + // exit gracefully when the word "exit" is typed. + if (buffer.length() == 5 && strncmp(buffer.c_str(), "exit", 4) == 0) { + printf("Exit call given, printing stats and exiting.\n"); + llama_print_timings(ctx); + llama_free(ctx); + set_console_color(con_st, CONSOLE_COLOR_DEFAULT); + return 0; + } + input_noecho = true; // do not echo this again } From 47d809c692b8ee2d90134ea1291122f5d45d7b53 Mon Sep 17 00:00:00 2001 From: wbpxre150 Date: Thu, 13 Apr 2023 02:03:48 +0800 Subject: [PATCH 2/2] move code to signal handler --- examples/main/main.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/examples/main/main.cpp b/examples/main/main.cpp index b53d04713d332..718bb602955b1 100644 --- a/examples/main/main.cpp +++ b/examples/main/main.cpp @@ -27,6 +27,8 @@ static console_state con_st; static bool is_interacting = false; +llama_context * ctx; + #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) || defined (_WIN32) void sigint_handler(int signo) { set_console_color(con_st, CONSOLE_COLOR_DEFAULT); @@ -35,6 +37,9 @@ void sigint_handler(int signo) { if (!is_interacting) { is_interacting=true; } else { + //printf("Exit call given, printing stats and exiting.\n"); + llama_print_timings(ctx); + llama_free(ctx); _exit(130); } } @@ -92,8 +97,6 @@ int main(int argc, char ** argv) { // params.prompt = R"(// this function checks if the number n is prime //bool is_prime(int n) {)"; - llama_context * ctx; - // load the model { auto lparams = llama_context_default_params(); @@ -437,15 +440,6 @@ int main(int argc, char ** argv) { n_remain -= line_inp.size(); } - // exit gracefully when the word "exit" is typed. - if (buffer.length() == 5 && strncmp(buffer.c_str(), "exit", 4) == 0) { - printf("Exit call given, printing stats and exiting.\n"); - llama_print_timings(ctx); - llama_free(ctx); - set_console_color(con_st, CONSOLE_COLOR_DEFAULT); - return 0; - } - input_noecho = true; // do not echo this again }