From 1408a8449eca6aab4a3588ff420fc13decf38456 Mon Sep 17 00:00:00 2001 From: Yufeng He <40085740+he-yufeng@users.noreply.github.com> Date: Fri, 3 Apr 2026 16:38:22 +0800 Subject: [PATCH] perf: Set content to None when the OpenAI message content list is empty (#6551) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _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> --- astrbot/core/provider/sources/openai_source.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/astrbot/core/provider/sources/openai_source.py b/astrbot/core/provider/sources/openai_source.py index 9c7c61fae..72fc176d9 100644 --- a/astrbot/core/provider/sources/openai_source.py +++ b/astrbot/core/provider/sources/openai_source.py @@ -877,8 +877,9 @@ class ProviderOpenAIOfficial(Provider): reasoning_content += str(part.get("think")) else: new_content.append(part) - message["content"] = new_content - # reasoning key is "reasoning_content" + # Some providers (Grok, etc.) reject empty content lists. + # When all parts were think blocks, fall back to None. + message["content"] = new_content or None if reasoning_content: message["reasoning_content"] = reasoning_content