From b1d9c2636ae1f20294b4a6a6e30e4975607615e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DAN=E2=84=A2?= Date: Sat, 9 Mar 2024 12:57:00 -0500 Subject: [PATCH] Flush stdout and output ending newline if streaming. --- examples/gritlm/gritlm.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/gritlm/gritlm.cpp b/examples/gritlm/gritlm.cpp index bb94d597a..752a4f78c 100644 --- a/examples/gritlm/gritlm.cpp +++ b/examples/gritlm/gritlm.cpp @@ -158,12 +158,17 @@ static std::string generate(llama_context* ctx, const std::string& prompt, bool std::string piece = llama_token_to_piece(ctx, token); if (stream) { std::printf("%s", piece.c_str()); + std::fflush(stdout); } pieces.push_back(piece); inputs.push_back(token); } + if (stream) { + std::printf("\n"); + } + llama_batch_free(bat); return aggregate_pieces(pieces);