Flush stdout and output ending newline if streaming.

This commit is contained in:
DAN™ 2024-03-09 12:57:00 -05:00
parent a86c844f3f
commit b1d9c2636a

View file

@ -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); std::string piece = llama_token_to_piece(ctx, token);
if (stream) { if (stream) {
std::printf("%s", piece.c_str()); std::printf("%s", piece.c_str());
std::fflush(stdout);
} }
pieces.push_back(piece); pieces.push_back(piece);
inputs.push_back(token); inputs.push_back(token);
} }
if (stream) {
std::printf("\n");
}
llama_batch_free(bat); llama_batch_free(bat);
return aggregate_pieces(pieces); return aggregate_pieces(pieces);