Skip to content

Refactoring: Use STL in input processing and fix off-by-one bug #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -961,15 +961,15 @@ int main(int argc, char ** argv) {
--remaining_tokens;
} else {
// some user input remains from prompt or interaction, forward it to processing
while (embd_inp.size() > input_consumed) {
embd.push_back(embd_inp[input_consumed]);
last_n_tokens.erase(last_n_tokens.begin());
last_n_tokens.push_back(embd_inp[input_consumed]);
++input_consumed;
if (embd.size() > params.n_batch) {
break;
}
}
// Copy at most n_batch elements from embd_inp to embd
size_t num_copied = std::min((size_t) params.n_batch, embd_inp.size() - input_consumed);
std::copy(embd_inp.begin() + input_consumed, embd_inp.begin() + input_consumed + num_copied, std::back_inserter(embd));
input_consumed += num_copied;

// Copy the last `last_n_size` elements copied into embd to last_n_tokens
size_t num_copied_last_n = std::min(num_copied, (size_t) last_n_size);
last_n_tokens.erase(last_n_tokens.begin(), last_n_tokens.begin()+num_copied_last_n);
last_n_tokens.insert(last_n_tokens.end(), embd.end() - num_copied_last_n, embd.end());

// reset color to default if we there is no pending user input
if (!input_noecho && params.use_color && embd_inp.size() == input_consumed) {
Expand Down