From 35e76863db5125e8e63f285f273d99a0672015a8 Mon Sep 17 00:00:00 2001 From: Jakub Horak Date: Sun, 26 Mar 2023 16:50:02 +0200 Subject: [PATCH] Treat empty line input as "no input" Do not insert a "newline" token if user inputs empty line. This let's user to continue the output after she has been asked by reverse prompt for more data. Otherwise an empty-line input would insert a "newline" token which would break the flow of the conversation. --- examples/main/main.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/main/main.cpp b/examples/main/main.cpp index 66b7c2d5d..864201152 100644 --- a/examples/main/main.cpp +++ b/examples/main/main.cpp @@ -465,14 +465,19 @@ int main(int argc, char ** argv) { // done taking input, reset color set_console_state(CONSOLE_STATE_DEFAULT); - auto line_inp = ::llama_tokenize(ctx, buffer, false); - embd_inp.insert(embd_inp.end(), line_inp.begin(), line_inp.end()); + // Add tokens to buffer only if the line is non-empty. + // This let's the user make the chat continue if it was stopped + // on a reverse prompt. + if (buffer.length() > 1) { + auto line_inp = ::llama_tokenize(ctx, buffer, false); + embd_inp.insert(embd_inp.end(), line_inp.begin(), line_inp.end()); - if (params.instruct) { - embd_inp.insert(embd_inp.end(), inp_sfx.begin(), inp_sfx.end()); - } + if (params.instruct) { + embd_inp.insert(embd_inp.end(), inp_sfx.begin(), inp_sfx.end()); + } - n_remain -= line_inp.size(); + n_remain -= line_inp.size(); + } input_noecho = true; // do not echo this again }