@@ -885,15 +885,8 @@ int main(int argc, char ** argv) {
885
885
params.antiprompt .push_back (" ### Instruction:\n\n " );
886
886
}
887
887
888
- // tokenize the reverse prompt
889
- std::vector<std::vector<llama_vocab::id>> antipromptv_inp;
890
-
891
- for (auto antiprompt : params.antiprompt ) {
892
- antipromptv_inp.push_back (::llama_tokenize (vocab, antiprompt, false ));
893
- }
894
-
895
888
// enable interactive mode if reverse prompt is specified
896
- if (antipromptv_inp .size () != 0 ) {
889
+ if (params. antiprompt .size () != 0 ) {
897
890
params.interactive = true ;
898
891
}
899
892
@@ -917,15 +910,9 @@ int main(int argc, char ** argv) {
917
910
918
911
fprintf (stderr, " %s: interactive mode on.\n " , __func__);
919
912
920
- if (antipromptv_inp.size ()) {
921
- for (size_t apindex = 0 ; apindex < antipromptv_inp.size (); ++apindex) {
922
- auto antiprompt_inp = antipromptv_inp.at (apindex);
923
- fprintf (stderr, " %s: reverse prompt: '%s'\n " , __func__, params.antiprompt .at (apindex).c_str ());
924
- fprintf (stderr, " %s: number of tokens in reverse prompt = %zu\n " , __func__, antiprompt_inp.size ());
925
- for (int i = 0 ; i < (int ) antiprompt_inp.size (); i++) {
926
- fprintf (stderr, " %6d -> '%s'\n " , antiprompt_inp[i], vocab.id_to_token .at (antiprompt_inp[i]).c_str ());
927
- }
928
- fprintf (stderr, " \n " );
913
+ if (params.antiprompt .size ()) {
914
+ for (auto antiprompt : params.antiprompt ) {
915
+ fprintf (stderr, " Reverse prompt: '%s'\n " , antiprompt.c_str ());
929
916
}
930
917
}
931
918
}
@@ -1042,9 +1029,14 @@ int main(int argc, char ** argv) {
1042
1029
// check if we should prompt the user for more
1043
1030
if (params.interactive && (int ) embd_inp.size () <= input_consumed) {
1044
1031
// check for reverse prompt
1045
- for (auto antiprompt_inp : antipromptv_inp) {
1046
- if (antiprompt_inp.size () && std::equal (antiprompt_inp.rbegin (), antiprompt_inp.rend (), last_n_tokens.rbegin ())) {
1047
- // reverse prompt found
1032
+ std::string last_output;
1033
+ for (auto id : last_n_tokens) {
1034
+ last_output += vocab.id_to_token [id];
1035
+ }
1036
+
1037
+ // Check if each of the reverse prompts appears at the end of the output.
1038
+ for (std::string antiprompt : params.antiprompt ) {
1039
+ if (last_output.find (antiprompt.c_str (), last_output.length () - antiprompt.length (), antiprompt.length ()) != std::string::npos) {
1048
1040
is_interacting = true ;
1049
1041
break ;
1050
1042
}
0 commit comments