From 2c93d17b41dfe389735e3dd999b26b700eefcc0a Mon Sep 17 00:00:00 2001 From: Terristen Date: Fri, 24 Mar 2023 20:41:36 -0500 Subject: [PATCH 1/2] Input line len protection for pasting --- chat.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chat.cpp b/chat.cpp index 22f0a4ddf4a05..cc9d26971c27d 100644 --- a/chat.cpp +++ b/chat.cpp @@ -1041,10 +1041,10 @@ int main(int argc, char ** argv) { bool another_line=true; while (another_line) { fflush(stdout); - char buf[256] = {0}; + char buf[16384] = {0}; int n_read; if(params.use_color) printf(ANSI_BOLD ANSI_COLOR_GREEN); - if (scanf("%255[^\n]%n%*c", buf, &n_read) <= 0) { + if (scanf("%16383[^\n]%n%*c", buf, &n_read) <= 0) { // presumable empty line, consume the newline if (scanf("%*c") <= 0) { /*ignore*/ } n_read=0; From 5360cd9bb89b02c8e8a3ca01b10c25ef925e23f8 Mon Sep 17 00:00:00 2001 From: Terristen Date: Fri, 24 Mar 2023 22:08:26 -0500 Subject: [PATCH 2/2] Fixes the CTRL+C error makes ESC the new interrupt --- chat.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/chat.cpp b/chat.cpp index cc9d26971c27d..08bff36d50e95 100644 --- a/chat.cpp +++ b/chat.cpp @@ -758,15 +758,12 @@ bool llama_eval( static bool is_interacting = false; + #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) || defined (_WIN32) void sigint_handler(int signo) { printf(ANSI_COLOR_RESET); if (signo == SIGINT) { - if (!is_interacting) { - is_interacting=true; - } else { - _exit(130); - } + _exit(130); } } #endif @@ -923,7 +920,7 @@ int main(int argc, char ** argv) { if (params.interactive) { fprintf(stderr, "== Running in chat mode. ==\n" #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) || defined (_WIN32) - " - Press Ctrl+C to interject at any time.\n" + " - Press ESC to interject at any time.\n" #endif " - Press Return to return control to LLaMA.\n" " - If you want to submit another line, end your input in '\\'.\n"); @@ -947,6 +944,10 @@ int main(int argc, char ** argv) { while (remaining_tokens > 0) { + if (GetAsyncKeyState(VK_ESCAPE)){ + is_interacting = true; + } + // predict if (embd.size() > 0) { const int64_t t_start_us = ggml_time_us(); @@ -1041,10 +1042,10 @@ int main(int argc, char ** argv) { bool another_line=true; while (another_line) { fflush(stdout); - char buf[16384] = {0}; + char buf[256] = {0}; //16384 - for extended length int n_read; if(params.use_color) printf(ANSI_BOLD ANSI_COLOR_GREEN); - if (scanf("%16383[^\n]%n%*c", buf, &n_read) <= 0) { + if (scanf("%255[^\n]%n%*c", buf, &n_read) <= 0) { //16383 - for extended length // presumable empty line, consume the newline if (scanf("%*c") <= 0) { /*ignore*/ } n_read=0;