Skip to content

Commit 40a68f4

Browse files
committed
simplify "send text" checks
1 parent ae996a2 commit 40a68f4

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
@@ -1068,22 +1068,21 @@ struct server_context {
10681068
size_t pos = std::min(slot.n_sent_text, slot.generated_text.size());
10691069

10701070
const std::string str_test = slot.generated_text.substr(pos);
1071-
bool is_stop_full = false;
1071+
bool send_text = true;
10721072

10731073
size_t stop_pos = slot.find_stopping_strings(str_test, token_str.size(), STOP_TYPE_FULL);
10741074
if (stop_pos != std::string::npos) {
1075-
is_stop_full = true;
10761075
slot.generated_text.erase(
10771076
slot.generated_text.begin() + pos + stop_pos,
10781077
slot.generated_text.end());
10791078
pos = std::min(slot.n_sent_text, slot.generated_text.size());
1080-
} else {
1081-
is_stop_full = false;
1079+
} else if (slot.has_next_token) {
10821080
stop_pos = slot.find_stopping_strings(str_test, token_str.size(), STOP_TYPE_PARTIAL);
1081+
send_text = stop_pos == std::string::npos;
10831082
}
10841083

10851084
// check if there is any token to predict
1086-
if (stop_pos == std::string::npos || is_stop_full || (!slot.has_next_token && !is_stop_full && stop_pos > 0)) {
1085+
if (send_text) {
10871086
// no send the stop word in the response
10881087
result.text_to_send = slot.generated_text.substr(pos, std::string::npos);
10891088
slot.n_sent_text += result.text_to_send.size();

0 commit comments

Comments
 (0)