@@ -209,8 +209,8 @@ int main(int argc, char ** argv) {
209
209
params.antiprompt .push_back (" ### Instruction:\n\n " );
210
210
}
211
211
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 ) {
214
214
params.interactive = true ;
215
215
}
216
216
@@ -306,7 +306,7 @@ int main(int argc, char ** argv) {
306
306
307
307
std::vector<llama_token> embd;
308
308
309
- while (( n_remain != 0 && !is_antiprompt) || params.interactive ) {
309
+ while (n_remain != 0 || params.interactive ) {
310
310
// predict
311
311
if (embd.size () > 0 ) {
312
312
// infinite text generation via context swapping
@@ -504,8 +504,9 @@ int main(int argc, char ** argv) {
504
504
console_set_color (con_st, CONSOLE_COLOR_DEFAULT);
505
505
}
506
506
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) {
509
510
510
511
// check for reverse prompt
511
512
if (params.antiprompt .size ()) {
@@ -516,21 +517,10 @@ int main(int argc, char ** argv) {
516
517
517
518
is_antiprompt = false ;
518
519
// 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.
521
520
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 ;
532
523
is_antiprompt = true ;
533
- fflush (stdout);
534
524
break ;
535
525
}
536
526
}
0 commit comments