Skip to content
Open
Changes from 1 commit
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
20 changes: 14 additions & 6 deletions astrbot/core/provider/sources/openai_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,12 +594,20 @@ def _is_empty(content: Any) -> bool:
tool_calls = msg.get("tool_calls")
reasoning_content = msg.get("reasoning_content")

if _is_empty(content) and not tool_calls and not reasoning_content:
logger.warning(f"过滤第 {idx} 条空 assistant 消息 (无工具调用)")
continue

if _is_empty(content) and tool_calls:
msg["content"] = None
if _is_empty(content) and not tool_calls:
if not reasoning_content:
# 三者全空,真正的垃圾消息,丢弃
logger.debug(f"过滤第 {idx} 条空 assistant 消息 (无 context | tool_calls | reasoning_content)")
Comment thread
renchonghan marked this conversation as resolved.
Outdated
continue
else:
# ⭐ 有 reasoning_content 但没有 content 和 tool_calls
# 不能丢(推理模型需要 reasoning 历史)
# 但 API 要求 content 或 tool_calls 至少有一个
# → 设空字符串占位,满足校验
msg["content"] = ""

elif _is_empty(content) and tool_calls:
msg["content"] = None # 有 tool_calls,按 OpenAI 规范

cleaned.append(msg)

Expand Down