mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-04-27 13:25:52 +00:00
fix(helpers): ensure assistant message content is never None
This commit is contained in:
parent
1dd2d5486e
commit
6d74c88014
@ -252,7 +252,7 @@ def split_message(content: str, max_len: int = 2000) -> list[str]:
|
|||||||
while content:
|
while content:
|
||||||
if len(content) <= max_len:
|
if len(content) <= max_len:
|
||||||
chunks.append(content)
|
chunks.append(content)
|
||||||
break
|
breakmsg: dict[str, Any] = {"role": "assistant", "content": content}
|
||||||
cut = content[:max_len]
|
cut = content[:max_len]
|
||||||
# Try to break at newline first, then space, then hard break
|
# Try to break at newline first, then space, then hard break
|
||||||
pos = cut.rfind('\n')
|
pos = cut.rfind('\n')
|
||||||
@ -272,7 +272,7 @@ def build_assistant_message(
|
|||||||
thinking_blocks: list[dict] | None = None,
|
thinking_blocks: list[dict] | None = None,
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Build a provider-safe assistant message with optional reasoning fields."""
|
"""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:
|
if tool_calls:
|
||||||
msg["tool_calls"] = tool_calls
|
msg["tool_calls"] = tool_calls
|
||||||
if reasoning_content is not None or thinking_blocks:
|
if reasoning_content is not None or thinking_blocks:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user