Skip to content

Commit 1408a84

Browse files
authored
perf: Set content to None when the OpenAI message content list is empty (#6551)
_finally_convert_payload 提取 think 部分后,如果 assistant 消息的 所有 content 都是 think 类型,new_content 会变成空列表 []。 Grok 等 provider 不接受空 content list,直接报 400。 改为 new_content or None,空列表时回退到 None(OpenAI 兼容 API 普遍接受 null content 的 assistant 消息)。 Fixes #6447 Co-authored-by: Yufeng He <40085740+universeplayer@users.noreply.github.com>
1 parent 8f95ca9 commit 1408a84

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

astrbot/core/provider/sources/openai_source.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,8 +877,9 @@ def _finally_convert_payload(self, payloads: dict) -> None:
877877
reasoning_content += str(part.get("think"))
878878
else:
879879
new_content.append(part)
880-
message["content"] = new_content
881-
# reasoning key is "reasoning_content"
880+
# Some providers (Grok, etc.) reject empty content lists.
881+
# When all parts were think blocks, fall back to None.
882+
message["content"] = new_content or None
882883
if reasoning_content:
883884
message["reasoning_content"] = reasoning_content
884885

0 commit comments

Comments
 (0)