Refactor whitespace and formatting in async stream printer

- Cleaned up whitespace throughout the `print_stream` function for improved readability.
- Standardized output formatting for function call detection and tool result messages, enhancing clarity in logs.
- Ensured consistent handling of empty lines and message content, contributing to better overall code quality.
This commit is contained in:
mykonos-ibiza 2025-07-31 23:33:30 +05:30
parent ac9dbd7127
commit eb53999291
1 changed files with 29 additions and 30 deletions

View File

@ -69,7 +69,9 @@ async def print_stream(stream: AsyncGenerator[str, None]):
full_status = {**data, **status_details}
finish_reason = full_status.get("finish_reason", "received")
status_type = full_status.get("status_type", full_status.get("status", "unknown"))
status_type = full_status.get(
"status_type", full_status.get("status", "unknown")
)
print(f"[STATUS] {status_type} {finish_reason}")
elif event_type == "assistant":
@ -96,7 +98,9 @@ async def print_stream(stream: AsyncGenerator[str, None]):
match = invoke_name_regex.search(full_text)
if match:
current_function_name = match.group(1)
print(f'[TOOL UPDATE] Calling function: "{current_function_name}"')
print(
f'[TOOL UPDATE] Calling function: "{current_function_name}"'
)
if "</function_calls>" in full_text:
parsing_state = "function_call_ended"
@ -140,12 +144,7 @@ async def print_stream(stream: AsyncGenerator[str, None]):
print(f"[TOOL RESULT] Failed to parse message content")
continue
content_str = parsed_content.get("content", "")
if not content_str:
print(f"[TOOL RESULT] No content string in parsed content")
continue
execution_result = try_parse_json(content_str)
execution_result = parsed_content
if not execution_result:
print(f"[TOOL RESULT] Failed to parse execution result")
continue