From 9a56dcb1be88bc77b2a16f2277a2bb6cd446c9e9 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Tue, 11 Feb 2025 21:29:28 +0800 Subject: [PATCH] fix: cannot reset conversation in dify chat mode #469 --- astrbot/core/provider/sources/dify_source.py | 1 + packages/astrbot/main.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/astrbot/core/provider/sources/dify_source.py b/astrbot/core/provider/sources/dify_source.py index 6f946871a..4e8e3e851 100644 --- a/astrbot/core/provider/sources/dify_source.py +++ b/astrbot/core/provider/sources/dify_source.py @@ -35,6 +35,7 @@ class ProviderDify(Provider): if isinstance(self.timeout, str): self.timeout = int(self.timeout) self.conversation_ids = {} + '''记录当前 session id 的对话 ID''' async def text_chat( diff --git a/packages/astrbot/main.py b/packages/astrbot/main.py index cfa32e2a2..63a2a87b4 100644 --- a/packages/astrbot/main.py +++ b/packages/astrbot/main.py @@ -8,6 +8,7 @@ from astrbot.api.event import AstrMessageEvent, MessageEventResult from astrbot.api import sp from astrbot.api.platform import MessageType from astrbot.api.provider import Personality, ProviderRequest, LLMResponse +from astrbot.core.provider.sources.dify_source import ProviderDify from astrbot.core.utils.io import download_dashboard, get_dashboard_version from astrbot.core.star.star_handler import star_handlers_registry, StarHandlerMetadata from astrbot.core.star.star import star_map @@ -348,6 +349,12 @@ UID: {user_id} 此 ID 可用于设置管理员。/op 授权管理员, /deo message.set_result(MessageEventResult().message("未找到任何 LLM 提供商。请先配置。")) return + provider = self.context.get_using_provider() + if provider.meta().type == 'dify': + assert isinstance(provider, ProviderDify) + await provider.forget() + message.set_result(MessageEventResult().message("已重置当前 Dify 会话,新聊天将更换到新的会话。")) + cid = await self.context.conversation_manager.get_curr_conversation_id(message.unified_msg_origin) if not cid: