diff --git a/src/chat/message_receive/bot.py b/src/chat/message_receive/bot.py index 34647c6f8..8b8d6f255 100644 --- a/src/chat/message_receive/bot.py +++ b/src/chat/message_receive/bot.py @@ -133,10 +133,10 @@ class ChatBot: user_info = message.message_info.user_info if message.message_info.additional_config: sent_message = message.message_info.additional_config.get("echo", False) - if sent_message: # 这一段只是为了在一切处理前劫持上报的自身消息,用于更新message_id,需要ada支持上报事件,实际测试中不会对正常使用造成任何问题 + if sent_message: # 这一段只是为了在一切处理前劫持上报的自身消息,用于更新message_id,需要ada支持上报事件,实际测试中不会对正常使用造成任何问题 await MessageStorage.update_message(message) return - + get_chat_manager().register_message(message) # 创建聊天流 @@ -203,4 +203,4 @@ class ChatBot: # 创建全局ChatBot实例 -chat_bot = ChatBot() \ No newline at end of file +chat_bot = ChatBot() diff --git a/src/chat/message_receive/storage.py b/src/chat/message_receive/storage.py index 9cd357ab2..c4ef047de 100644 --- a/src/chat/message_receive/storage.py +++ b/src/chat/message_receive/storage.py @@ -101,10 +101,11 @@ class MessageStorage: except Exception: logger.exception("删除撤回消息失败") - -# 如果需要其他存储相关的函数,可以在这里添加 + # 如果需要其他存储相关的函数,可以在这里添加 @staticmethod - async def update_message(message: MessageRecv) -> None: # 用于实时更新数据库的自身发送消息ID,目前能处理text,reply,image和emoji + async def update_message( + message: MessageRecv, + ) -> None: # 用于实时更新数据库的自身发送消息ID,目前能处理text,reply,image和emoji """更新最新一条匹配消息的message_id""" try: if message.message_segment.type == "notify": @@ -117,18 +118,16 @@ class MessageStorage: logger.info("消息不存在message_id,无法更新") return # 查询最新一条匹配消息 - matched_message = Messages.select().where( - (Messages.message_id == mmc_message_id) - ).order_by(Messages.time.desc()).first() - + matched_message = ( + Messages.select().where((Messages.message_id == mmc_message_id)).order_by(Messages.time.desc()).first() + ) + if matched_message: # 更新找到的消息记录 - Messages.update(message_id=qq_message_id).where( - Messages.id == matched_message.id - ).execute() + Messages.update(message_id=qq_message_id).where(Messages.id == matched_message.id).execute() logger.info(f"更新消息ID成功: {matched_message.message_id} -> {qq_message_id}") else: logger.debug("未找到匹配的消息") - + except Exception as e: - logger.error(f"更新消息ID失败: {e}") \ No newline at end of file + logger.error(f"更新消息ID失败: {e}") diff --git a/src/chat/replyer/default_generator.py b/src/chat/replyer/default_generator.py index 4cc397e89..c301ce31c 100644 --- a/src/chat/replyer/default_generator.py +++ b/src/chat/replyer/default_generator.py @@ -160,10 +160,7 @@ class DefaultReplyer: return None async def generate_reply_with_context( - self, - reply_data: Dict[str, Any], - enable_splitter: bool=True, - enable_chinese_typo: bool=True + self, reply_data: Dict[str, Any], enable_splitter: bool = True, enable_chinese_typo: bool = True ) -> Tuple[bool, Optional[List[str]]]: """ 回复器 (Replier): 核心逻辑,负责生成回复文本。 @@ -193,7 +190,7 @@ class DefaultReplyer: logger.error(f"{self.log_prefix}LLM 生成失败: {llm_e}") return False, None # LLM 调用失败则无法生成回复 - processed_response = process_llm_response(content,enable_splitter,enable_chinese_typo) + processed_response = process_llm_response(content, enable_splitter, enable_chinese_typo) # 5. 处理 LLM 响应 if not content: @@ -216,10 +213,7 @@ class DefaultReplyer: return False, None async def rewrite_reply_with_context( - self, - reply_data: Dict[str, Any], - enable_splitter: bool=True, - enable_chinese_typo: bool=True + self, reply_data: Dict[str, Any], enable_splitter: bool = True, enable_chinese_typo: bool = True ) -> Tuple[bool, Optional[List[str]]]: """ 表达器 (Expressor): 核心逻辑,负责生成回复文本。 @@ -256,7 +250,7 @@ class DefaultReplyer: logger.error(f"{self.log_prefix}LLM 生成失败: {llm_e}") return False, None # LLM 调用失败则无法生成回复 - processed_response = process_llm_response(content,enable_splitter,enable_chinese_typo) + processed_response = process_llm_response(content, enable_splitter, enable_chinese_typo) # 5. 处理 LLM 响应 if not content: diff --git a/src/chat/utils/utils.py b/src/chat/utils/utils.py index 56dd9b435..a147846ca 100644 --- a/src/chat/utils/utils.py +++ b/src/chat/utils/utils.py @@ -321,7 +321,7 @@ def random_remove_punctuation(text: str) -> str: return result -def process_llm_response(text: str, enable_splitter: bool=True, enable_chinese_typo: bool=True) -> list[str]: +def process_llm_response(text: str, enable_splitter: bool = True, enable_chinese_typo: bool = True) -> list[str]: if not global_config.response_post_process.enable_response_post_process: return [text] diff --git a/src/plugin_system/apis/generator_api.py b/src/plugin_system/apis/generator_api.py index aa3c41253..c537d9d95 100644 --- a/src/plugin_system/apis/generator_api.py +++ b/src/plugin_system/apis/generator_api.py @@ -73,8 +73,8 @@ async def generate_reply( chat_stream=None, action_data: Dict[str, Any] = None, chat_id: str = None, - enable_splitter: bool=True, - enable_chinese_typo: bool=True + enable_splitter: bool = True, + enable_chinese_typo: bool = True, ) -> Tuple[bool, List[Tuple[str, Any]]]: """生成回复 @@ -99,9 +99,7 @@ async def generate_reply( # 调用回复器生成回复 success, reply_set = await replyer.generate_reply_with_context( - reply_data=action_data or {}, - enable_splitter=enable_splitter, - enable_chinese_typo=enable_chinese_typo + reply_data=action_data or {}, enable_splitter=enable_splitter, enable_chinese_typo=enable_chinese_typo ) if success: @@ -120,8 +118,8 @@ async def rewrite_reply( chat_stream=None, reply_data: Dict[str, Any] = None, chat_id: str = None, - enable_splitter: bool=True, - enable_chinese_typo: bool=True + enable_splitter: bool = True, + enable_chinese_typo: bool = True, ) -> Tuple[bool, List[Tuple[str, Any]]]: """重写回复 @@ -146,9 +144,7 @@ async def rewrite_reply( # 调用回复器重写回复 success, reply_set = await replyer.rewrite_reply_with_context( - reply_data=reply_data or {}, - enable_splitter=enable_splitter, - enable_chinese_typo=enable_chinese_typo + reply_data=reply_data or {}, enable_splitter=enable_splitter, enable_chinese_typo=enable_chinese_typo ) if success: