Skip to content

Commit 2bb2ff1

Browse files
committed
Update gpt_params_parse and fix a merge error
1 parent 927afdd commit 2bb2ff1

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

Diff for: examples/common.cpp

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

Diff for: examples/main/main.cpp

+8-18
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ int main(int argc, char ** argv) {
209209
params.antiprompt.push_back("### Instruction:\n\n");
210210
}
211211

212-
// enable interactive mode if interactive start is specified
213-
if (params.interactive_start) {
212+
// enable interactive mode if reverse prompt or interactive start is specified
213+
if (params.interactive_first) {
214214
params.interactive = true;
215215
}
216216

@@ -306,7 +306,7 @@ int main(int argc, char ** argv) {
306306

307307
std::vector<llama_token> embd;
308308

309-
while ((n_remain != 0 && !is_antiprompt) || params.interactive) {
309+
while (n_remain != 0 || params.interactive) {
310310
// predict
311311
if (embd.size() > 0) {
312312
// infinite text generation via context swapping
@@ -504,8 +504,9 @@ int main(int argc, char ** argv) {
504504
console_set_color(con_st, CONSOLE_COLOR_DEFAULT);
505505
}
506506

507-
// if not currently processing queued inputs;
508-
if ((int) embd_inp.size() <= n_consumed) {
507+
// in interactive mode, and not currently processing queued inputs;
508+
// check if we should prompt the user for more
509+
if (params.interactive && (int) embd_inp.size() <= n_consumed) {
509510

510511
// check for reverse prompt
511512
if (params.antiprompt.size()) {
@@ -516,21 +517,10 @@ int main(int argc, char ** argv) {
516517

517518
is_antiprompt = false;
518519
// Check if each of the reverse prompts appears at the end of the output.
519-
// If we're not running interactively, the reverse prompt might be tokenized with some following characters
520-
// so we'll compensate for that by widening the search window a bit.
521520
for (std::string & antiprompt : params.antiprompt) {
522-
size_t extra_padding = params.interactive ? 0 : 2;
523-
size_t search_start_pos = last_output.length() > static_cast<size_t>(antiprompt.length() + extra_padding)
524-
? last_output.length() - static_cast<size_t>(antiprompt.length() + extra_padding)
525-
: 0;
526-
527-
if (last_output.find(antiprompt.c_str(), search_start_pos) != std::string::npos) {
528-
if (params.interactive) {
529-
is_interacting = true;
530-
set_console_color(con_st, CONSOLE_COLOR_USER_INPUT);
531-
}
521+
if (last_output.find(antiprompt.c_str(), last_output.length() - antiprompt.length(), antiprompt.length()) != std::string::npos) {
522+
is_interacting = true;
532523
is_antiprompt = true;
533-
fflush(stdout);
534524
break;
535525
}
536526
}

0 commit comments

Comments
 (0)