From 98e8ecb8e28e1cbc342db80265c2cee77e55ffac Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Tue, 25 Feb 2025 11:46:17 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20add=20type=20check=20for?= =?UTF-8?q?=20completion=20response=20from=20API=20to=20ensure=20correct?= =?UTF-8?q?=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/provider/sources/openai_source.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/astrbot/core/provider/sources/openai_source.py b/astrbot/core/provider/sources/openai_source.py index 90cbfe00..d43f00e9 100644 --- a/astrbot/core/provider/sources/openai_source.py +++ b/astrbot/core/provider/sources/openai_source.py @@ -89,7 +89,9 @@ class ProviderOpenAIOfficial(Provider): extra_body=extra_body ) - assert isinstance(completion, ChatCompletion) + if not isinstance(completion, ChatCompletion): + raise Exception(f"API 返回的 completion 类型错误:{type(completion)}: {completion}。") + logger.debug(f"completion: {completion}") if len(completion.choices) == 0: