Flush console output after every message. (#4475)

This commit is contained in:
afourney 2024-12-02 16:51:50 -08:00 committed by GitHub
parent 95dfe7bf22
commit c062c510b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -58,6 +58,7 @@ async def Console(
f"Duration: {duration:.2f} seconds\n"
)
sys.stdout.write(output)
sys.stdout.flush()
# mypy ignore
last_processed = message # type: ignore
@ -71,6 +72,7 @@ async def Console(
total_usage.completion_tokens += message.chat_message.models_usage.completion_tokens
total_usage.prompt_tokens += message.chat_message.models_usage.prompt_tokens
sys.stdout.write(output)
sys.stdout.flush()
# Print summary.
if message.inner_messages is not None:
@ -85,6 +87,7 @@ async def Console(
f"Duration: {duration:.2f} seconds\n"
)
sys.stdout.write(output)
sys.stdout.flush()
# mypy ignore
last_processed = message # type: ignore
@ -97,6 +100,7 @@ async def Console(
total_usage.completion_tokens += message.models_usage.completion_tokens
total_usage.prompt_tokens += message.models_usage.prompt_tokens
sys.stdout.write(output)
sys.stdout.flush()
if last_processed is None:
raise ValueError("No TaskResult or Response was processed.")