Skip to content

Commit 30df9d3

Browse files
committed
main : fix double console output with token healing
1 parent a1972c0 commit 30df9d3

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

examples/main/main.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -755,19 +755,17 @@ int main(int argc, char ** argv) {
755755
for (auto id : embd) {
756756
const std::string token_str = llama_token_to_piece(ctx, id, params.special);
757757

758+
// Console/Stream Output
758759
// Suppress printing while generating token healing prefix
759760
if (n_bytes_to_skip > 0 && n_bytes_to_skip < (int)token_str.size()) {
760-
printf("%s", token_str.substr(n_bytes_to_skip).c_str());
761+
fprintf(stdout, "%s", token_str.substr(n_bytes_to_skip).c_str());
761762
n_bytes_to_skip = 0;
762763
} else if (n_bytes_to_skip > 0) {
763764
n_bytes_to_skip -= token_str.size();
764765
} else {
765-
printf("%s", token_str.c_str());
766+
fprintf(stdout, "%s", token_str.c_str());
766767
}
767768

768-
// Console/Stream Output
769-
fprintf(stdout, "%s", token_str.c_str());
770-
771769
// Record Displayed Tokens To Log
772770
// Note: Generated tokens are created one by one hence this check
773771
if (embd.size() > 1) {

0 commit comments

Comments
 (0)