feat:优化了了auto模式切换逻辑

This commit is contained in:
SengokuCola
2025-06-14 13:09:13 +08:00
parent 8158f2cda4
commit bf0e813142
11 changed files with 190 additions and 131 deletions

View File

@@ -42,14 +42,13 @@ def init_prompt():
请你阅读聊天记录,查看是否需要调取某个人的信息,这个人可以是出现在聊天记录中的,也可以是记录中提到的人。
你不同程度上认识群聊里的人,以及他们谈论到的人,你可以根据聊天记录,回忆起有关他们的信息,帮助你参与聊天
1.你需要提供用户名,以及你想要提取的信息名称类型来进行调取
2.你也可以完全不输出任何信息
2.请注意,提取的信息类型一定要和用户有关,不要提取无关的信息
3.阅读调取记录,如果已经回忆过某个人的信息,请不要重复调取,除非你忘记了
请以json格式输出例如
{{
"用户A": "昵称",
"用户A": "性别",
"用户B": "对你的态度",
"用户C": "你和ta最近做的事",
"用户D": "你对ta的印象",
@@ -230,10 +229,10 @@ class RelationshipProcessor(BaseProcessor):
)
try:
logger.debug(f"{self.log_prefix} 人物信息prompt: \n{prompt}\n")
# logger.debug(f"{self.log_prefix} 人物信息prompt: \n{prompt}\n")
content, _ = await self.llm_model.generate_response_async(prompt=prompt)
if content:
print(f"content: {content}")
# print(f"content: {content}")
content_json = json.loads(repair_json(content))
# 收集即时提取任务

View File

@@ -110,8 +110,8 @@ class WorkingMemoryProcessor(BaseProcessor):
try:
content, _ = await self.llm_model.generate_response_async(prompt=prompt)
print(f"prompt: {prompt}---------------------------------")
print(f"content: {content}---------------------------------")
# print(f"prompt: {prompt}---------------------------------")
# print(f"content: {content}---------------------------------")
if not content:
logger.warning(f"{self.log_prefix} LLM返回空结果处理工作记忆失败。")

View File

@@ -120,7 +120,7 @@ class ActionManager:
self._using_actions = self._default_actions.copy()
# 添加系统核心动作
self._add_system_core_actions()
# self._add_system_core_actions()
def _load_plugin_actions(self) -> None:
"""
@@ -377,8 +377,8 @@ class ActionManager:
if action_mode == "all" or action_mode == mode:
filtered_actions[action_name] = action_info
logger.debug(f"动作 {action_name} 在模式 {mode} 下可用 (mode_enable: {action_mode})")
else:
logger.debug(f"动作 {action_name} 在模式 {mode} 下不可用 (mode_enable: {action_mode})")
# else:
# logger.debug(f"动作 {action_name} 在模式 {mode} 下不可用 (mode_enable: {action_mode})")
logger.debug(f"模式 {mode} 下可用动作: {list(filtered_actions.keys())}")
return filtered_actions
@@ -475,19 +475,19 @@ class ActionManager:
"""恢复默认动作集到使用集"""
self._using_actions = self._default_actions.copy()
# 添加系统核心动作即使enable_plugin为False的系统动作
self._add_system_core_actions()
# self._add_system_core_actions()
def _add_system_core_actions(self) -> None:
"""
添加系统核心动作到使用集
系统核心动作是那些enable_plugin为False但是系统必需的动作
"""
system_core_actions = ["exit_focus_chat"] # 可以根据需要扩展
# def _add_system_core_actions(self) -> None:
# """
# 添加系统核心动作到使用集
# 系统核心动作是那些enable_plugin为False但是系统必需的动作
# """
# system_core_actions = ["exit_focus_chat"] # 可以根据需要扩展
for action_name in system_core_actions:
if action_name in self._registered_actions and action_name not in self._using_actions:
self._using_actions[action_name] = self._registered_actions[action_name]
logger.debug(f"添加系统核心动作到使用集: {action_name}")
# for action_name in system_core_actions:
# if action_name in self._registered_actions and action_name not in self._using_actions:
# self._using_actions[action_name] = self._registered_actions[action_name]
# logger.debug(f"添加系统核心动作到使用集: {action_name}")
def add_system_action_if_needed(self, action_name: str) -> bool:
"""

View File

@@ -136,6 +136,13 @@ class ActionModifier:
if chat_content is not None:
logger.debug(f"{self.log_prefix}开始激活类型判定阶段")
# 保存exit_focus_chat动作如果存在
exit_focus_action = None
if "exit_focus_chat" in self.action_manager.get_using_actions():
exit_focus_action = self.action_manager.get_using_actions()["exit_focus_chat"]
self.action_manager.remove_action_from_using("exit_focus_chat")
logger.debug(f"{self.log_prefix}临时移除exit_focus_chat动作以进行激活类型判定")
# 获取当前使用的动作集经过第一阶段处理且适用于FOCUS模式
current_using_actions = self.action_manager.get_using_actions()
all_registered_actions = self.action_manager.get_registered_actions()
@@ -185,6 +192,11 @@ class ActionModifier:
reason = removal_reasons.get(action_name, "未知原因")
logger.info(f"{self.log_prefix}移除动作: {action_name},原因: {reason}")
# 恢复exit_focus_chat动作如果之前存在
if exit_focus_action:
self.action_manager.add_action_to_using("exit_focus_chat")
logger.debug(f"{self.log_prefix}恢复exit_focus_chat动作")
logger.info(f"{self.log_prefix}激活类型判定完成,最终可用动作: {list(final_activated_actions.keys())}")
logger.info(