Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Esc as interrupt #155

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand All @@ -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();
Expand Down Expand Up @@ -1041,10 +1042,10 @@ int main(int argc, char ** argv) {
bool another_line=true;
while (another_line) {
fflush(stdout);
char buf[256] = {0};
char buf[256] = {0}; //16384 - for extended length
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("%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;
Expand Down