From cf39f2fe8440847b18e03092dadaca434a04a363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=A5=E6=B2=B3=E6=99=B4?= Date: Tue, 10 Jun 2025 16:41:28 +0900 Subject: [PATCH] random qa --- src/api/main.py | 4 ---- src/api/reload_config.py | 6 +++--- src/chat/actions/base_action.py | 1 - .../actions/default_actions/reply_action.py | 3 --- src/chat/command/command_handler.py | 5 +---- .../focus_chat/expressors/default_expressor.py | 5 ----- .../info_processors/tool_processor.py | 17 +++++++---------- src/chat/focus_chat/planners/modify_actions.py | 8 ++------ src/chat/focus_chat/planners/planner_simple.py | 1 - src/chat/knowledge/lpmmconfig.py | 3 --- src/chat/knowledge/raw_processing.py | 8 ++++---- src/chat/message_receive/message.py | 2 +- src/chat/utils/chat_message_builder.py | 5 ----- src/chat/utils/utils.py | 3 --- src/config/config.py | 8 ++++++++ src/experimental/PFC/message_storage.py | 1 - src/individuality/expression_style.py | 16 ++++++++-------- .../commands/message_info_command.py | 3 --- .../commands/send_msg_with_context.py | 1 - 19 files changed, 34 insertions(+), 66 deletions(-) diff --git a/src/api/main.py b/src/api/main.py index 5e9322827..db3e697f1 100644 --- a/src/api/main.py +++ b/src/api/main.py @@ -18,16 +18,12 @@ from src.api.apiforgui import ( from src.chat.heart_flow.sub_heartflow import ChatState from src.api.basic_info_api import get_all_basic_info # 新增导入 -# import uvicorn -# import os - router = APIRouter() logger = get_logger("api") -# maiapi = FastAPI() logger.info("麦麦API服务器已启动") graphql_router = GraphQLRouter(schema=None, path="/") # Replace `None` with your actual schema diff --git a/src/api/reload_config.py b/src/api/reload_config.py index 1772800b6..5137f3331 100644 --- a/src/api/reload_config.py +++ b/src/api/reload_config.py @@ -1,6 +1,6 @@ from fastapi import HTTPException from rich.traceback import install -from src.config.config import Config +from src.config.config import get_config_dir, load_config from src.common.logger_manager import get_logger import os @@ -14,8 +14,8 @@ async def reload_config(): from src.config import config as config_module logger.debug("正在重载配置文件...") - bot_config_path = os.path.join(Config.get_config_dir(), "bot_config.toml") - config_module.global_config = Config.load_config(config_path=bot_config_path) + bot_config_path = os.path.join(get_config_dir(), "bot_config.toml") + config_module.global_config = load_config(config_path=bot_config_path) logger.debug("配置文件重载成功") return {"status": "reloaded"} except FileNotFoundError as e: diff --git a/src/chat/actions/base_action.py b/src/chat/actions/base_action.py index 624f163ea..f33d870c5 100644 --- a/src/chat/actions/base_action.py +++ b/src/chat/actions/base_action.py @@ -73,7 +73,6 @@ class BaseAction(ABC): """初始化动作 Args: - action_name: 动作名称 action_data: 动作数据 reasoning: 执行该动作的理由 cycle_timers: 计时器字典 diff --git a/src/chat/actions/default_actions/reply_action.py b/src/chat/actions/default_actions/reply_action.py index 5e9c236e1..cbc2cbb40 100644 --- a/src/chat/actions/default_actions/reply_action.py +++ b/src/chat/actions/default_actions/reply_action.py @@ -118,13 +118,10 @@ class ReplyAction(BaseAction): reply_to = reply_data.get("reply_to", "none") - # sender = "" - target = "" if ":" in reply_to or ":" in reply_to: # 使用正则表达式匹配中文或英文冒号 parts = re.split(pattern=r"[::]", string=reply_to, maxsplit=1) if len(parts) == 2: - # sender = parts[0].strip() target = parts[1].strip() anchor_message = chatting_observation.search_message_by_text(target) else: diff --git a/src/chat/command/command_handler.py b/src/chat/command/command_handler.py index 07b452a6c..dfa7d92a9 100644 --- a/src/chat/command/command_handler.py +++ b/src/chat/command/command_handler.py @@ -32,10 +32,7 @@ class BaseCommand(ABC): """ self.message = message self.matched_groups: Dict[str, str] = {} # 存储正则表达式匹配的命名组 - self._services = {} # 存储内部服务 - - # 设置服务 - self._services["chat_stream"] = message.chat_stream + self._services = {"chat_stream": message.chat_stream} # 存储内部服务 # 日志前缀 self.log_prefix = f"[Command:{self.command_name}]" diff --git a/src/chat/focus_chat/expressors/default_expressor.py b/src/chat/focus_chat/expressors/default_expressor.py index a0e85843b..5bb11936a 100644 --- a/src/chat/focus_chat/expressors/default_expressor.py +++ b/src/chat/focus_chat/expressors/default_expressor.py @@ -181,11 +181,6 @@ class DefaultExpressor: (已整合原 HeartFCGenerator 的功能) """ try: - # 1. 获取情绪影响因子并调整模型温度 - # arousal_multiplier = mood_manager.get_arousal_multiplier() - # current_temp = float(global_config.model.normal["temp"]) * arousal_multiplier - # self.express_model.params["temperature"] = current_temp # 动态调整温度 - # --- Determine sender_name for private chat --- sender_name_for_prompt = "某人" # Default for group or if info unavailable if not self.is_group_chat and self.chat_target_info: diff --git a/src/chat/focus_chat/info_processors/tool_processor.py b/src/chat/focus_chat/info_processors/tool_processor.py index 2f46fc8b2..832b4d478 100644 --- a/src/chat/focus_chat/info_processors/tool_processor.py +++ b/src/chat/focus_chat/info_processors/tool_processor.py @@ -48,11 +48,13 @@ class ToolProcessor(BaseProcessor): self.structured_info = [] async def process_info( - self, observations: Optional[List[Observation]] = None, running_memorys: Optional[List[Dict]] = None, *infos - ) -> List[dict]: + self, observations: Optional[List[Observation]] = None, running_memories: Optional[List[Dict]] = None, *infos + ) -> List[StructuredInfo]: """处理信息对象 Args: + observations: 可选的观察列表,包含ChattingObservation和StructureObservation类型 + running_memories: 可选的运行时记忆列表,包含字典类型的记忆信息 *infos: 可变数量的InfoBase类型的信息对象 Returns: @@ -60,15 +62,15 @@ class ToolProcessor(BaseProcessor): """ working_infos = [] + result = [] if observations: for observation in observations: if isinstance(observation, ChattingObservation): - result, used_tools, prompt = await self.execute_tools(observation, running_memorys) + result, used_tools, prompt = await self.execute_tools(observation, running_memories) - # 更新WorkingObservation中的结构化信息 logger.debug(f"工具调用结果: {result}") - + # 更新WorkingObservation中的结构化信息 for observation in observations: if isinstance(observation, StructureObservation): for structured_info in result: @@ -81,12 +83,7 @@ class ToolProcessor(BaseProcessor): structured_info = StructuredInfo() if working_infos: for working_info in working_infos: - # print(f"working_info: {working_info}") - # print(f"working_info.get('type'): {working_info.get('type')}") - # print(f"working_info.get('content'): {working_info.get('content')}") structured_info.set_info(key=working_info.get("type"), value=working_info.get("content")) - # info = structured_info.get_processed_info() - # print(f"info: {info}") return [structured_info] diff --git a/src/chat/focus_chat/planners/modify_actions.py b/src/chat/focus_chat/planners/modify_actions.py index 4be4af786..05d317a54 100644 --- a/src/chat/focus_chat/planners/modify_actions.py +++ b/src/chat/focus_chat/planners/modify_actions.py @@ -198,9 +198,7 @@ class ActionModifier: Args: actions_with_info: 带完整信息的动作字典 - observed_messages_str: 观察到的聊天消息 - chat_context: 聊天上下文信息 - extra_context: 额外的上下文信息 + chat_content: 聊天内容 Returns: Dict[str, Any]: 过滤后激活的actions字典 @@ -320,9 +318,7 @@ class ActionModifier: Args: llm_judge_actions: 需要LLM判定的actions - observed_messages_str: 观察到的聊天消息 - chat_context: 聊天上下文 - extra_context: 额外上下文 + chat_content: 聊天内容 Returns: Dict[str, bool]: action名称到激活结果的映射 diff --git a/src/chat/focus_chat/planners/planner_simple.py b/src/chat/focus_chat/planners/planner_simple.py index 7154c7ecc..d7345095d 100644 --- a/src/chat/focus_chat/planners/planner_simple.py +++ b/src/chat/focus_chat/planners/planner_simple.py @@ -217,7 +217,6 @@ class ActionPlanner(BasePlanner): # 提取决策,提供默认值 extracted_action = parsed_json.get("action", "no_reply") - # extracted_reasoning = parsed_json.get("reasoning", "LLM未提供理由") extracted_reasoning = "" # 将所有其他属性添加到action_data diff --git a/src/chat/knowledge/lpmmconfig.py b/src/chat/knowledge/lpmmconfig.py index 6cb91db25..49f777251 100644 --- a/src/chat/knowledge/lpmmconfig.py +++ b/src/chat/knowledge/lpmmconfig.py @@ -132,9 +132,6 @@ global_config = dict( } ) -# _load_config(global_config, parser.parse_args().config_path) -# file_path = os.path.abspath(__file__) -# dir_path = os.path.dirname(file_path) ROOT_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..")) config_path = os.path.join(ROOT_PATH, "config", "lpmm_config.toml") _load_config(global_config, config_path) diff --git a/src/chat/knowledge/raw_processing.py b/src/chat/knowledge/raw_processing.py index a5ac45dcc..98b1f1687 100644 --- a/src/chat/knowledge/raw_processing.py +++ b/src/chat/knowledge/raw_processing.py @@ -25,10 +25,10 @@ def load_raw_data(path: str = None) -> tuple[list[str], list[str]]: import_json = json.loads(f.read()) else: raise Exception(f"原始数据文件读取失败: {json_path}") - # import_json内容示例: - # import_json = [ - # "The capital of China is Beijing. The capital of France is Paris.", - # ] + """ + import_json 内容示例: + import_json = ["The capital of China is Beijing. The capital of France is Paris.",] + """ raw_data = [] sha256_list = [] sha256_set = set() diff --git a/src/chat/message_receive/message.py b/src/chat/message_receive/message.py index 92aff4c31..dd880fcea 100644 --- a/src/chat/message_receive/message.py +++ b/src/chat/message_receive/message.py @@ -112,7 +112,7 @@ class MessageRecv(Message): self.detailed_plain_text = message_dict.get("detailed_plain_text", "") # 初始化为空字符串 self.is_emoji = False - def update_chat_stream(self, chat_stream: "ChatStream"): + def update_chat_stream(self, chat_stream: ChatStream): self.chat_stream = chat_stream async def process(self) -> None: diff --git a/src/chat/utils/chat_message_builder.py b/src/chat/utils/chat_message_builder.py index 73ee59fd1..da6ff5e58 100644 --- a/src/chat/utils/chat_message_builder.py +++ b/src/chat/utils/chat_message_builder.py @@ -585,14 +585,9 @@ async def build_anonymous_messages(messages: List[Dict[str, Any]]) -> str: for msg in messages: try: - # user_info = msg.get("user_info", {}) platform = msg.get("chat_info_platform") user_id = msg.get("user_id") _timestamp = msg.get("time") - # print(f"msg:{msg}") - # print(f"platform:{platform}") - # print(f"user_id:{user_id}") - # print(f"timestamp:{timestamp}") if msg.get("display_message"): content = msg.get("display_message") else: diff --git a/src/chat/utils/utils.py b/src/chat/utils/utils.py index 149454abe..26be121e0 100644 --- a/src/chat/utils/utils.py +++ b/src/chat/utils/utils.py @@ -247,8 +247,6 @@ def split_into_sentences_w_remove_punctuation(text: str) -> list[str]: # 如果分割后为空(例如,输入全是分隔符且不满足保留条件),恢复颜文字并返回 if not segments: - # recovered_text = recover_kaomoji([text], mapping) # 恢复原文本中的颜文字 - 已移至上层处理 - # return [s for s in recovered_text if s] # 返回非空结果 return [text] if text else [] # 如果原始文本非空,则返回原始文本(可能只包含未被分割的字符或颜文字占位符) # 2. 概率合并 @@ -336,7 +334,6 @@ def process_llm_response(text: str) -> list[str]: kaomoji_mapping = {} # 提取被 () 或 [] 或 ()包裹且包含中文的内容 pattern = re.compile(r"[(\[(](?=.*[一-鿿]).*?[)\])]") - # _extracted_contents = pattern.findall(text) _extracted_contents = pattern.findall(protected_text) # 在保护后的文本上查找 # 去除 () 和 [] 及其包裹的内容 cleaned_text = pattern.sub("", protected_text) diff --git a/src/config/config.py b/src/config/config.py index 893967158..46605c090 100644 --- a/src/config/config.py +++ b/src/config/config.py @@ -185,6 +185,14 @@ def load_config(config_path: str) -> Config: raise e +def get_config_dir() -> str: + """ + 获取配置目录 + :return: 配置目录路径 + """ + return CONFIG_DIR + + # 获取配置文件路径 logger.info(f"MaiCore当前版本: {MMC_VERSION}") update_config() diff --git a/src/experimental/PFC/message_storage.py b/src/experimental/PFC/message_storage.py index f049e002f..2505a06f5 100644 --- a/src/experimental/PFC/message_storage.py +++ b/src/experimental/PFC/message_storage.py @@ -3,7 +3,6 @@ from typing import List, Dict, Any, Callable from playhouse import shortcuts -# from src.common.database.database import db # Peewee db 导入 from src.common.database.database_model import Messages # Peewee Messages 模型导入 model_to_dict: Callable[..., dict] = shortcuts.model_to_dict # Peewee 模型转换为字典的快捷函数 diff --git a/src/individuality/expression_style.py b/src/individuality/expression_style.py index 7ff3b91ff..40b8da211 100644 --- a/src/individuality/expression_style.py +++ b/src/individuality/expression_style.py @@ -48,8 +48,8 @@ class PersonalityExpression: def _read_meta_data(self): if os.path.exists(self.meta_file_path): try: - with open(self.meta_file_path, "r", encoding="utf-8") as f: - meta_data = json.load(f) + with open(self.meta_file_path, "r", encoding="utf-8") as meta_file: + meta_data = json.load(meta_file) # 检查是否有last_update_time字段 if "last_update_time" not in meta_data: logger.warning(f"{self.meta_file_path} 中缺少last_update_time字段,将重新开始。") @@ -57,8 +57,8 @@ class PersonalityExpression: self._write_meta_data({"last_style_text": None, "count": 0, "last_update_time": None}) # 清空并重写表达文件 if os.path.exists(self.expressions_file_path): - with open(self.expressions_file_path, "w", encoding="utf-8") as f: - json.dump([], f, ensure_ascii=False, indent=2) + with open(self.expressions_file_path, "w", encoding="utf-8") as expressions_file: + json.dump([], expressions_file, ensure_ascii=False, indent=2) logger.debug(f"已清空表达文件: {self.expressions_file_path}") return {"last_style_text": None, "count": 0, "last_update_time": None} return meta_data @@ -68,16 +68,16 @@ class PersonalityExpression: self._write_meta_data({"last_style_text": None, "count": 0, "last_update_time": None}) # 清空并重写表达文件 if os.path.exists(self.expressions_file_path): - with open(self.expressions_file_path, "w", encoding="utf-8") as f: - json.dump([], f, ensure_ascii=False, indent=2) + with open(self.expressions_file_path, "w", encoding="utf-8") as expressions_file: + json.dump([], expressions_file, ensure_ascii=False, indent=2) logger.debug(f"已清空表达文件: {self.expressions_file_path}") return {"last_style_text": None, "count": 0, "last_update_time": None} return {"last_style_text": None, "count": 0, "last_update_time": None} def _write_meta_data(self, data): os.makedirs(os.path.dirname(self.meta_file_path), exist_ok=True) - with open(self.meta_file_path, "w", encoding="utf-8") as f: - json.dump(data, f, ensure_ascii=False, indent=2) + with open(self.meta_file_path, "w", encoding="utf-8") as meta_file: + json.dump(data, meta_file, ensure_ascii=False, indent=2) async def extract_and_store_personality_expressions(self): """ diff --git a/src/plugins/example_command_plugin/commands/message_info_command.py b/src/plugins/example_command_plugin/commands/message_info_command.py index 4a73eb29b..dd05c2a71 100644 --- a/src/plugins/example_command_plugin/commands/message_info_command.py +++ b/src/plugins/example_command_plugin/commands/message_info_command.py @@ -95,7 +95,6 @@ class MessageInfoCommand(BaseCommand): "", "🔄 聊天流信息:", f" 流ID: {chat_stream.stream_id}", - f" 是否激活: {'是' if chat_stream.is_active else '否'}", ] ) @@ -172,7 +171,6 @@ class MessageInfoCommand(BaseCommand): "🔄 聊天流详细信息:", f" 流ID: {chat_stream.stream_id}", f" 平台: {chat_stream.platform}", - f" 是否激活: {'是' if chat_stream.is_active else '否'}", f" 用户信息: {chat_stream.user_info.user_nickname} ({chat_stream.user_info.user_id})", f" 群信息: {getattr(chat_stream.group_info, 'group_name', '私聊') if chat_stream.group_info else '私聊'}", ] @@ -270,7 +268,6 @@ class ChatStreamInfoCommand(BaseCommand): "🔄 聊天流信息", f"🆔 流ID: {chat_stream.stream_id}", f"🌐 平台: {chat_stream.platform}", - f"⚡ 状态: {'激活' if chat_stream.is_active else '非激活'}", ] # 用户信息 diff --git a/src/plugins/example_command_plugin/commands/send_msg_with_context.py b/src/plugins/example_command_plugin/commands/send_msg_with_context.py index a2b485fff..82031b60e 100644 --- a/src/plugins/example_command_plugin/commands/send_msg_with_context.py +++ b/src/plugins/example_command_plugin/commands/send_msg_with_context.py @@ -219,7 +219,6 @@ class MessageContextCommand(BaseCommand): "", "🔄 聊天流:", f" 流ID: {chat_stream.stream_id}", - f" 激活状态: {'激活' if chat_stream.is_active else '非激活'}", ] )