From 03282dee0f38c5c484a54662b0e79db9463fc5e5 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Tue, 25 Feb 2025 14:09:12 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20handle=20message=20end=20?= =?UTF-8?q?and=20error=20events=20in=20Dify=20provider,=20improve=20loggin?= =?UTF-8?q?g=20and=20error=20reporting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/provider/sources/dify_source.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/astrbot/core/provider/sources/dify_source.py b/astrbot/core/provider/sources/dify_source.py index 1127c7561..d0ffa9d0f 100644 --- a/astrbot/core/provider/sources/dify_source.py +++ b/astrbot/core/provider/sources/dify_source.py @@ -99,6 +99,12 @@ class ProviderDify(Provider): if not conversation_id: self.conversation_ids[session_id] = chunk['conversation_id'] conversation_id = chunk['conversation_id'] + elif chunk['event'] == 'message_end': + logger.debug(f"Dify message end") + break + elif chunk['event'] == 'error': + logger.error(f"Dify 出现错误:{chunk['error']}") + raise Exception(f"Dify 出现错误 status: {chunk['status']} message: {chunk['message']} error_code: {chunk['error']}") case "workflow": async for chunk in self.api_client.workflow_run( @@ -130,6 +136,9 @@ class ProviderDify(Provider): logger.error(f"Dify 请求失败:{str(e)}") return LLMResponse(role="err", completion_text=f"Dify 请求失败:{str(e)}") + if not result: + logger.warning("Dify 请求结果为空,请查看 Debug 日志。") + return LLMResponse(role="assistant", completion_text=result) async def forget(self, session_id):