Skip to content

Commit

Permalink
Flush console output after every message. (#4475)
Browse files Browse the repository at this point in the history
  • Loading branch information
afourney authored Dec 3, 2024
1 parent 95dfe7b commit c062c51
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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

Expand All @@ -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.")
Expand Down

0 comments on commit c062c51

Please sign in to comment.