mirror of
https://github.com/ikawrakow/ik_llama.cpp.git
synced 2026-05-01 03:41:53 +00:00
Fix incomplete utf-8 characters in streaming text completions (#810)
This commit is contained in:
@@ -1968,7 +1968,9 @@ struct server_context {
|
|||||||
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());
|
||||||
pos = std::min(slot.n_sent_text, slot.generated_text.size());
|
// Update n_sent_text to not exceed the new generated_text size
|
||||||
|
slot.n_sent_text = std::min(slot.n_sent_text, slot.generated_text.size());
|
||||||
|
pos = slot.n_sent_text;
|
||||||
} else {
|
} else {
|
||||||
is_stop_full = false;
|
is_stop_full = false;
|
||||||
stop_pos = slot.find_stopping_strings(str_test, token_str.size(), false);
|
stop_pos = slot.find_stopping_strings(str_test, token_str.size(), false);
|
||||||
@@ -1980,6 +1982,9 @@ struct server_context {
|
|||||||
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) {
|
||||||
|
// Handle partial stop - update n_sent_text to the end of the current text
|
||||||
|
slot.n_sent_text = slot.generated_text.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
slot.add_token_string(result);
|
slot.add_token_string(result);
|
||||||
|
|||||||
Reference in New Issue
Block a user