Update gpt_params_parse and fix a merge error

This commit is contained in:
Jason McCartney 2023-05-11 21:00:11 -07:00
parent 927afddf95
commit 2bb2ff1748
2 changed files with 9 additions and 19 deletions

View file

@ -346,7 +346,7 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
} }
if (params.prompt_cache_all && if (params.prompt_cache_all &&
(params.interactive || params.interactive_first || (params.interactive || params.interactive_first ||
params.instruct || params.antiprompt.size())) { params.instruct)) {
fprintf(stderr, "error: --prompt-cache-all not supported in interactive mode yet\n"); fprintf(stderr, "error: --prompt-cache-all not supported in interactive mode yet\n");
gpt_print_usage(argc, argv, default_params); gpt_print_usage(argc, argv, default_params);
exit(1); exit(1);

View file

@ -209,8 +209,8 @@ int main(int argc, char ** argv) {
params.antiprompt.push_back("### Instruction:\n\n"); params.antiprompt.push_back("### Instruction:\n\n");
} }
// enable interactive mode if interactive start is specified // enable interactive mode if reverse prompt or interactive start is specified
if (params.interactive_start) { if (params.interactive_first) {
params.interactive = true; params.interactive = true;
} }
@ -306,7 +306,7 @@ int main(int argc, char ** argv) {
std::vector<llama_token> embd; std::vector<llama_token> embd;
while ((n_remain != 0 && !is_antiprompt) || params.interactive) { while (n_remain != 0 || params.interactive) {
// predict // predict
if (embd.size() > 0) { if (embd.size() > 0) {
// infinite text generation via context swapping // infinite text generation via context swapping
@ -504,8 +504,9 @@ int main(int argc, char ** argv) {
console_set_color(con_st, CONSOLE_COLOR_DEFAULT); console_set_color(con_st, CONSOLE_COLOR_DEFAULT);
} }
// if not currently processing queued inputs; // in interactive mode, and not currently processing queued inputs;
if ((int) embd_inp.size() <= n_consumed) { // check if we should prompt the user for more
if (params.interactive && (int) embd_inp.size() <= n_consumed) {
// check for reverse prompt // check for reverse prompt
if (params.antiprompt.size()) { if (params.antiprompt.size()) {
@ -516,21 +517,10 @@ int main(int argc, char ** argv) {
is_antiprompt = false; is_antiprompt = false;
// Check if each of the reverse prompts appears at the end of the output. // Check if each of the reverse prompts appears at the end of the output.
// If we're not running interactively, the reverse prompt might be tokenized with some following characters
// so we'll compensate for that by widening the search window a bit.
for (std::string & antiprompt : params.antiprompt) { for (std::string & antiprompt : params.antiprompt) {
size_t extra_padding = params.interactive ? 0 : 2; if (last_output.find(antiprompt.c_str(), last_output.length() - antiprompt.length(), antiprompt.length()) != std::string::npos) {
size_t search_start_pos = last_output.length() > static_cast<size_t>(antiprompt.length() + extra_padding) is_interacting = true;
? last_output.length() - static_cast<size_t>(antiprompt.length() + extra_padding)
: 0;
if (last_output.find(antiprompt.c_str(), search_start_pos) != std::string::npos) {
if (params.interactive) {
is_interacting = true;
set_console_color(con_st, CONSOLE_COLOR_USER_INPUT);
}
is_antiprompt = true; is_antiprompt = true;
fflush(stdout);
break; break;
} }
} }