File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -961,15 +961,15 @@ int main(int argc, char ** argv) {
961
961
--remaining_tokens;
962
962
} else {
963
963
// some user input remains from prompt or interaction, forward it to processing
964
- while (embd_inp. size () > input_consumed) {
965
- embd. push_back ( embd_inp[ input_consumed] );
966
- last_n_tokens. erase (last_n_tokens. begin ( ));
967
- last_n_tokens. push_back (embd_inp[input_consumed]) ;
968
- ++input_consumed;
969
- if (embd. size () > params. n_batch ) {
970
- break ;
971
- }
972
- }
964
+ // Copy at most n_batch elements from embd_inp to embd
965
+ size_t num_copied = std::min (( size_t ) params. n_batch , embd_inp. size () - input_consumed);
966
+ std::copy_n (embd_inp. begin () + input_consumed, num_copied, std::back_inserter (embd ));
967
+ input_consumed += num_copied ;
968
+
969
+ // Copy the last `last_n_size` elements copied into embd to last_n_tokens
970
+ size_t num_copied_last_n = std::min (num_copied, ( size_t ) last_n_size) ;
971
+ last_n_tokens. erase (last_n_tokens. begin (), last_n_tokens. begin ()+num_copied_last_n);
972
+ last_n_tokens. insert (last_n_tokens. end (), embd. end () - num_copied_last_n, embd. end ());
973
973
974
974
// reset color to default if we there is no pending user input
975
975
if (!input_noecho && params.use_color && embd_inp.size () == input_consumed) {
You can’t perform that action at this time.
0 commit comments