Co-authored-by: firecoperana <firecoperana>
This commit is contained in:
firecoperana 2025-10-27 12:17:48 +00:00 committed by GitHub
parent e34399c116
commit 40eabe5dd8
1 changed files with 10 additions and 13 deletions

View File

@ -788,7 +788,7 @@ struct server_slot {
pos = text.find(word, from_pos); pos = text.find(word, from_pos);
} else { } else {
pos = string_find_partial_stop(word, text); pos = string_find_partial_stop(text, word);
} }
if (pos != std::string::npos && (stop_pos == std::string::npos || pos < stop_pos)) { if (pos != std::string::npos && (stop_pos == std::string::npos || pos < stop_pos)) {
@ -1960,31 +1960,28 @@ struct server_context {
size_t pos = std::min(slot.n_sent_text, slot.generated_text.size()); size_t pos = std::min(slot.n_sent_text, slot.generated_text.size());
const std::string str_test = slot.generated_text.substr(pos); const std::string str_test = slot.generated_text.substr(pos);
bool is_stop_full = false; bool send_text = true;
size_t stop_pos = slot.find_stopping_strings(str_test, token_str.size(), true); size_t stop_pos = slot.find_stopping_strings(str_test, token_str.size(), true);
if (stop_pos != std::string::npos) { if (stop_pos != std::string::npos) {
is_stop_full = true;
slot.generated_text.erase( slot.generated_text.erase(
slot.generated_text.begin() + pos + stop_pos, slot.generated_text.begin() + pos + stop_pos,
slot.generated_text.end()); slot.generated_text.end());
// Update n_sent_text to not exceed the new generated_text size pos = std::min(slot.n_sent_text, slot.generated_text.size());
slot.n_sent_text = std::min(slot.n_sent_text, slot.generated_text.size()); }
pos = slot.n_sent_text; else if (slot.has_next_token && !llama_token_is_eog(model, result.tok)) {
} else { stop_pos = slot.find_stopping_strings(str_test, token_str.size(), false);
is_stop_full = false; send_text = stop_pos == std::string::npos;
stop_pos = slot.find_stopping_strings(str_test, token_str.size(), false);
} }
// check if there is any token to predict // check if there is any token to predict
if (stop_pos == std::string::npos || (!slot.has_next_token && !is_stop_full && stop_pos > 0)) { if (send_text) {
// no send the stop word in the response // no send the stop word in the response
result.text_to_send = slot.generated_text.substr(pos, std::string::npos); result.text_to_send = slot.generated_text.substr(pos, std::string::npos);
slot.n_sent_text += result.text_to_send.size(); slot.n_sent_text += result.text_to_send.size();
// add the token to slot queue and cache // add the token to slot queue and cache
} else if (stop_pos != std::string::npos) { } else {
// Handle partial stop - update n_sent_text to the end of the current text result.text_to_send = "";
slot.n_sent_text = slot.generated_text.size();
} }
slot.add_token_string(result); slot.add_token_string(result);