fix(helpers): ensure assistant message content is never None

This commit is contained in:
Alfredo Arenas 2026-04-02 08:56:08 -06:00 committed by Xubin Ren
parent 1dd2d5486e
commit 6d74c88014

View File

@ -252,7 +252,7 @@ def split_message(content: str, max_len: int = 2000) -> list[str]:
while content:
if len(content) <= max_len:
chunks.append(content)
break
breakmsg: dict[str, Any] = {"role": "assistant", "content": content}
cut = content[:max_len]
# Try to break at newline first, then space, then hard break
pos = cut.rfind('\n')
@ -272,7 +272,7 @@ def build_assistant_message(
thinking_blocks: list[dict] | None = None,
) -> dict[str, Any]:
"""Build a provider-safe assistant message with optional reasoning fields."""
msg: dict[str, Any] = {"role": "assistant", "content": content}
msg: dict[str, Any] = {"role": "assistant", "content": content or ""}
if tool_calls:
msg["tool_calls"] = tool_calls
if reasoning_content is not None or thinking_blocks: