feat: 🤠为new指令增加清理上下文选项, 默认为清理, 更符合直觉

This commit is contained in:
anka
2025-04-21 12:06:20 +08:00
parent cc16548e5f
commit c5b24b4764
+21 -2
View File
@@ -763,8 +763,13 @@ UID: {user_id} 此 ID 可用于设置管理员。
return
@filter.command("new")
async def new_conv(self, message: AstrMessageEvent):
"""创建新对话"""
async def new_conv(self, message: AstrMessageEvent, clean: bool = True):
"""
创建新对话
Args:
clean(bool): 是否清理当前对话的上下文, 默认为 True.
"""
provider = self.context.get_using_provider()
if provider and provider.meta().type == "dify":
assert isinstance(provider, ProviderDify)
@@ -777,6 +782,20 @@ UID: {user_id} 此 ID 可用于设置管理员。
cid = await self.context.conversation_manager.new_conversation(
message.unified_msg_origin
)
# 判断是否清理上下文
if clean:
await self.context.conversation_manager.update_conversation(
message.unified_msg_origin, cid, []
)
# 长期记忆
if self.ltm:
try:
await self.ltm.remove_session(event=message)
except BaseException as e:
logger.error(f"清理聊天增强记录失败: {e}")
message.set_result(
MessageEventResult().message(f"切换到新对话: 新对话({cid[:4]})。")
)