From be05cc83487fe26af5e396871704ac63b546ea13 Mon Sep 17 00:00:00 2001 From: mykonos-ibiza <222371740+mykonos-ibiza@users.noreply.github.com> Date: Thu, 31 Jul 2025 23:11:39 +0530 Subject: [PATCH] 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. --- sdk/kortix/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/kortix/utils.py b/sdk/kortix/utils.py index b1458bf3..872ac72f 100644 --- a/sdk/kortix/utils.py +++ b/sdk/kortix/utils.py @@ -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