Skip to content

Commit 8cec440

Browse files
committed
skip -1 tok in loop to avoid send '' on end
1 parent 343be7f commit 8cec440

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

examples/server/server.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,10 @@ struct llama_server_context
549549
llama_grammar_accept_token(ctx, grammar, result.tok);
550550
}
551551

552-
for (size_t i = 0; i < std::min(candidates_p.size, (size_t)n_probs); ++i)
552+
size_t prob_size = std::min(candidates_p.size, (size_t)n_probs);
553+
// Pick the first prob
554+
555+
for (size_t i = 0; i < ; ++i)
553556
{
554557
result.probs.push_back({candidates_p.data[i].id, candidates_p.data[i].p});
555558
}
@@ -1322,10 +1325,10 @@ int main(int argc, char **argv)
13221325

13231326
while (llama.has_next_token) {
13241327
const completion_token_output token_with_probs = llama.doCompletion();
1325-
const std::string token_text = token_with_probs.tok == -1 ? "" : llama_token_to_str(llama.ctx, token_with_probs.tok);
1326-
if (llama.multibyte_pending > 0) {
1328+
if (token_with_probs.tok == -1 || llama.multibyte_pending > 0) {
13271329
continue;
13281330
}
1331+
const std::string token_text = llama_token_to_str(llama.ctx, token_with_probs.tok);
13291332

13301333
size_t pos = std::min(sent_count, llama.generated_text.size());
13311334

0 commit comments

Comments
 (0)