Update assistant message handling in async stream printer

- Modified the `print_stream` function to include a check for `message_id` before processing assistant messages, ensuring only valid messages are printed.
- Changed output labels from `[MESSAGE]` to `[ASSISTANT]` for clarity in logs, improving the distinction between different message types.
This commit is contained in:
mykonos-ibiza 2025-07-31 23:11:39 +05:30
parent 891e232ce2
commit be05cc8348
1 changed files with 3 additions and 3 deletions

View File

@ -47,7 +47,7 @@ async def print_stream(stream: AsyncGenerator[str, None]):
elif event_type == "assistant":
# Handle assistant messages - print at end of message
content = data.get("content", "")
if content:
if content and data.get("message_id"):
parsed_content = try_parse_json(content)
if parsed_content:
role = parsed_content.get("role", "unknown")
@ -58,10 +58,10 @@ async def print_stream(stream: AsyncGenerator[str, None]):
else message_content
)
print() # New line
print(f"[MESSAGE] {role}: {preview}")
print(f"[ASSISTANT] {preview}")
else:
print() # New line
print(f"[MESSAGE] Failed to parse message content")
print(f"[ASSISTANT] Failed to parse message content")
elif event_type == "tool":
# Handle tool results