Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions astrbot/core/provider/sources/openai_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,22 @@ def _normalize_content(raw_content: Any, strip: bool = True) -> str:
plain string. This method handles both formats.

Args:
raw_content: The raw content from LLM response, can be str, list, or other.
raw_content: The raw content from LLM response, can be str, list, dict, or other.
strip: Whether to strip whitespace from the result. Set to False for
streaming chunks to preserve spaces between words.

Returns:
Normalized plain text string.
"""
# Handle dict format (e.g., {"type": "text", "text": "..."})
if isinstance(raw_content, dict):
if "text" in raw_content:
text_val = raw_content.get("text", "")
return str(text_val) if text_val is not None else ""
# For other dict formats, return empty string and log
logger.warning(f"Unexpected dict format content: {raw_content}")
return ""

if isinstance(raw_content, list):
# Check if this looks like OpenAI content-part format
# Only process if at least one item has {'type': 'text', 'text': ...} structure
Expand Down Expand Up @@ -450,7 +459,8 @@ def _normalize_content(raw_content: Any, strip: bool = True) -> str:
return "".join(text_parts)
return content

return str(raw_content)
# Fallback for other types (int, float, etc.)
return str(raw_content) if raw_content is not None else ""

async def _parse_openai_completion(
self, completion: ChatCompletion, tools: ToolSet | None
Expand Down