diff --git a/src/chat/focus_chat/hfc_performance_logger.py b/src/chat/focus_chat/hfc_performance_logger.py index 2b7f44070..cafb08003 100644 --- a/src/chat/focus_chat/hfc_performance_logger.py +++ b/src/chat/focus_chat/hfc_performance_logger.py @@ -42,7 +42,6 @@ class HFCPerformanceLogger: "total_time": cycle_data.get("total_time", 0), "step_times": cycle_data.get("step_times", {}), "processor_time_costs": cycle_data.get("processor_time_costs", {}), # 前处理器时间 - "post_processor_time_costs": cycle_data.get("post_processor_time_costs", {}), # 后处理器时间 "reasoning": cycle_data.get("reasoning", ""), "success": cycle_data.get("success", False), } @@ -60,12 +59,7 @@ class HFCPerformanceLogger: f"time={record['total_time']:.2f}s", ] - # 添加后处理器时间信息到日志 - if record["post_processor_time_costs"]: - post_processor_stats = ", ".join( - [f"{name}: {time_cost:.3f}s" for name, time_cost in record["post_processor_time_costs"].items()] - ) - log_parts.append(f"post_processors=({post_processor_stats})") + logger.debug(f"记录HFC循环数据: {', '.join(log_parts)}") diff --git a/src/chat/focus_chat/hfc_version_manager.py b/src/chat/focus_chat/hfc_version_manager.py index bccc9e22a..91a3f51be 100644 --- a/src/chat/focus_chat/hfc_version_manager.py +++ b/src/chat/focus_chat/hfc_version_manager.py @@ -20,7 +20,7 @@ class HFCVersionManager: """HFC版本号管理器""" # 默认版本号 - DEFAULT_VERSION = "v4.0.0" + DEFAULT_VERSION = "v5.0.0" # 当前运行时版本号 _current_version: Optional[str] = None diff --git a/src/chat/focus_chat/memory_activator.py b/src/chat/focus_chat/memory_activator.py index c7a355a66..bfe6a58e5 100644 --- a/src/chat/focus_chat/memory_activator.py +++ b/src/chat/focus_chat/memory_activator.py @@ -46,9 +46,12 @@ def init_prompt(): # --- Group Chat Prompt --- memory_activator_prompt = """ 你是一个记忆分析器,你需要根据以下信息来进行回忆 - 以下是一场聊天中的信息,请根据这些信息,总结出几个关键词作为记忆回忆的触发词 + 以下是一段聊天记录,请根据这些信息,总结出几个关键词作为记忆回忆的触发词 + 聊天记录: {obs_info_text} + 你想要回复的消息: + {target_message} 历史关键词(请避免重复提取这些关键词): {cached_keywords} @@ -69,12 +72,12 @@ class MemoryActivator: self.summary_model = LLMRequest( model=global_config.model.memory_summary, temperature=0.7, - request_type="focus.memory_activator", + request_type="memory_activator", ) self.running_memory = [] self.cached_keywords = set() # 用于缓存历史关键词 - async def activate_memory_with_chat_history(self, chat_id, target_message, chat_history_prompt) -> List[Dict]: + async def activate_memory_with_chat_history(self, target_message, chat_history_prompt) -> List[Dict]: """ 激活记忆 @@ -88,23 +91,13 @@ class MemoryActivator: if not global_config.memory.enable_memory: return [] - # obs_info_text = "" - # for observation in observations: - # if isinstance(observation, ChattingObservation): - # obs_info_text += observation.talking_message_str_truncate_short - # elif isinstance(observation, StructureObservation): - # working_info = observation.get_observe_info() - # for working_info_item in working_info: - # obs_info_text += f"{working_info_item['type']}: {working_info_item['content']}\n" - - # logger.info(f"回忆待检索内容:obs_info_text: {obs_info_text}") - # 将缓存的关键词转换为字符串,用于prompt cached_keywords_str = ", ".join(self.cached_keywords) if self.cached_keywords else "暂无历史关键词" prompt = await global_prompt_manager.format_prompt( "memory_activator_prompt", obs_info_text=chat_history_prompt, + target_message=target_message, cached_keywords=cached_keywords_str, ) @@ -130,9 +123,6 @@ class MemoryActivator: related_memory = await hippocampus_manager.get_memory_from_topic( valid_keywords=keywords, max_memory_num=3, max_memory_length=2, max_depth=3 ) - # related_memory = await hippocampus_manager.get_memory_from_text( - # text=obs_info_text, max_memory_num=5, max_memory_length=2, max_depth=3, fast_retrieval=False - # ) logger.info(f"获取到的记忆: {related_memory}") diff --git a/src/person_info/relationship_fetcher.py b/src/person_info/relationship_fetcher.py index 7114d91ed..15bc6cc81 100644 --- a/src/person_info/relationship_fetcher.py +++ b/src/person_info/relationship_fetcher.py @@ -23,7 +23,7 @@ def init_real_time_info_prompts(): {name_block} 现在,你想要回复{person_name}的消息,消息内容是:{target_message}。请根据聊天记录和你要回复的消息,从你对{person_name}的了解中提取有关的信息: -1.你需要提供你想要提取的信息具体是哪方面的信息,例如:年龄,性别,对ta的印象,最近发生的事等等。 +1.你需要提供你想要提取的信息具体是哪方面的信息,例如:年龄,性别,你们之间的交流方式,最近发生的事等等。 2.请注意,请不要重复调取相同的信息,已经调取的信息如下: {info_cache_block} 3.如果当前聊天记录中没有需要查询的信息,或者现有信息已经足够回复,请返回{{"none": "不需要查询"}} @@ -71,13 +71,13 @@ class RelationshipFetcher: # LLM模型配置 self.llm_model = LLMRequest( model=global_config.model.relation, - request_type="focus.real_time_info", + request_type="relation", ) # 小模型用于即时信息提取 self.instant_llm_model = LLMRequest( model=global_config.model.utils_small, - request_type="focus.real_time_info.instant", + request_type="relation.instant", ) name = get_chat_manager().get_stream_name(self.chat_id) diff --git a/src/plugins/built_in/core_actions/emoji.py b/src/plugins/built_in/core_actions/emoji.py new file mode 100644 index 000000000..394b2b7c7 --- /dev/null +++ b/src/plugins/built_in/core_actions/emoji.py @@ -0,0 +1,81 @@ +from typing import Tuple + +# 导入新插件系统 +from src.plugin_system import BaseAction, ActionActivationType, ChatMode + +# 导入依赖的系统组件 +from src.common.logger import get_logger + +# 导入API模块 - 标准Python包方式 +from src.plugin_system.apis import emoji_api +from src.plugins.built_in.core_actions.no_reply import NoReplyAction + + +logger = get_logger("core_actions") + + + +class EmojiAction(BaseAction): + """表情动作 - 发送表情包""" + + # 激活设置 + focus_activation_type = ActionActivationType.LLM_JUDGE + normal_activation_type = ActionActivationType.RANDOM + mode_enable = ChatMode.ALL + parallel_action = True + random_activation_probability = 0.2 # 默认值,可通过配置覆盖 + + # 动作基本信息 + action_name = "emoji" + action_description = "发送表情包辅助表达情绪" + + # LLM判断提示词 + llm_judge_prompt = """ + 判定是否需要使用表情动作的条件: + 1. 用户明确要求使用表情包 + 2. 这是一个适合表达强烈情绪的场合 + 3. 不要发送太多表情包,如果你已经发送过多个表情包则回答"否" + + 请回答"是"或"否"。 + """ + + # 动作参数定义 + action_parameters = {"description": "文字描述你想要发送的表情包内容"} + + # 动作使用场景 + action_require = ["发送表情包辅助表达情绪","表达情绪时可以选择使用", "不要连续发送,如果你已经发过[表情包],就不要选择此动作"] + + # 关联类型 + associated_types = ["emoji"] + + async def execute(self) -> Tuple[bool, str]: + """执行表情动作""" + logger.info(f"{self.log_prefix} 决定发送表情") + + try: + # 1. 根据描述选择表情包 + description = self.action_data.get("description", "") + emoji_result = await emoji_api.get_by_description(description) + + if not emoji_result: + logger.warning(f"{self.log_prefix} 未找到匹配描述 '{description}' 的表情包") + return False, f"未找到匹配 '{description}' 的表情包" + + emoji_base64, emoji_description, matched_emotion = emoji_result + logger.info(f"{self.log_prefix} 找到表情包: {emoji_description}, 匹配情感: {matched_emotion}") + + # 使用BaseAction的便捷方法发送表情包 + success = await self.send_emoji(emoji_base64) + + if not success: + logger.error(f"{self.log_prefix} 表情包发送失败") + return False, "表情包发送失败" + + # 重置NoReplyAction的连续计数器 + NoReplyAction.reset_consecutive_count() + + return True, f"发送表情包: {emoji_description}" + + except Exception as e: + logger.error(f"{self.log_prefix} 表情动作执行失败: {e}") + return False, f"表情发送失败: {str(e)}" \ No newline at end of file diff --git a/src/plugins/built_in/core_actions/plugin.py b/src/plugins/built_in/core_actions/plugin.py index 05ed8cf9d..acf83314d 100644 --- a/src/plugins/built_in/core_actions/plugin.py +++ b/src/plugins/built_in/core_actions/plugin.py @@ -18,8 +18,9 @@ from src.config.config import global_config from src.common.logger import get_logger # 导入API模块 - 标准Python包方式 -from src.plugin_system.apis import emoji_api, generator_api, message_api +from src.plugin_system.apis import generator_api, message_api from src.plugins.built_in.core_actions.no_reply import NoReplyAction +from src.plugins.built_in.core_actions.emoji import EmojiAction logger = get_logger("core_actions") @@ -112,72 +113,6 @@ class ReplyAction(BaseAction): return False, f"回复失败: {str(e)}" -class EmojiAction(BaseAction): - """表情动作 - 发送表情包""" - - # 激活设置 - focus_activation_type = ActionActivationType.LLM_JUDGE - normal_activation_type = ActionActivationType.RANDOM - mode_enable = ChatMode.ALL - parallel_action = True - random_activation_probability = 0.2 # 默认值,可通过配置覆盖 - - # 动作基本信息 - action_name = "emoji" - action_description = "发送表情包辅助表达情绪" - - # LLM判断提示词 - llm_judge_prompt = """ - 判定是否需要使用表情动作的条件: - 1. 用户明确要求使用表情包 - 2. 这是一个适合表达强烈情绪的场合 - 3. 不要发送太多表情包,如果你已经发送过多个表情包则回答"否" - - 请回答"是"或"否"。 - """ - - # 动作参数定义 - action_parameters = {"description": "文字描述你想要发送的表情包内容"} - - # 动作使用场景 - action_require = ["表达情绪时可以选择使用", "重点:不要连续发,如果你已经发过[表情包],就不要选择此动作"] - - # 关联类型 - associated_types = ["emoji"] - - async def execute(self) -> Tuple[bool, str]: - """执行表情动作""" - logger.info(f"{self.log_prefix} 决定发送表情") - - try: - # 1. 根据描述选择表情包 - description = self.action_data.get("description", "") - emoji_result = await emoji_api.get_by_description(description) - - if not emoji_result: - logger.warning(f"{self.log_prefix} 未找到匹配描述 '{description}' 的表情包") - return False, f"未找到匹配 '{description}' 的表情包" - - emoji_base64, emoji_description, matched_emotion = emoji_result - logger.info(f"{self.log_prefix} 找到表情包: {emoji_description}, 匹配情感: {matched_emotion}") - - # 使用BaseAction的便捷方法发送表情包 - success = await self.send_emoji(emoji_base64) - - if not success: - logger.error(f"{self.log_prefix} 表情包发送失败") - return False, "表情包发送失败" - - # 重置NoReplyAction的连续计数器 - NoReplyAction.reset_consecutive_count() - - return True, f"发送表情包: {emoji_description}" - - except Exception as e: - logger.error(f"{self.log_prefix} 表情动作执行失败: {e}") - return False, f"表情发送失败: {str(e)}" - - @register_plugin class CoreActionsPlugin(BasePlugin): """核心动作插件