From 5581eae9573df259caad774455433a2eecaf4a12 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sun, 2 Feb 2025 14:59:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20deepseek-r1=E6=A8=A1=E5=9E=8B=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E9=81=97=E7=95=99=E2=80=9C=E2=80=9D=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20#279=20Open?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/provider/sources/openai_source.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/astrbot/core/provider/sources/openai_source.py b/astrbot/core/provider/sources/openai_source.py index 60d7484d7..bdcb41346 100644 --- a/astrbot/core/provider/sources/openai_source.py +++ b/astrbot/core/provider/sources/openai_source.py @@ -94,13 +94,14 @@ class ProviderOpenAIOfficial(Provider): if tool_list: payloads['tools'] = tool_list + completion = None try: completion = await self.client.chat.completions.create( **payloads, stream=False ) except BaseException as e: - if 'does not support Function Calling' \ + if 'does not support Function Calling' in e \ or 'does not support tools' in e: # ollama del payloads['tools'] logger.debug(f"模型 {self.model_name} 不支持 tools,已自动移除") @@ -109,6 +110,9 @@ class ProviderOpenAIOfficial(Provider): stream=False ) + if not completion: + raise Exception("API 返回的 completion 为空。") + assert isinstance(completion, ChatCompletion) logger.debug(f"completion: {completion}") @@ -121,7 +125,7 @@ class ProviderOpenAIOfficial(Provider): completion_text = str(choice.message.content).strip() # 适配 deepseek-r1 模型 - if r'' in completion_text: + if r'' in completion_text or r'' in completion_text: completion_text = re.sub(r'.*?', '', completion_text, flags=re.DOTALL).strip() # 可能有单标签情况 completion_text = completion_text.replace(r'', '').replace(r'', '').strip()