From 3e7001c6ea38062cfd105ce60aa2c5a2f7e0ed47 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Mon, 23 Mar 2026 12:53:17 +0800 Subject: [PATCH] fix: handle empty choices in ChatCompletionStreamState --- astrbot/core/provider/sources/openai_source.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/astrbot/core/provider/sources/openai_source.py b/astrbot/core/provider/sources/openai_source.py index cef62f8a0..d64feb5a0 100644 --- a/astrbot/core/provider/sources/openai_source.py +++ b/astrbot/core/provider/sources/openai_source.py @@ -329,6 +329,8 @@ class ProviderOpenAIOfficial(Provider): state = ChatCompletionStreamState() async for chunk in stream: + if not chunk.choices: + continue choice = chunk.choices[0] delta = choice.delta @@ -341,8 +343,6 @@ class ProviderOpenAIOfficial(Provider): state.handle_chunk(chunk) except Exception as e: logger.error("Saving chunk state error: " + str(e)) - if not chunk.choices: - continue # logger.debug(f"chunk delta: {delta}") # handle the content delta reasoning = self._extract_reasoning_content(chunk)