mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-15 17:30:13 +08:00
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>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user