Skip to content

Commit 1f66b69

Browse files
authored
server : fix the disappearance of the end of the text (#9867)
* server: fix the disappearance of the end of the text when streaming with stop strings * simplify "send text" checks
1 parent 0e41b30 commit 1f66b69

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

examples/server/server.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,22 +1090,21 @@ struct server_context {
10901090
size_t pos = std::min(slot.n_sent_text, slot.generated_text.size());
10911091

10921092
const std::string str_test = slot.generated_text.substr(pos);
1093-
bool is_stop_full = false;
1093+
bool send_text = true;
10941094

10951095
size_t stop_pos = slot.find_stopping_strings(str_test, token_str.size(), STOP_TYPE_FULL);
10961096
if (stop_pos != std::string::npos) {
1097-
is_stop_full = true;
10981097
slot.generated_text.erase(
10991098
slot.generated_text.begin() + pos + stop_pos,
11001099
slot.generated_text.end());
11011100
pos = std::min(slot.n_sent_text, slot.generated_text.size());
1102-
} else {
1103-
is_stop_full = false;
1101+
} else if (slot.has_next_token) {
11041102
stop_pos = slot.find_stopping_strings(str_test, token_str.size(), STOP_TYPE_PARTIAL);
1103+
send_text = stop_pos == std::string::npos;
11051104
}
11061105

11071106
// check if there is any token to predict
1108-
if (stop_pos == std::string::npos || (!slot.has_next_token && !is_stop_full && stop_pos > 0)) {
1107+
if (send_text) {
11091108
// no send the stop word in the response
11101109
result.text_to_send = slot.generated_text.substr(pos, std::string::npos);
11111110
slot.n_sent_text += result.text_to_send.size();

0 commit comments

Comments
 (0)