From 68114993ea6d54d1f87a12299f52b969e51d2f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=A5=E6=B2=B3=E6=99=B4?= Date: Thu, 17 Apr 2025 15:03:42 +0900 Subject: [PATCH 01/12] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E5=92=8C=E4=BB=A3=E7=A0=81=E4=B8=AD=E7=9A=84LLM=5Freq?= =?UTF-8?q?uest=E4=B8=BALLMRequest=EF=BC=8C=E4=BC=98=E5=8C=96dockerignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 1 - CONTRIBUTE.md | 1 - README.md | 22 ++--- src/plugins/message/test.py | 95 ------------------- .../topic_identify/topic_identifier.py | 2 +- src/plugins/willing/mode_llmcheck.py | 4 +- 6 files changed, 14 insertions(+), 111 deletions(-) delete mode 100644 src/plugins/message/test.py diff --git a/.dockerignore b/.dockerignore index 6c2d07736..fac1bf99a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,5 @@ .git __pycache__ -*.pyc *.pyo *.pyd .DS_Store diff --git a/CONTRIBUTE.md b/CONTRIBUTE.md index 440a8202d..c372aebe8 100644 --- a/CONTRIBUTE.md +++ b/CONTRIBUTE.md @@ -19,7 +19,6 @@ ● [我有问题](#我有问题) ● [我想做贡献](#我想做贡献) -● [我想报告BUG](#报告BUG) ● [我想提出建议](#提出建议) ## 我有问题 diff --git a/README.md b/README.md index 325e3ad22..e5a3d1306 100644 --- a/README.md +++ b/README.md @@ -113,17 +113,17 @@ ## 🎯 功能介绍 -| 模块 | 主要功能 | 特点 | -|------|---------|------| -| 💬 聊天系统 | • 心流/推理聊天
• 关键词主动发言
• 多模型支持
• 动态prompt构建
• 私聊功能(PFC) | 拟人化交互 | -| 🧠 心流系统 | • 实时思考生成
• 自动启停机制
• 日程系统联动
• 工具调用能力 | 智能化决策 | -| 🧠 记忆系统 | • 优化记忆抽取
• 海马体记忆机制
• 聊天记录概括 | 持久化记忆 | -| 😊 表情系统 | • 情绪匹配发送
• GIF支持
• 自动收集与审查 | 丰富表达 | -| 📅 日程系统 | • 动态日程生成
• 自定义想象力
• 思维流联动 | 智能规划 | -| 👥 关系系统 | • 关系管理优化
• 丰富接口支持
• 个性化交互 | 深度社交 | -| 📊 统计系统 | • 使用数据统计
• LLM调用记录
• 实时控制台显示 | 数据可视 | -| 🔧 系统功能 | • 优雅关闭机制
• 自动数据保存
• 异常处理完善 | 稳定可靠 | -| 🛠️ 工具系统 | • 知识获取工具
• 自动注册机制
• 多工具支持 | 扩展功能 | +| 模块 | 主要功能 | 特点 | +|----------|------------------------------------------------------------------|-------| +| 💬 聊天系统 | • 心流/推理聊天
• 关键词主动发言
• 多模型支持
• 动态prompt构建
• 私聊功能(PFC) | 拟人化交互 | +| 🧠 心流系统 | • 实时思考生成
• 自动启停机制
• 日程系统联动
• 工具调用能力 | 智能化决策 | +| 🧠 记忆系统 | • 优化记忆抽取
• 海马体记忆机制
• 聊天记录概括 | 持久化记忆 | +| 😊 表情系统 | • 情绪匹配发送
• GIF支持
• 自动收集与审查 | 丰富表达 | +| 📅 日程系统 | • 动态日程生成
• 自定义想象力
• 思维流联动 | 智能规划 | +| 👥 关系系统 | • 关系管理优化
• 丰富接口支持
• 个性化交互 | 深度社交 | +| 📊 统计系统 | • 使用数据统计
• LLM调用记录
• 实时控制台显示 | 数据可视 | +| 🔧 系统功能 | • 优雅关闭机制
• 自动数据保存
• 异常处理完善 | 稳定可靠 | +| 🛠️ 工具系统 | • 知识获取工具
• 自动注册机制
• 多工具支持 | 扩展功能 | ## 📐 项目架构 diff --git a/src/plugins/message/test.py b/src/plugins/message/test.py deleted file mode 100644 index abb4c03b5..000000000 --- a/src/plugins/message/test.py +++ /dev/null @@ -1,95 +0,0 @@ -import unittest -import asyncio -import aiohttp -from api import BaseMessageAPI -from message_base import ( - BaseMessageInfo, - UserInfo, - GroupInfo, - FormatInfo, - MessageBase, - Seg, -) - - -send_url = "http://localhost" -receive_port = 18002 # 接收消息的端口 -send_port = 18000 # 发送消息的端口 -test_endpoint = "/api/message" - -# 创建并启动API实例 -api = BaseMessageAPI(host="0.0.0.0", port=receive_port) - - -class TestLiveAPI(unittest.IsolatedAsyncioTestCase): - async def asyncSetUp(self): - """测试前的设置""" - self.received_messages = [] - - async def message_handler(message): - self.received_messages.append(message) - - self.api = api - self.api.register_message_handler(message_handler) - self.server_task = asyncio.create_task(self.api.run()) - try: - await asyncio.wait_for(asyncio.sleep(1), timeout=5) - except asyncio.TimeoutError: - self.skipTest("服务器启动超时") - - async def asyncTearDown(self): - """测试后的清理""" - if hasattr(self, "server_task"): - await self.api.stop() # 先调用正常的停止流程 - if not self.server_task.done(): - self.server_task.cancel() - try: - await asyncio.wait_for(self.server_task, timeout=100) - except (asyncio.CancelledError, asyncio.TimeoutError): - pass - - async def test_send_and_receive_message(self): - """测试向运行中的API发送消息并接收响应""" - # 准备测试消息 - user_info = UserInfo(user_id=12345678, user_nickname="测试用户", platform="qq") - group_info = GroupInfo(group_id=12345678, group_name="测试群", platform="qq") - format_info = FormatInfo(content_format=["text"], accept_format=["text", "emoji", "reply"]) - template_info = None - message_info = BaseMessageInfo( - platform="qq", - message_id=12345678, - time=12345678, - group_info=group_info, - user_info=user_info, - format_info=format_info, - template_info=template_info, - ) - message = MessageBase( - message_info=message_info, - raw_message="测试消息", - message_segment=Seg(type="text", data="测试消息"), - ) - test_message = message.to_dict() - - # 发送测试消息到发送端口 - async with aiohttp.ClientSession() as session: - async with session.post( - f"{send_url}:{send_port}{test_endpoint}", - json=test_message, - ) as response: - response_data = await response.json() - self.assertEqual(response.status, 200) - self.assertEqual(response_data["status"], "success") - try: - async with asyncio.timeout(5): # 设置5秒超时 - while len(self.received_messages) == 0: - await asyncio.sleep(0.1) - received_message = self.received_messages[0] - print(received_message) - self.received_messages.clear() - except asyncio.TimeoutError: - self.fail("等待接收消息超时") - - -if __name__ == "__main__": - unittest.main() diff --git a/src/plugins/topic_identify/topic_identifier.py b/src/plugins/topic_identify/topic_identifier.py index bc81874c1..25c290a3a 100644 --- a/src/plugins/topic_identify/topic_identifier.py +++ b/src/plugins/topic_identify/topic_identifier.py @@ -28,7 +28,7 @@ class TopicIdentifier: 消息内容:{text}""" - # 使用 LLM_request 类进行请求 + # 使用 LLMRequest 类进行请求 try: topic, _, _ = await self.llm_topic_judge.generate_response(prompt) except Exception as e: diff --git a/src/plugins/willing/mode_llmcheck.py b/src/plugins/willing/mode_llmcheck.py index d6ac3dc6b..ec1cde295 100644 --- a/src/plugins/willing/mode_llmcheck.py +++ b/src/plugins/willing/mode_llmcheck.py @@ -13,7 +13,7 @@ llmcheck 模式: import time from loguru import logger -from ..models.utils_model import LLM_request +from ..models.utils_model import LLMRequest from ...config.config import global_config # from ..chat.chat_stream import ChatStream @@ -61,7 +61,7 @@ def llmcheck_decorator(trigger_condition_func): class LlmcheckWillingManager(MxpWillingManager): def __init__(self): super().__init__() - self.model_v3 = LLM_request(model=global_config.llm_normal, temperature=0.3) + self.model_v3 = LLMRequest(model=global_config.llm_normal, temperature=0.3) async def get_llmreply_probability(self, message_id: str): message_info = self.ongoing_messages[message_id] From 51af1ef4cefc0376a6914e35f6554d78debd1f7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=A5=E6=B2=B3=E6=99=B4?= Date: Thu, 17 Apr 2025 15:17:07 +0900 Subject: [PATCH 02/12] =?UTF-8?q?=E7=A7=BB=E9=99=A4.gitignore=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 37813f433..9bf54a1dc 100644 --- a/.gitignore +++ b/.gitignore @@ -239,6 +239,5 @@ logs .vscode /config/* -run_none.bat config/old/bot_config_20250405_212257.toml From be6699340ae9a08e8dca97707a5946cd57740944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=A5=E6=B2=B3=E6=99=B4?= Date: Thu, 17 Apr 2025 15:20:33 +0900 Subject: [PATCH 03/12] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3identity=5Fdetai?= =?UTF-8?q?l=E7=9A=84=E5=BC=95=E7=94=A8=E4=BB=A5=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E5=A4=84=E7=90=86=E8=BA=AB=E4=BB=BD=E7=BB=86?= =?UTF-8?q?=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/individuality/identity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/individuality/identity.py b/src/individuality/identity.py index 89cba98d1..6abf0a5ea 100644 --- a/src/individuality/identity.py +++ b/src/individuality/identity.py @@ -102,7 +102,7 @@ class Identity: random.shuffle(identity_detail) prompt_identity += identity_detail[0] elif level == 2: - for detail in identity_detail: + for detail in self.identity_detail: prompt_identity += f",{detail}" prompt_identity += "。" return prompt_identity From 73da67fce86ef17fc0a75ed59b58a5f8578e316f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=A5=E6=B2=B3=E6=99=B4?= Date: Thu, 17 Apr 2025 15:21:01 +0900 Subject: [PATCH 04/12] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4hippocampus?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E7=9A=84=E9=94=99=E8=AF=AF=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/__init__.py b/src/plugins/__init__.py index 1bc844939..85de966e0 100644 --- a/src/plugins/__init__.py +++ b/src/plugins/__init__.py @@ -17,6 +17,5 @@ __all__ = [ "relationship_manager", "MoodManager", "willing_manager", - "hippocampus", "bot_schedule", ] From dc96e26ca5d48dfaf6688c951c54dba17aea29e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=A5=E6=B2=B3=E6=99=B4?= Date: Thu, 17 Apr 2025 15:39:49 +0900 Subject: [PATCH 05/12] =?UTF-8?q?refactor:=20=E5=B0=86=E5=A4=9A=E4=B8=AA?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=BF=AE=E6=94=B9=E4=B8=BA=E9=9D=99=E6=80=81?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=BB=A5=E6=8F=90=E9=AB=98=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=8F=AF=E8=AF=BB=E6=80=A7=E5=92=8C=E4=B8=80=E8=87=B4=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/logger.py | 82 +++++++++---------- src/config/config.py | 18 ---- src/do_tool/tool_can_use/change_mood.py | 2 +- .../tool_can_use/change_relationship.py | 12 +-- src/do_tool/tool_can_use/get_knowledge.py | 3 +- src/do_tool/tool_can_use/send_emoji.py | 2 +- src/do_tool/tool_use.py | 9 +- src/heart_flow/heartflow.py | 3 +- src/heart_flow/observation.py | 3 +- src/main.py | 9 +- src/plugins/PFC/conversation.py | 3 +- src/plugins/PFC/message_sender.py | 4 +- src/plugins/PFC/pfc.py | 12 +-- src/plugins/PFC/pfc_KnowledgeFetcher.py | 3 +- src/plugins/chat/chat_stream.py | 9 +- src/plugins/chat/emoji_manager.py | 9 +- src/plugins/chat/message_buffer.py | 6 +- src/plugins/chat/messagesender.py | 6 +- src/plugins/chat/utils_image.py | 15 ++-- .../only_process/only_message_process.py | 6 +- .../reasoning_chat/reasoning_chat.py | 15 ++-- .../reasoning_chat/reasoning_generator.py | 3 +- .../reasoning_prompt_builder.py | 3 +- .../think_flow_chat/think_flow_chat.py | 15 ++-- .../think_flow_chat/think_flow_generator.py | 3 +- .../think_flow_prompt_builder.py | 10 ++- src/plugins/memory_system/Hippocampus.py | 33 +++++--- src/plugins/person_info/person_info.py | 25 ++++-- .../person_info/relationship_manager.py | 24 ++++-- .../respon_info_catcher/info_catcher.py | 6 +- src/plugins/schedule/schedule_generator.py | 3 +- src/plugins/storage/storage.py | 9 +- src/plugins/utils/statistic.py | 18 ++-- src/plugins/utils/timer_calculater.py | 3 +- src/plugins/utils/typo_generator.py | 18 ++-- src/plugins/willing/mode_mxp.py | 6 +- src/plugins/zhishi/knowledge_library.py | 12 ++- 37 files changed, 248 insertions(+), 174 deletions(-) diff --git a/src/common/logger.py b/src/common/logger.py index 7365e34a6..a948059ba 100644 --- a/src/common/logger.py +++ b/src/common/logger.py @@ -47,7 +47,7 @@ if not SIMPLE_OUTPUT: "{extra[module]: <12} | " "{message}" ), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | {message}"), + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | {message}", "log_dir": LOG_ROOT, "rotation": "00:00", "retention": "3 days", @@ -59,8 +59,8 @@ else: "console_level": "INFO", "file_level": "DEBUG", # 格式配置 - "console_format": ("{time:MM-DD HH:mm} | {extra[module]} | {message}"), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | {message}"), + "console_format": "{time:MM-DD HH:mm} | {extra[module]} | {message}", + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | {message}", "log_dir": LOG_ROOT, "rotation": "00:00", "retention": "3 days", @@ -78,13 +78,13 @@ MEMORY_STYLE_CONFIG = { "海马体 | " "{message}" ), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 海马体 | {message}"), + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 海马体 | {message}", }, "simple": { "console_format": ( "{time:MM-DD HH:mm} | 海马体 | {message}" ), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 海马体 | {message}"), + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 海马体 | {message}", }, } @@ -99,11 +99,11 @@ MOOD_STYLE_CONFIG = { "心情 | " "{message}" ), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 心情 | {message}"), + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 心情 | {message}", }, "simple": { - "console_format": ("{time:MM-DD HH:mm} | 心情 | {message}"), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 心情 | {message}"), + "console_format": "{time:MM-DD HH:mm} | 心情 | {message}", + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 心情 | {message}", }, } # tool use @@ -116,11 +116,11 @@ TOOL_USE_STYLE_CONFIG = { "工具使用 | " "{message}" ), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 工具使用 | {message}"), + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 工具使用 | {message}", }, "simple": { - "console_format": ("{time:MM-DD HH:mm} | 工具使用 | {message}"), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 工具使用 | {message}"), + "console_format": "{time:MM-DD HH:mm} | 工具使用 | {message}", + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 工具使用 | {message}", }, } @@ -135,11 +135,11 @@ RELATION_STYLE_CONFIG = { "关系 | " "{message}" ), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 关系 | {message}"), + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 关系 | {message}", }, "simple": { - "console_format": ("{time:MM-DD HH:mm} | 关系 | {message}"), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 关系 | {message}"), + "console_format": "{time:MM-DD HH:mm} | 关系 | {message}", + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 关系 | {message}", }, } @@ -153,11 +153,11 @@ CONFIG_STYLE_CONFIG = { "配置 | " "{message}" ), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 配置 | {message}"), + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 配置 | {message}", }, "simple": { - "console_format": ("{time:MM-DD HH:mm} | 配置 | {message}"), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 配置 | {message}"), + "console_format": "{time:MM-DD HH:mm} | 配置 | {message}", + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 配置 | {message}", }, } @@ -170,11 +170,11 @@ SENDER_STYLE_CONFIG = { "消息发送 | " "{message}" ), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 消息发送 | {message}"), + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 消息发送 | {message}", }, "simple": { - "console_format": ("{time:MM-DD HH:mm} | 消息发送 | {message}"), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 消息发送 | {message}"), + "console_format": "{time:MM-DD HH:mm} | 消息发送 | {message}", + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 消息发送 | {message}", }, } @@ -187,13 +187,13 @@ HEARTFLOW_STYLE_CONFIG = { "麦麦大脑袋 | " "{message}" ), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦大脑袋 | {message}"), + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦大脑袋 | {message}", }, "simple": { "console_format": ( "{time:MM-DD HH:mm} | 麦麦大脑袋 | {message}" ), # noqa: E501 - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦大脑袋 | {message}"), + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦大脑袋 | {message}", }, } @@ -206,11 +206,11 @@ SCHEDULE_STYLE_CONFIG = { "在干嘛 | " "{message}" ), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 在干嘛 | {message}"), + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 在干嘛 | {message}", }, "simple": { - "console_format": ("{time:MM-DD HH:mm} | 在干嘛 | {message}"), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 在干嘛 | {message}"), + "console_format": "{time:MM-DD HH:mm} | 在干嘛 | {message}", + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 在干嘛 | {message}", }, } @@ -223,11 +223,11 @@ LLM_STYLE_CONFIG = { "麦麦组织语言 | " "{message}" ), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦组织语言 | {message}"), + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦组织语言 | {message}", }, "simple": { - "console_format": ("{time:MM-DD HH:mm} | 麦麦组织语言 | {message}"), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦组织语言 | {message}"), + "console_format": "{time:MM-DD HH:mm} | 麦麦组织语言 | {message}", + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦组织语言 | {message}", }, } @@ -242,11 +242,11 @@ TOPIC_STYLE_CONFIG = { "话题 | " "{message}" ), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 话题 | {message}"), + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 话题 | {message}", }, "simple": { - "console_format": ("{time:MM-DD HH:mm} | 主题 | {message}"), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 话题 | {message}"), + "console_format": "{time:MM-DD HH:mm} | 主题 | {message}", + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 话题 | {message}", }, } @@ -260,13 +260,13 @@ CHAT_STYLE_CONFIG = { "见闻 | " "{message}" ), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 见闻 | {message}"), + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 见闻 | {message}", }, "simple": { "console_format": ( "{time:MM-DD HH:mm} | 见闻 | {message}" ), # noqa: E501 - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 见闻 | {message}"), + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 见闻 | {message}", }, } @@ -279,13 +279,13 @@ SUB_HEARTFLOW_STYLE_CONFIG = { "麦麦小脑袋 | " "{message}" ), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦小脑袋 | {message}"), + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦小脑袋 | {message}", }, "simple": { "console_format": ( "{time:MM-DD HH:mm} | 麦麦小脑袋 | {message}" ), # noqa: E501 - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦小脑袋 | {message}"), + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦小脑袋 | {message}", }, } @@ -298,17 +298,17 @@ WILLING_STYLE_CONFIG = { "意愿 | " "{message}" ), - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 意愿 | {message}"), + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 意愿 | {message}", }, "simple": { - "console_format": ("{time:MM-DD HH:mm} | 意愿 | {message}"), # noqa: E501 - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 意愿 | {message}"), + "console_format": "{time:MM-DD HH:mm} | 意愿 | {message}", # noqa: E501 + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 意愿 | {message}", }, } CONFIRM_STYLE_CONFIG = { - "console_format": ("{message}"), # noqa: E501 - "file_format": ("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | EULA与PRIVACY确认 | {message}"), + "console_format": "{message}", # noqa: E501 + "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | EULA与PRIVACY确认 | {message}", } # 根据SIMPLE_OUTPUT选择配置 @@ -459,7 +459,7 @@ other_log_dir.mkdir(parents=True, exist_ok=True) DEFAULT_FILE_HANDLER = logger.add( sink=str(other_log_dir / "{time:YYYY-MM-DD}.log"), level=os.getenv("DEFAULT_FILE_LOG_LEVEL", "DEBUG"), - format=("{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {name: <15} | {message}"), + format="{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {name: <15} | {message}", rotation=DEFAULT_CONFIG["rotation"], retention=DEFAULT_CONFIG["retention"], compression=DEFAULT_CONFIG["compression"], diff --git a/src/config/config.py b/src/config/config.py index 332be7442..9d9fbe8f0 100644 --- a/src/config/config.py +++ b/src/config/config.py @@ -130,9 +130,6 @@ def update_config(): logger.info("配置文件更新完成") -logger = get_module_logger("config") - - @dataclass class BotConfig: """机器人配置类""" @@ -284,21 +281,6 @@ class BotConfig: llm_sub_heartflow: Dict[str, str] = field(default_factory=lambda: {}) llm_heartflow: Dict[str, str] = field(default_factory=lambda: {}) - build_memory_interval: int = 600 # 记忆构建间隔(秒) - - forget_memory_interval: int = 600 # 记忆遗忘间隔(秒) - memory_forget_time: int = 24 # 记忆遗忘时间(小时) - memory_forget_percentage: float = 0.01 # 记忆遗忘比例 - memory_compress_rate: float = 0.1 # 记忆压缩率 - build_memory_sample_num: int = 10 # 记忆构建采样数量 - build_memory_sample_length: int = 20 # 记忆构建采样长度 - memory_build_distribution: list = field( - default_factory=lambda: [4, 2, 0.6, 24, 8, 0.4] - ) # 记忆构建分布,参数:分布1均值,标准差,权重,分布2均值,标准差,权重 - memory_ban_words: list = field( - default_factory=lambda: ["表情包", "图片", "回复", "聊天记录"] - ) # 添加新的配置项默认值 - api_urls: Dict[str, str] = field(default_factory=lambda: {}) @staticmethod diff --git a/src/do_tool/tool_can_use/change_mood.py b/src/do_tool/tool_can_use/change_mood.py index 1c13b1e5f..67c7f6690 100644 --- a/src/do_tool/tool_can_use/change_mood.py +++ b/src/do_tool/tool_can_use/change_mood.py @@ -23,7 +23,7 @@ class ChangeMoodTool(BaseTool): "required": ["text", "response_set"], } - async def execute(self, function_args: Dict[str, Any], message_txt: str) -> Dict[str, Any]: + async def execute(self, function_args: Dict[str, Any], message_txt: str = "") -> Dict[str, Any]: """执行心情改变 Args: diff --git a/src/do_tool/tool_can_use/change_relationship.py b/src/do_tool/tool_can_use/change_relationship.py index 9aa084855..448dba6a8 100644 --- a/src/do_tool/tool_can_use/change_relationship.py +++ b/src/do_tool/tool_can_use/change_relationship.py @@ -1,4 +1,6 @@ # from src.plugins.person_info.relationship_manager import relationship_manager +from typing import Dict, Any + from src.common.logger import get_module_logger from src.do_tool.tool_can_use.base_tool import BaseTool # from src.plugins.chat_module.think_flow_chat.think_flow_generator import ResponseGenerator @@ -20,11 +22,11 @@ class RelationshipTool(BaseTool): "required": ["text", "changed_value", "reason"], } - async def execute(self, args: dict, message_txt: str) -> dict: + async def execute(self, function_args: Dict[str, Any], message_txt: str = "") -> dict: """执行工具功能 Args: - args: 包含工具参数的字典 + function_args: 包含工具参数的字典 text: 原始消息文本 changed_value: 变更值 reason: 变更原因 @@ -33,9 +35,9 @@ class RelationshipTool(BaseTool): dict: 包含执行结果的字典 """ try: - text = args.get("text") - changed_value = args.get("changed_value") - reason = args.get("reason") + text = function_args.get("text") + changed_value = function_args.get("changed_value") + reason = function_args.get("reason") return {"content": f"因为你刚刚因为{reason},所以你和发[{text}]这条消息的人的关系值变化为{changed_value}"} diff --git a/src/do_tool/tool_can_use/get_knowledge.py b/src/do_tool/tool_can_use/get_knowledge.py index b78c07750..31d3c2811 100644 --- a/src/do_tool/tool_can_use/get_knowledge.py +++ b/src/do_tool/tool_can_use/get_knowledge.py @@ -49,8 +49,9 @@ class SearchKnowledgeTool(BaseTool): logger.error(f"知识库搜索工具执行失败: {str(e)}") return {"name": "search_knowledge", "content": f"知识库搜索失败: {str(e)}"} + @staticmethod def get_info_from_db( - self, query_embedding: list, limit: int = 1, threshold: float = 0.5, return_raw: bool = False + query_embedding: list, limit: int = 1, threshold: float = 0.5, return_raw: bool = False ) -> Union[str, list]: """从数据库中获取相关信息 diff --git a/src/do_tool/tool_can_use/send_emoji.py b/src/do_tool/tool_can_use/send_emoji.py index 9cd48f0e4..3c6c8a3f1 100644 --- a/src/do_tool/tool_can_use/send_emoji.py +++ b/src/do_tool/tool_can_use/send_emoji.py @@ -17,7 +17,7 @@ class SendEmojiTool(BaseTool): "required": ["text"], } - async def execute(self, function_args: Dict[str, Any], message_txt: str) -> Dict[str, Any]: + async def execute(self, function_args: Dict[str, Any], message_txt: str = "") -> Dict[str, Any]: text = function_args.get("text", message_txt) return { "name": "send_emoji", diff --git a/src/do_tool/tool_use.py b/src/do_tool/tool_use.py index 1f618e385..d2c8df9c5 100644 --- a/src/do_tool/tool_use.py +++ b/src/do_tool/tool_use.py @@ -24,8 +24,9 @@ class ToolUser: model=global_config.llm_tool_use, temperature=0.2, max_tokens=1000, request_type="tool_use" ) + @staticmethod async def _build_tool_prompt( - self, message_txt: str, sender_name: str, chat_stream: ChatStream, subheartflow: SubHeartflow = None + message_txt: str, sender_name: str, chat_stream: ChatStream, subheartflow: SubHeartflow = None ): """构建工具使用的提示词 @@ -69,7 +70,8 @@ class ToolUser: prompt += "你现在需要对群里的聊天内容进行回复,现在选择工具来对消息和你的回复进行处理,你是否需要额外的信息,比如回忆或者搜寻已有的知识,改变关系和情感,或者了解你现在正在做什么。" return prompt - def _define_tools(self): + @staticmethod + def _define_tools(): """获取所有已注册工具的定义 Returns: @@ -77,7 +79,8 @@ class ToolUser: """ return get_all_tool_definitions() - async def _execute_tool_call(self, tool_call, message_txt: str): + @staticmethod + async def _execute_tool_call(tool_call, message_txt: str): """执行特定的工具调用 Args: diff --git a/src/heart_flow/heartflow.py b/src/heart_flow/heartflow.py index 4936c33e6..9e288c853 100644 --- a/src/heart_flow/heartflow.py +++ b/src/heart_flow/heartflow.py @@ -105,7 +105,8 @@ class Heartflow: # 启动子心流更新任务 asyncio.create_task(self._sub_heartflow_update()) - async def _update_current_state(self): + @staticmethod + async def _update_current_state(): print("TODO") async def do_a_thinking(self): diff --git a/src/heart_flow/observation.py b/src/heart_flow/observation.py index 66059f02e..00213f3f1 100644 --- a/src/heart_flow/observation.py +++ b/src/heart_flow/observation.py @@ -161,7 +161,8 @@ class ChattingObservation(Observation): # print(f"prompt:{prompt}") # print(f"self.observe_info:{self.observe_info}") - def translate_message_list_to_str(self, talking_message): + @staticmethod + def translate_message_list_to_str(talking_message): talking_message_str = "" for message in talking_message: talking_message_str += message["detailed_plain_text"] diff --git a/src/main.py b/src/main.py index 70e870b0c..7b571b3aa 100644 --- a/src/main.py +++ b/src/main.py @@ -131,14 +131,16 @@ class MainSystem: ] await asyncio.gather(*tasks) - async def build_memory_task(self): + @staticmethod + async def build_memory_task(): """记忆构建任务""" while True: await asyncio.sleep(global_config.build_memory_interval) logger.info("正在进行记忆构建") await HippocampusManager.get_instance().build_memory() - async def forget_memory_task(self): + @staticmethod + async def forget_memory_task(): """记忆遗忘任务""" while True: await asyncio.sleep(global_config.forget_memory_interval) @@ -152,7 +154,8 @@ class MainSystem: self.mood_manager.print_mood_status() await asyncio.sleep(30) - async def remove_recalled_message_task(self): + @staticmethod + async def remove_recalled_message_task(): """删除撤回消息任务""" while True: try: diff --git a/src/plugins/PFC/conversation.py b/src/plugins/PFC/conversation.py index 7fcff895b..ba1bf3a78 100644 --- a/src/plugins/PFC/conversation.py +++ b/src/plugins/PFC/conversation.py @@ -113,7 +113,8 @@ class Conversation: return True return False - def _convert_to_message(self, msg_dict: Dict[str, Any]) -> Message: + @staticmethod + def _convert_to_message(msg_dict: Dict[str, Any]) -> Message: """将消息字典转换为Message对象""" try: chat_info = msg_dict.get("chat_info", {}) diff --git a/src/plugins/PFC/message_sender.py b/src/plugins/PFC/message_sender.py index 6a5eb9709..3ff7cba01 100644 --- a/src/plugins/PFC/message_sender.py +++ b/src/plugins/PFC/message_sender.py @@ -15,9 +15,9 @@ class DirectMessageSender: def __init__(self): pass + @staticmethod async def send_message( - self, - chat_stream: ChatStream, + chat_stream: ChatStream, content: str, reply_to_message: Optional[Message] = None, ) -> None: diff --git a/src/plugins/PFC/pfc.py b/src/plugins/PFC/pfc.py index b8b14b475..1d096cc46 100644 --- a/src/plugins/PFC/pfc.py +++ b/src/plugins/PFC/pfc.py @@ -160,16 +160,16 @@ class GoalAnalyzer: # 返回第一个目标作为当前主要目标(如果有) if result: first_goal = result[0] - return (first_goal.get("goal", ""), "", first_goal.get("reasoning", "")) + return first_goal.get("goal", ""), "", first_goal.get("reasoning", "") else: # 单个目标的情况 goal = result.get("goal", "") reasoning = result.get("reasoning", "") conversation_info.goal_list.append((goal, reasoning)) - return (goal, "", reasoning) + return goal, "", reasoning # 如果解析失败,返回默认值 - return ("", "", "") + return "", "", "" async def _update_goals(self, new_goal: str, method: str, reasoning: str): """更新目标列表 @@ -195,7 +195,8 @@ class GoalAnalyzer: if len(self.goals) > self.max_goals: self.goals.pop() # 移除最老的目标 - def _calculate_similarity(self, goal1: str, goal2: str) -> float: + @staticmethod + def _calculate_similarity(goal1: str, goal2: str) -> float: """简单计算两个目标之间的相似度 这里使用一个简单的实现,实际可以使用更复杂的文本相似度算法 @@ -299,7 +300,8 @@ class DirectMessageSender: self.logger = get_module_logger("direct_sender") self.storage = MessageStorage() - async def send_via_ws(self, message: MessageSending) -> None: + @staticmethod + async def send_via_ws(message: MessageSending) -> None: try: await global_api.send_message(message) except Exception as e: diff --git a/src/plugins/PFC/pfc_KnowledgeFetcher.py b/src/plugins/PFC/pfc_KnowledgeFetcher.py index 1a0d495c3..7ce7ce7a3 100644 --- a/src/plugins/PFC/pfc_KnowledgeFetcher.py +++ b/src/plugins/PFC/pfc_KnowledgeFetcher.py @@ -19,7 +19,8 @@ class KnowledgeFetcher: request_type="knowledge_fetch", ) - async def fetch(self, query: str, chat_history: List[Message]) -> Tuple[str, str]: + @staticmethod + async def fetch(query: str, chat_history: List[Message]) -> Tuple[str, str]: """获取相关知识 Args: diff --git a/src/plugins/chat/chat_stream.py b/src/plugins/chat/chat_stream.py index 694e685fa..fb647c836 100644 --- a/src/plugins/chat/chat_stream.py +++ b/src/plugins/chat/chat_stream.py @@ -103,7 +103,8 @@ class ChatManager: except Exception as e: logger.error(f"聊天流自动保存失败: {str(e)}") - def _ensure_collection(self): + @staticmethod + def _ensure_collection(): """确保数据库集合存在并创建索引""" if "chat_streams" not in db.list_collection_names(): db.create_collection("chat_streams") @@ -111,7 +112,8 @@ class ChatManager: db.chat_streams.create_index([("stream_id", 1)], unique=True) db.chat_streams.create_index([("platform", 1), ("user_info.user_id", 1), ("group_info.group_id", 1)]) - def _generate_stream_id(self, platform: str, user_info: UserInfo, group_info: Optional[GroupInfo] = None) -> str: + @staticmethod + def _generate_stream_id(platform: str, user_info: UserInfo, group_info: Optional[GroupInfo] = None) -> str: """生成聊天流唯一ID""" if group_info: # 组合关键信息 @@ -188,7 +190,8 @@ class ChatManager: stream_id = self._generate_stream_id(platform, user_info, group_info) return self.streams.get(stream_id) - async def _save_stream(self, stream: ChatStream): + @staticmethod + async def _save_stream(stream: ChatStream): """保存聊天流到数据库""" if not stream.saved: db.chat_streams.update_one({"stream_id": stream.stream_id}, {"$set": stream.to_dict()}, upsert=True) diff --git a/src/plugins/chat/emoji_manager.py b/src/plugins/chat/emoji_manager.py index 112cd472b..6b09a5839 100644 --- a/src/plugins/chat/emoji_manager.py +++ b/src/plugins/chat/emoji_manager.py @@ -82,7 +82,8 @@ class EmojiManager: if not self._initialized: raise RuntimeError("EmojiManager not initialized") - def _ensure_emoji_collection(self): + @staticmethod + def _ensure_emoji_collection(): """确保emoji集合存在并创建索引 这个函数用于确保MongoDB数据库中存在emoji集合,并创建必要的索引。 @@ -193,7 +194,8 @@ class EmojiManager: logger.error(f"[错误] 获取表情包失败: {str(e)}") return None - async def _get_emoji_description(self, image_base64: str) -> str: + @staticmethod + async def _get_emoji_description(image_base64: str) -> str: """获取表情包的标签,使用image_manager的描述生成功能""" try: @@ -554,7 +556,8 @@ class EmojiManager: self.check_emoji_file_full() await asyncio.sleep(global_config.EMOJI_CHECK_INTERVAL * 60) - async def delete_all_images(self): + @staticmethod + async def delete_all_images(): """删除 data/image 目录下的所有文件""" try: image_dir = os.path.join("data", "image") diff --git a/src/plugins/chat/message_buffer.py b/src/plugins/chat/message_buffer.py index 13cdb8f7d..10c61a298 100644 --- a/src/plugins/chat/message_buffer.py +++ b/src/plugins/chat/message_buffer.py @@ -26,7 +26,8 @@ class MessageBuffer: self.buffer_pool: Dict[str, OrderedDict[str, CacheMessages]] = {} self.lock = asyncio.Lock() - def get_person_id_(self, platform: str, user_id: str, group_info: GroupInfo): + @staticmethod + def get_person_id_(platform: str, user_id: str, group_info: GroupInfo): """获取唯一id""" if group_info: group_id = group_info.group_id @@ -185,7 +186,8 @@ class MessageBuffer: logger.debug(f"查询超时消息id: {message.message_info.message_id}") return False - async def save_message_interval(self, person_id: str, message: BaseMessageInfo): + @staticmethod + async def save_message_interval(person_id: str, message: BaseMessageInfo): message_interval_list = await person_info_manager.get_value(person_id, "msg_interval_list") now_time_ms = int(round(time.time() * 1000)) if len(message_interval_list) < 1000: diff --git a/src/plugins/chat/messagesender.py b/src/plugins/chat/messagesender.py index fd5ab5a75..376a167e1 100644 --- a/src/plugins/chat/messagesender.py +++ b/src/plugins/chat/messagesender.py @@ -35,7 +35,8 @@ class MessageSender: """设置当前bot实例""" pass - def get_recalled_messages(self, stream_id: str) -> list: + @staticmethod + def get_recalled_messages(stream_id: str) -> list: """获取所有撤回的消息""" recalled_messages = [] @@ -43,7 +44,8 @@ class MessageSender: # 按thinking_start_time排序,时间早的在前面 return recalled_messages - async def send_via_ws(self, message: MessageSending) -> None: + @staticmethod + async def send_via_ws(message: MessageSending) -> None: try: await global_api.send_message(message) except Exception as e: diff --git a/src/plugins/chat/utils_image.py b/src/plugins/chat/utils_image.py index 330df3485..e944fbeaa 100644 --- a/src/plugins/chat/utils_image.py +++ b/src/plugins/chat/utils_image.py @@ -38,7 +38,8 @@ class ImageManager: """确保图像存储目录存在""" os.makedirs(self.IMAGE_DIR, exist_ok=True) - def _ensure_image_collection(self): + @staticmethod + def _ensure_image_collection(): """确保images集合存在并创建索引""" if "images" not in db.list_collection_names(): db.create_collection("images") @@ -50,7 +51,8 @@ class ImageManager: db.images.create_index([("url", 1)]) db.images.create_index([("path", 1)]) - def _ensure_description_collection(self): + @staticmethod + def _ensure_description_collection(): """确保image_descriptions集合存在并创建索引""" if "image_descriptions" not in db.list_collection_names(): db.create_collection("image_descriptions") @@ -60,7 +62,8 @@ class ImageManager: # 创建新的复合索引 db.image_descriptions.create_index([("hash", 1), ("type", 1)], unique=True) - def _get_description_from_db(self, image_hash: str, description_type: str) -> Optional[str]: + @staticmethod + def _get_description_from_db(image_hash: str, description_type: str) -> Optional[str]: """从数据库获取图片描述 Args: @@ -73,7 +76,8 @@ class ImageManager: result = db.image_descriptions.find_one({"hash": image_hash, "type": description_type}) return result["description"] if result else None - def _save_description_to_db(self, image_hash: str, description: str, description_type: str) -> None: + @staticmethod + def _save_description_to_db(image_hash: str, description: str, description_type: str) -> None: """保存图片描述到数据库 Args: @@ -226,7 +230,8 @@ class ImageManager: logger.error(f"获取图片描述失败: {str(e)}") return "[图片]" - def transform_gif(self, gif_base64: str) -> str: + @staticmethod + def transform_gif(gif_base64: str) -> str: """将GIF转换为水平拼接的静态图像 Args: diff --git a/src/plugins/chat_module/only_process/only_message_process.py b/src/plugins/chat_module/only_process/only_message_process.py index 9538d10c6..5c239fb1f 100644 --- a/src/plugins/chat_module/only_process/only_message_process.py +++ b/src/plugins/chat_module/only_process/only_message_process.py @@ -13,7 +13,8 @@ class MessageProcessor: def __init__(self): self.storage = MessageStorage() - def _check_ban_words(self, text: str, chat, userinfo) -> bool: + @staticmethod + def _check_ban_words(text: str, chat, userinfo) -> bool: """检查消息中是否包含过滤词""" for word in global_config.ban_words: if word in text: @@ -24,7 +25,8 @@ class MessageProcessor: return True return False - def _check_ban_regex(self, text: str, chat, userinfo) -> bool: + @staticmethod + def _check_ban_regex(text: str, chat, userinfo) -> bool: """检查消息是否匹配过滤正则表达式""" for pattern in global_config.ban_msgs_regex: if pattern.search(text): diff --git a/src/plugins/chat_module/reasoning_chat/reasoning_chat.py b/src/plugins/chat_module/reasoning_chat/reasoning_chat.py index 850bf4b44..efe37715c 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_chat.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_chat.py @@ -37,7 +37,8 @@ class ReasoningChat: self.mood_manager = MoodManager.get_instance() self.mood_manager.start_mood_update() - async def _create_thinking_message(self, message, chat, userinfo, messageinfo): + @staticmethod + async def _create_thinking_message(message, chat, userinfo, messageinfo): """创建思考消息""" bot_user_info = UserInfo( user_id=global_config.BOT_QQ, @@ -59,7 +60,8 @@ class ReasoningChat: return thinking_id - async def _send_response_messages(self, message, chat, response_set: List[str], thinking_id) -> MessageSending: + @staticmethod + async def _send_response_messages(message, chat, response_set: List[str], thinking_id) -> MessageSending: """发送回复消息""" container = message_manager.get_container(chat.stream_id) thinking_message = None @@ -104,7 +106,8 @@ class ReasoningChat: return first_bot_msg - async def _handle_emoji(self, message, chat, response): + @staticmethod + async def _handle_emoji(message, chat, response): """处理表情包""" if random() < global_config.emoji_chance: emoji_raw = await emoji_manager.get_emoji_for_text(response) @@ -291,7 +294,8 @@ class ReasoningChat: # 意愿管理器:注销当前message信息 willing_manager.delete(message.message_info.message_id) - def _check_ban_words(self, text: str, chat, userinfo) -> bool: + @staticmethod + def _check_ban_words(text: str, chat, userinfo) -> bool: """检查消息中是否包含过滤词""" for word in global_config.ban_words: if word in text: @@ -302,7 +306,8 @@ class ReasoningChat: return True return False - def _check_ban_regex(self, text: str, chat, userinfo) -> bool: + @staticmethod + def _check_ban_regex(text: str, chat, userinfo) -> bool: """检查消息是否匹配过滤正则表达式""" for pattern in global_config.ban_msgs_regex: if pattern.search(text): diff --git a/src/plugins/chat_module/reasoning_chat/reasoning_generator.py b/src/plugins/chat_module/reasoning_chat/reasoning_generator.py index 4a6796303..0fb73cc3c 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_generator.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_generator.py @@ -188,7 +188,8 @@ class ResponseGenerator: logger.debug(f"获取情感标签时出错: {e}") return "中立", "平静" # 出错时返回默认值 - async def _process_response(self, content: str) -> Tuple[List[str], List[str]]: + @staticmethod + async def _process_response(content: str) -> Tuple[List[str], List[str]]: """处理响应内容,返回处理后的内容和情感标签""" if not content: return None, [] diff --git a/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py b/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py index 057c948bf..1f6943ced 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py @@ -373,8 +373,9 @@ class PromptBuilder: logger.info(f"知识库检索总耗时: {time.time() - start_time:.3f}秒") return related_info + @staticmethod def get_info_from_db( - self, query_embedding: list, limit: int = 1, threshold: float = 0.5, return_raw: bool = False + query_embedding: list, limit: int = 1, threshold: float = 0.5, return_raw: bool = False ) -> Union[str, list]: if not query_embedding: return "" if not return_raw else [] diff --git a/src/plugins/chat_module/think_flow_chat/think_flow_chat.py b/src/plugins/chat_module/think_flow_chat/think_flow_chat.py index a2a27d38c..dc6a91677 100644 --- a/src/plugins/chat_module/think_flow_chat/think_flow_chat.py +++ b/src/plugins/chat_module/think_flow_chat/think_flow_chat.py @@ -40,7 +40,8 @@ class ThinkFlowChat: self.mood_manager.start_mood_update() self.tool_user = ToolUser() - async def _create_thinking_message(self, message, chat, userinfo, messageinfo): + @staticmethod + async def _create_thinking_message(message, chat, userinfo, messageinfo): """创建思考消息""" bot_user_info = UserInfo( user_id=global_config.BOT_QQ, @@ -62,7 +63,8 @@ class ThinkFlowChat: return thinking_id - async def _send_response_messages(self, message, chat, response_set: List[str], thinking_id) -> MessageSending: + @staticmethod + async def _send_response_messages(message, chat, response_set: List[str], thinking_id) -> MessageSending: """发送回复消息""" container = message_manager.get_container(chat.stream_id) thinking_message = None @@ -108,7 +110,8 @@ class ThinkFlowChat: message_manager.add_message(message_set) return first_bot_msg - async def _handle_emoji(self, message, chat, response, send_emoji=""): + @staticmethod + async def _handle_emoji(message, chat, response, send_emoji=""): """处理表情包""" if send_emoji: emoji_raw = await emoji_manager.get_emoji_for_text(send_emoji) @@ -457,7 +460,8 @@ class ThinkFlowChat: # 意愿管理器:注销当前message信息 willing_manager.delete(message.message_info.message_id) - def _check_ban_words(self, text: str, chat, userinfo) -> bool: + @staticmethod + def _check_ban_words(text: str, chat, userinfo) -> bool: """检查消息中是否包含过滤词""" for word in global_config.ban_words: if word in text: @@ -468,7 +472,8 @@ class ThinkFlowChat: return True return False - def _check_ban_regex(self, text: str, chat, userinfo) -> bool: + @staticmethod + def _check_ban_regex(text: str, chat, userinfo) -> bool: """检查消息是否匹配过滤正则表达式""" for pattern in global_config.ban_msgs_regex: if pattern.search(text): diff --git a/src/plugins/chat_module/think_flow_chat/think_flow_generator.py b/src/plugins/chat_module/think_flow_chat/think_flow_generator.py index fbc80c95c..19b72ee5f 100644 --- a/src/plugins/chat_module/think_flow_chat/think_flow_generator.py +++ b/src/plugins/chat_module/think_flow_chat/think_flow_generator.py @@ -236,7 +236,8 @@ class ResponseGenerator: logger.debug(f"获取情感标签时出错: {e}") return "中立", "平静" # 出错时返回默认值 - async def _process_response(self, content: str) -> List[str]: + @staticmethod + async def _process_response(content: str) -> List[str]: """处理响应内容,返回处理后的内容和情感标签""" if not content: return None diff --git a/src/plugins/chat_module/think_flow_chat/think_flow_prompt_builder.py b/src/plugins/chat_module/think_flow_chat/think_flow_prompt_builder.py index bada143c6..f63e98973 100644 --- a/src/plugins/chat_module/think_flow_chat/think_flow_prompt_builder.py +++ b/src/plugins/chat_module/think_flow_chat/think_flow_prompt_builder.py @@ -64,8 +64,9 @@ class PromptBuilder: self.prompt_built = "" self.activate_messages = "" + @staticmethod async def _build_prompt( - self, chat_stream, message_txt: str, sender_name: str = "某人", stream_id: Optional[int] = None + chat_stream, message_txt: str, sender_name: str = "某人", stream_id: Optional[int] = None ) -> tuple[str, str]: current_mind_info = heartflow.get_subheartflow(stream_id).current_mind @@ -168,8 +169,9 @@ class PromptBuilder: return prompt + @staticmethod async def _build_prompt_simple( - self, chat_stream, message_txt: str, sender_name: str = "某人", stream_id: Optional[int] = None + chat_stream, message_txt: str, sender_name: str = "某人", stream_id: Optional[int] = None ) -> tuple[str, str]: current_mind_info = heartflow.get_subheartflow(stream_id).current_mind @@ -237,9 +239,9 @@ class PromptBuilder: logger.info(f"生成回复的prompt: {prompt}") return prompt + @staticmethod async def _build_prompt_check_response( - self, - chat_stream, + chat_stream, message_txt: str, sender_name: str = "某人", stream_id: Optional[int] = None, diff --git a/src/plugins/memory_system/Hippocampus.py b/src/plugins/memory_system/Hippocampus.py index 2378011e2..7f2d954f7 100644 --- a/src/plugins/memory_system/Hippocampus.py +++ b/src/plugins/memory_system/Hippocampus.py @@ -250,7 +250,8 @@ class Hippocampus: """获取记忆图中所有节点的名字列表""" return list(self.memory_graph.G.nodes()) - def calculate_node_hash(self, concept, memory_items) -> int: + @staticmethod + def calculate_node_hash(concept, memory_items) -> int: """计算节点的特征值""" if not isinstance(memory_items, list): memory_items = [memory_items] if memory_items else [] @@ -258,12 +259,14 @@ class Hippocampus: content = f"{concept}:{'|'.join(sorted_items)}" return hash(content) - def calculate_edge_hash(self, source, target) -> int: + @staticmethod + def calculate_edge_hash(source, target) -> int: """计算边的特征值""" nodes = sorted([source, target]) return hash(f"{nodes[0]}:{nodes[1]}") - def find_topic_llm(self, text, topic_num): + @staticmethod + def find_topic_llm(text, topic_num): prompt = ( f"这是一段文字:{text}。请你从这段话中总结出最多{topic_num}个关键的概念,可以是名词,动词,或者特定人物,帮我列出来," f"将主题用逗号隔开,并加上<>,例如<主题1>,<主题2>......尽可能精简。只需要列举最多{topic_num}个话题就好,不要有序号,不要告诉我其他内容。" @@ -271,14 +274,16 @@ class Hippocampus: ) return prompt - def topic_what(self, text, topic, time_info): + @staticmethod + def topic_what(text, topic, time_info): prompt = ( f'这是一段文字,{time_info}:{text}。我想让你基于这段文字来概括"{topic}"这个概念,帮我总结成一句自然的话,' f"可以包含时间和人物,以及具体的观点。只输出这句话就好" ) return prompt - def calculate_topic_num(self, text, compress_rate): + @staticmethod + def calculate_topic_num(text, compress_rate): """计算文本的话题数量""" information_content = calculate_information_content(text) topic_by_length = text.count("\n") * compress_rate @@ -693,7 +698,8 @@ class EntorhinalCortex: return chat_samples - def random_get_msg_snippet(self, target_timestamp: float, chat_size: int, max_memorized_time_per_msg: int) -> list: + @staticmethod + def random_get_msg_snippet(target_timestamp: float, chat_size: int, max_memorized_time_per_msg: int) -> list: """从数据库中随机获取指定时间戳附近的消息片段""" try_count = 0 while try_count < 3: @@ -958,7 +964,8 @@ class Hippocampus: """获取记忆图中所有节点的名字列表""" return list(self.memory_graph.G.nodes()) - def calculate_node_hash(self, concept, memory_items) -> int: + @staticmethod + def calculate_node_hash(concept, memory_items) -> int: """计算节点的特征值""" if not isinstance(memory_items, list): memory_items = [memory_items] if memory_items else [] @@ -966,12 +973,14 @@ class Hippocampus: content = f"{concept}:{'|'.join(sorted_items)}" return hash(content) - def calculate_edge_hash(self, source, target) -> int: + @staticmethod + def calculate_edge_hash(source, target) -> int: """计算边的特征值""" nodes = sorted([source, target]) return hash(f"{nodes[0]}:{nodes[1]}") - def find_topic_llm(self, text, topic_num): + @staticmethod + def find_topic_llm(text, topic_num): prompt = ( f"这是一段文字:{text}。请你从这段话中总结出最多{topic_num}个关键的概念,可以是名词,动词,或者特定人物,帮我列出来," f"将主题用逗号隔开,并加上<>,例如<主题1>,<主题2>......尽可能精简。只需要列举最多{topic_num}个话题就好,不要有序号,不要告诉我其他内容。" @@ -979,14 +988,16 @@ class Hippocampus: ) return prompt - def topic_what(self, text, topic, time_info): + @staticmethod + def topic_what(text, topic, time_info): prompt = ( f'这是一段文字,{time_info}:{text}。我想让你基于这段文字来概括"{topic}"这个概念,帮我总结成一句自然的话,' f"可以包含时间和人物,以及具体的观点。只输出这句话就好" ) return prompt - def calculate_topic_num(self, text, compress_rate): + @staticmethod + def calculate_topic_num(text, compress_rate): """计算文本的话题数量""" information_content = calculate_information_content(text) topic_by_length = text.count("\n") * compress_rate diff --git a/src/plugins/person_info/person_info.py b/src/plugins/person_info/person_info.py index 59306884a..892653fc2 100644 --- a/src/plugins/person_info/person_info.py +++ b/src/plugins/person_info/person_info.py @@ -72,7 +72,8 @@ class PersonInfoManager: self.person_name_list[doc["person_id"]] = doc["person_name"] logger.debug(f"已加载 {len(self.person_name_list)} 个用户名称") - def get_person_id(self, platform: str, user_id: int): + @staticmethod + def get_person_id(platform: str, user_id: int): """获取唯一id""" # 如果platform中存在-,就截取-后面的部分 if "-" in platform: @@ -91,7 +92,8 @@ class PersonInfoManager: else: return False - async def create_person_info(self, person_id: str, data: dict = None): + @staticmethod + async def create_person_info(person_id: str, data: dict = None): """创建一个项""" if not person_id: logger.debug("创建失败,personid不存在") @@ -131,7 +133,8 @@ class PersonInfoManager: else: return False - def _extract_json_from_text(self, text: str) -> dict: + @staticmethod + def _extract_json_from_text(text: str) -> dict: """从文本中提取JSON数据的高容错方法""" try: # 尝试直接解析 @@ -225,7 +228,8 @@ class PersonInfoManager: logger.error(f"在{max_retries}次尝试后仍未能生成唯一昵称") return None - async def del_one_document(self, person_id: str): + @staticmethod + async def del_one_document(person_id: str): """删除指定 person_id 的文档""" if not person_id: logger.debug("删除失败:person_id 不能为空") @@ -237,7 +241,8 @@ class PersonInfoManager: else: logger.debug(f"删除失败:未找到 person_id={person_id}") - async def get_value(self, person_id: str, field_name: str): + @staticmethod + async def get_value(person_id: str, field_name: str): """获取指定person_id文档的字段值,若不存在该字段,则返回该字段的全局默认值""" if not person_id: logger.debug("get_value获取失败:person_id不能为空") @@ -256,7 +261,8 @@ class PersonInfoManager: logger.trace(f"获取{person_id}的{field_name}失败,已返回默认值{default_value}") return default_value - async def get_values(self, person_id: str, field_names: list) -> dict: + @staticmethod + async def get_values(person_id: str, field_names: list) -> dict: """获取指定person_id文档的多个字段值,若不存在该字段,则返回该字段的全局默认值""" if not person_id: logger.debug("get_values获取失败:person_id不能为空") @@ -281,7 +287,8 @@ class PersonInfoManager: return result - async def del_all_undefined_field(self): + @staticmethod + async def del_all_undefined_field(): """删除所有项里的未定义字段""" # 获取所有已定义的字段名 defined_fields = set(person_info_default.keys()) @@ -307,9 +314,9 @@ class PersonInfoManager: logger.error(f"清理未定义字段时出错: {e}") return + @staticmethod async def get_specific_value_list( - self, - field_name: str, + field_name: str, way: Callable[[Any], bool], # 接受任意类型值 ) -> Dict[str, Any]: """ diff --git a/src/plugins/person_info/relationship_manager.py b/src/plugins/person_info/relationship_manager.py index 696a6391b..deda42fb2 100644 --- a/src/plugins/person_info/relationship_manager.py +++ b/src/plugins/person_info/relationship_manager.py @@ -62,7 +62,7 @@ class RelationshipManager: def mood_feedback(self, value): """情绪反馈""" mood_manager = self.mood_manager - mood_gain = (mood_manager.get_current_mood().valence) ** 2 * math.copysign( + mood_gain = mood_manager.get_current_mood().valence ** 2 * math.copysign( 1, value * mood_manager.get_current_mood().valence ) value += value * mood_gain @@ -77,24 +77,27 @@ class RelationshipManager: else: return mood_value / coefficient - async def is_known_some_one(self, platform, user_id): + @staticmethod + async def is_known_some_one(platform, user_id): """判断是否认识某人""" is_known = person_info_manager.is_person_known(platform, user_id) return is_known - async def is_qved_name(self, platform, user_id): + @staticmethod + async def is_qved_name(platform, user_id): """判断是否认识某人""" person_id = person_info_manager.get_person_id(platform, user_id) is_qved = await person_info_manager.has_one_field(person_id, "person_name") old_name = await person_info_manager.get_value(person_id, "person_name") print(f"old_name: {old_name}") print(f"is_qved: {is_qved}") - if is_qved and old_name != None: + if is_qved and old_name is not None: return True else: return False - async def first_knowing_some_one(self, platform, user_id, user_nickname, user_cardname, user_avatar): + @staticmethod + async def first_knowing_some_one(platform, user_id, user_nickname, user_cardname, user_avatar): """判断是否认识某人""" person_id = person_info_manager.get_person_id(platform, user_id) await person_info_manager.update_one_field(person_id, "nickname", user_nickname) @@ -102,7 +105,8 @@ class RelationshipManager: # await person_info_manager.update_one_field(person_id, "user_avatar", user_avatar) await person_info_manager.qv_person_name(person_id, user_nickname, user_cardname, user_avatar) - async def convert_all_person_sign_to_person_name(self, input_text: str): + @staticmethod + async def convert_all_person_sign_to_person_name(input_text: str): """将所有人的格式转换为person_name""" try: # 使用正则表达式匹配格式 @@ -119,7 +123,7 @@ class RelationshipManager: person_name = nickname.strip() if nickname.strip() else cardname.strip() if person_id in all_person: - if all_person[person_id] != None: + if all_person[person_id] is not None: person_name = all_person[person_id] print(f"将<{platform}:{user_id}:{nickname}:{cardname}>替换为{person_name}") @@ -326,7 +330,8 @@ class RelationshipManager: f"回复态度为{relation_prompt2_list[level_num]},关系等级为{level_num}。" ) - def calculate_level_num(self, relationship_value) -> int: + @staticmethod + def calculate_level_num(relationship_value) -> int: """关系等级计算""" if -1000 <= relationship_value < -227: level_num = 0 @@ -344,7 +349,8 @@ class RelationshipManager: level_num = 5 if relationship_value > 1000 else 0 return level_num - def ensure_float(self, value, person_id): + @staticmethod + def ensure_float(value, person_id): """确保返回浮点数,转换失败返回0.0""" if isinstance(value, float): return value diff --git a/src/plugins/respon_info_catcher/info_catcher.py b/src/plugins/respon_info_catcher/info_catcher.py index 5a602e280..4b19844a8 100644 --- a/src/plugins/respon_info_catcher/info_catcher.py +++ b/src/plugins/respon_info_catcher/info_catcher.py @@ -100,7 +100,8 @@ class InfoCatcher: self.trigger_response_message, first_bot_msg ) - def get_message_from_db_between_msgs(self, message_start: Message, message_end: Message): + @staticmethod + def get_message_from_db_between_msgs(message_start: Message, message_end: Message): try: # 从数据库中获取消息的时间戳 time_start = message_start.message_info.time @@ -155,7 +156,8 @@ class InfoCatcher: return result - def message_to_dict(self, message): + @staticmethod + def message_to_dict(message): if not message: return None if isinstance(message, dict): diff --git a/src/plugins/schedule/schedule_generator.py b/src/plugins/schedule/schedule_generator.py index 3b8638421..7c8103442 100644 --- a/src/plugins/schedule/schedule_generator.py +++ b/src/plugins/schedule/schedule_generator.py @@ -267,7 +267,8 @@ class ScheduleGenerator: db.schedule.update_one({"date": date_str}, {"$set": schedule_data}, upsert=True) logger.debug(f"已保存{date_str}的日程到数据库") - def load_schedule_from_db(self, date: datetime.datetime): + @staticmethod + def load_schedule_from_db(date: datetime.datetime): """从数据库加载日程,同时加载 today_done_list""" date_str = date.strftime("%Y-%m-%d") existing_schedule = db.schedule.find_one({"date": date_str}) diff --git a/src/plugins/storage/storage.py b/src/plugins/storage/storage.py index 577b40340..34864d2cf 100644 --- a/src/plugins/storage/storage.py +++ b/src/plugins/storage/storage.py @@ -10,7 +10,8 @@ logger = get_module_logger("message_storage") class MessageStorage: - async def store_message(self, message: Union[MessageSending, MessageRecv], chat_stream: ChatStream) -> None: + @staticmethod + async def store_message(message: Union[MessageSending, MessageRecv], chat_stream: ChatStream) -> None: """存储消息到数据库""" try: # 莫越权 救世啊 @@ -43,7 +44,8 @@ class MessageStorage: except Exception: logger.exception("存储消息失败") - async def store_recalled_message(self, message_id: str, time: str, chat_stream: ChatStream) -> None: + @staticmethod + async def store_recalled_message(message_id: str, time: str, chat_stream: ChatStream) -> None: """存储撤回消息到数据库""" if "recalled_messages" not in db.list_collection_names(): db.create_collection("recalled_messages") @@ -58,7 +60,8 @@ class MessageStorage: except Exception: logger.exception("存储撤回消息失败") - async def remove_recalled_message(self, time: str) -> None: + @staticmethod + async def remove_recalled_message(time: str) -> None: """删除撤回消息""" try: db.recalled_messages.delete_many({"time": {"$lt": time - 300}}) diff --git a/src/plugins/utils/statistic.py b/src/plugins/utils/statistic.py index af7138744..b1660d720 100644 --- a/src/plugins/utils/statistic.py +++ b/src/plugins/utils/statistic.py @@ -24,7 +24,8 @@ class LLMStatistics: self._init_database() self.name_dict: Dict[List] = {} - def _init_database(self): + @staticmethod + def _init_database(): """初始化数据库集合""" if "online_time" not in db.list_collection_names(): db.create_collection("online_time") @@ -51,7 +52,8 @@ class LLMStatistics: if self.console_thread: self.console_thread.join() - def _record_online_time(self): + @staticmethod + def _record_online_time(): """记录在线时间""" current_time = datetime.now() # 检查5分钟内是否已有记录 @@ -187,7 +189,7 @@ class LLMStatistics: # 按模型统计 output.append("按模型统计:") - output.append(("模型名称 调用次数 Token总量 累计花费")) + output.append("模型名称 调用次数 Token总量 累计花费") for model_name, count in sorted(stats["requests_by_model"].items()): tokens = stats["tokens_by_model"][model_name] cost = stats["costs_by_model"][model_name] @@ -198,7 +200,7 @@ class LLMStatistics: # 按请求类型统计 output.append("按请求类型统计:") - output.append(("模型名称 调用次数 Token总量 累计花费")) + output.append("模型名称 调用次数 Token总量 累计花费") for req_type, count in sorted(stats["requests_by_type"].items()): tokens = stats["tokens_by_type"][req_type] cost = stats["costs_by_type"][req_type] @@ -209,7 +211,7 @@ class LLMStatistics: # 修正用户统计列宽 output.append("按用户统计:") - output.append(("用户ID 调用次数 Token总量 累计花费")) + output.append("用户ID 调用次数 Token总量 累计花费") for user_id, count in sorted(stats["requests_by_user"].items()): tokens = stats["tokens_by_user"][user_id] cost = stats["costs_by_user"][user_id] @@ -225,7 +227,7 @@ class LLMStatistics: # 添加聊天统计 output.append("群组统计:") - output.append(("群组名称 消息数量")) + output.append("群组名称 消息数量") for group_id, count in sorted(stats["messages_by_chat"].items()): output.append(f"{self.name_dict[group_id][0][:32]:<32} {count:>10}") @@ -246,7 +248,7 @@ class LLMStatistics: # 按模型统计 output.append("按模型统计:") - output.append(("模型名称 调用次数 Token总量 累计花费")) + output.append("模型名称 调用次数 Token总量 累计花费") for model_name, count in sorted(stats["requests_by_model"].items()): tokens = stats["tokens_by_model"][model_name] cost = stats["costs_by_model"][model_name] @@ -284,7 +286,7 @@ class LLMStatistics: # 添加聊天统计 output.append("群组统计:") - output.append(("群组名称 消息数量")) + output.append("群组名称 消息数量") for group_id, count in sorted(stats["messages_by_chat"].items()): output.append(f"{self.name_dict[group_id][0][:32]:<32} {count:>10}") diff --git a/src/plugins/utils/timer_calculater.py b/src/plugins/utils/timer_calculater.py index aa12f35ce..13bc26f13 100644 --- a/src/plugins/utils/timer_calculater.py +++ b/src/plugins/utils/timer_calculater.py @@ -90,7 +90,8 @@ class Timer: self.auto_unit = auto_unit self.start = None - def _validate_types(self, name, storage): + @staticmethod + def _validate_types(name, storage): """类型检查""" if name is not None and not isinstance(name, str): raise TimerTypeError("name", "Optional[str]", type(name)) diff --git a/src/plugins/utils/typo_generator.py b/src/plugins/utils/typo_generator.py index 80da6c28a..304a2abe5 100644 --- a/src/plugins/utils/typo_generator.py +++ b/src/plugins/utils/typo_generator.py @@ -77,7 +77,8 @@ class ChineseTypoGenerator: return normalized_freq - def _create_pinyin_dict(self): + @staticmethod + def _create_pinyin_dict(): """ 创建拼音到汉字的映射字典 """ @@ -95,7 +96,8 @@ class ChineseTypoGenerator: return pinyin_dict - def _is_chinese_char(self, char): + @staticmethod + def _is_chinese_char(char): """ 判断是否为汉字 """ @@ -124,7 +126,8 @@ class ChineseTypoGenerator: return result - def _get_similar_tone_pinyin(self, py): + @staticmethod + def _get_similar_tone_pinyin(py): """ 获取相似声调的拼音 """ @@ -211,13 +214,15 @@ class ChineseTypoGenerator: # 返回概率最高的几个字 return [char for char, _ in candidates_with_prob[:num_candidates]] - def _get_word_pinyin(self, word): + @staticmethod + def _get_word_pinyin(word): """ 获取词语的拼音列表 """ return [py[0] for py in pinyin(word, style=Style.TONE3)] - def _segment_sentence(self, sentence): + @staticmethod + def _segment_sentence(sentence): """ 使用jieba分词,返回词语列表 """ @@ -392,7 +397,8 @@ class ChineseTypoGenerator: return "".join(result), correction_suggestion - def format_typo_info(self, typo_info): + @staticmethod + def format_typo_info(typo_info): """ 格式化错别字信息 diff --git a/src/plugins/willing/mode_mxp.py b/src/plugins/willing/mode_mxp.py index 0b847b8fe..78120ac53 100644 --- a/src/plugins/willing/mode_mxp.py +++ b/src/plugins/willing/mode_mxp.py @@ -240,7 +240,8 @@ class MxpWillingManager(BaseWillingManager): -2 * self.basic_maximum_willing * self.fatigue_coefficient ) - def _willing_to_probability(self, willing: float) -> float: + @staticmethod + def _willing_to_probability(willing: float) -> float: """意愿值转化为概率""" willing = max(0, willing) if willing < 2: @@ -285,7 +286,8 @@ class MxpWillingManager(BaseWillingManager): if self.is_debug: self.logger.debug(f"聊天流意愿值更新:{self.chat_reply_willing}") - def _get_relationship_level_num(self, relationship_value) -> int: + @staticmethod + def _get_relationship_level_num(relationship_value) -> int: """关系等级计算""" if -1000 <= relationship_value < -227: level_num = 0 diff --git a/src/plugins/zhishi/knowledge_library.py b/src/plugins/zhishi/knowledge_library.py index 6d046e025..f8914c2f6 100644 --- a/src/plugins/zhishi/knowledge_library.py +++ b/src/plugins/zhishi/knowledge_library.py @@ -35,12 +35,14 @@ class KnowledgeLibrary: """确保必要的目录存在""" os.makedirs(self.raw_info_dir, exist_ok=True) - def read_file(self, file_path: str) -> str: + @staticmethod + def read_file(file_path: str) -> str: """读取文件内容""" with open(file_path, "r", encoding="utf-8") as f: return f.read() - def split_content(self, content: str, max_length: int = 512) -> list: + @staticmethod + def split_content(content: str, max_length: int = 512) -> list: """将内容分割成适当大小的块,按空行分割 Args: @@ -146,7 +148,8 @@ class KnowledgeLibrary: return result - def _update_stats(self, total_stats, result, filename): + @staticmethod + def _update_stats(total_stats, result, filename): """更新总体统计信息""" if result["status"] == "success": total_stats["processed_files"] += 1 @@ -181,7 +184,8 @@ class KnowledgeLibrary: for filename in stats["skipped_files"]: self.console.print(f"[yellow]- {filename}[/yellow]") - def calculate_file_hash(self, file_path): + @staticmethod + def calculate_file_hash(file_path): """计算文件的MD5哈希值""" hash_md5 = hashlib.md5() with open(file_path, "rb") as f: From b305879541d4ff17826b5896bbabf255c74b6fe4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 17 Apr 2025 06:40:04 +0000 Subject: [PATCH 06/12] =?UTF-8?q?=F0=9F=A4=96=20=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/do_tool/tool_can_use/get_knowledge.py | 2 +- src/do_tool/tool_use.py | 2 +- src/plugins/PFC/message_sender.py | 2 +- .../chat_module/reasoning_chat/reasoning_prompt_builder.py | 2 +- .../think_flow_chat/think_flow_prompt_builder.py | 6 +++--- src/plugins/person_info/person_info.py | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/do_tool/tool_can_use/get_knowledge.py b/src/do_tool/tool_can_use/get_knowledge.py index 31d3c2811..0ccac52c4 100644 --- a/src/do_tool/tool_can_use/get_knowledge.py +++ b/src/do_tool/tool_can_use/get_knowledge.py @@ -51,7 +51,7 @@ class SearchKnowledgeTool(BaseTool): @staticmethod def get_info_from_db( - query_embedding: list, limit: int = 1, threshold: float = 0.5, return_raw: bool = False + query_embedding: list, limit: int = 1, threshold: float = 0.5, return_raw: bool = False ) -> Union[str, list]: """从数据库中获取相关信息 diff --git a/src/do_tool/tool_use.py b/src/do_tool/tool_use.py index d2c8df9c5..4cef79a37 100644 --- a/src/do_tool/tool_use.py +++ b/src/do_tool/tool_use.py @@ -26,7 +26,7 @@ class ToolUser: @staticmethod async def _build_tool_prompt( - message_txt: str, sender_name: str, chat_stream: ChatStream, subheartflow: SubHeartflow = None + message_txt: str, sender_name: str, chat_stream: ChatStream, subheartflow: SubHeartflow = None ): """构建工具使用的提示词 diff --git a/src/plugins/PFC/message_sender.py b/src/plugins/PFC/message_sender.py index 3ff7cba01..5a5818ae7 100644 --- a/src/plugins/PFC/message_sender.py +++ b/src/plugins/PFC/message_sender.py @@ -17,7 +17,7 @@ class DirectMessageSender: @staticmethod async def send_message( - chat_stream: ChatStream, + chat_stream: ChatStream, content: str, reply_to_message: Optional[Message] = None, ) -> None: diff --git a/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py b/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py index 1f6943ced..74ad2cdc2 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py @@ -375,7 +375,7 @@ class PromptBuilder: @staticmethod def get_info_from_db( - query_embedding: list, limit: int = 1, threshold: float = 0.5, return_raw: bool = False + query_embedding: list, limit: int = 1, threshold: float = 0.5, return_raw: bool = False ) -> Union[str, list]: if not query_embedding: return "" if not return_raw else [] diff --git a/src/plugins/chat_module/think_flow_chat/think_flow_prompt_builder.py b/src/plugins/chat_module/think_flow_chat/think_flow_prompt_builder.py index f63e98973..ecc20d271 100644 --- a/src/plugins/chat_module/think_flow_chat/think_flow_prompt_builder.py +++ b/src/plugins/chat_module/think_flow_chat/think_flow_prompt_builder.py @@ -66,7 +66,7 @@ class PromptBuilder: @staticmethod async def _build_prompt( - chat_stream, message_txt: str, sender_name: str = "某人", stream_id: Optional[int] = None + chat_stream, message_txt: str, sender_name: str = "某人", stream_id: Optional[int] = None ) -> tuple[str, str]: current_mind_info = heartflow.get_subheartflow(stream_id).current_mind @@ -171,7 +171,7 @@ class PromptBuilder: @staticmethod async def _build_prompt_simple( - chat_stream, message_txt: str, sender_name: str = "某人", stream_id: Optional[int] = None + chat_stream, message_txt: str, sender_name: str = "某人", stream_id: Optional[int] = None ) -> tuple[str, str]: current_mind_info = heartflow.get_subheartflow(stream_id).current_mind @@ -241,7 +241,7 @@ class PromptBuilder: @staticmethod async def _build_prompt_check_response( - chat_stream, + chat_stream, message_txt: str, sender_name: str = "某人", stream_id: Optional[int] = None, diff --git a/src/plugins/person_info/person_info.py b/src/plugins/person_info/person_info.py index 892653fc2..28117d029 100644 --- a/src/plugins/person_info/person_info.py +++ b/src/plugins/person_info/person_info.py @@ -316,7 +316,7 @@ class PersonInfoManager: @staticmethod async def get_specific_value_list( - field_name: str, + field_name: str, way: Callable[[Any], bool], # 接受任意类型值 ) -> Dict[str, Any]: """ From 959401f765dc6c0a6751452a641394f0b5e25b74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=A5=E6=B2=B3=E6=99=B4?= Date: Thu, 17 Apr 2025 15:45:39 +0900 Subject: [PATCH 07/12] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=E6=9C=AA?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84=E5=8F=98=E9=87=8F=E4=BB=A5=E7=AE=80?= =?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=A0=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/PFC/chat_observer.py | 1 - .../chat_module/reasoning_chat/reasoning_generator.py | 1 - .../chat_module/reasoning_chat/reasoning_prompt_builder.py | 6 ++---- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/plugins/PFC/chat_observer.py b/src/plugins/PFC/chat_observer.py index ba2143cf4..1239af7a0 100644 --- a/src/plugins/PFC/chat_observer.py +++ b/src/plugins/PFC/chat_observer.py @@ -119,7 +119,6 @@ class ChatObserver: self.last_cold_chat_check = current_time # 判断是否冷场 - is_cold = False if self.last_message_time is None: is_cold = True else: diff --git a/src/plugins/chat_module/reasoning_chat/reasoning_generator.py b/src/plugins/chat_module/reasoning_chat/reasoning_generator.py index 0fb73cc3c..c9f31990f 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_generator.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_generator.py @@ -69,7 +69,6 @@ class ResponseGenerator: return None async def _generate_response_with_model(self, message: MessageThinking, model: LLMRequest, thinking_id: str): - sender_name = "" info_catcher = info_catcher_manager.get_info_catcher(thinking_id) diff --git a/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py b/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py index 74ad2cdc2..9da416e07 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py @@ -101,16 +101,15 @@ class PromptBuilder: related_memory = await HippocampusManager.get_instance().get_memory_from_text( text=message_txt, max_memory_num=2, max_memory_length=2, max_depth=3, fast_retrieval=False ) + related_memory_info = "" if related_memory: - related_memory_info = "" for memory in related_memory: related_memory_info += memory[1] # memory_prompt = f"你想起你之前见过的事情:{related_memory_info}。\n以上是你的回忆,不一定是目前聊天里的人说的,也不一定是现在发生的事情,请记住。\n" memory_prompt = await global_prompt_manager.format_prompt( "memory_prompt", related_memory_info=related_memory_info ) - else: - related_memory_info = "" + # print(f"相关记忆:{related_memory_info}") @@ -162,7 +161,6 @@ class PromptBuilder: # 知识构建 start_time = time.time() - prompt_info = "" prompt_info = await self.get_prompt_info(message_txt, threshold=0.38) if prompt_info: # prompt_info = f"""\n你有以下这些**知识**:\n{prompt_info}\n请你**记住上面的知识**,之后可能会用到。\n""" From 78d7ce284a5c7f5bfcaa2832788dcaa6e970c257 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 17 Apr 2025 06:46:11 +0000 Subject: [PATCH 08/12] =?UTF-8?q?=F0=9F=A4=96=20=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/chat_module/reasoning_chat/reasoning_generator.py | 1 - .../chat_module/reasoning_chat/reasoning_prompt_builder.py | 1 - 2 files changed, 2 deletions(-) diff --git a/src/plugins/chat_module/reasoning_chat/reasoning_generator.py b/src/plugins/chat_module/reasoning_chat/reasoning_generator.py index c9f31990f..dda4e7c78 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_generator.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_generator.py @@ -69,7 +69,6 @@ class ResponseGenerator: return None async def _generate_response_with_model(self, message: MessageThinking, model: LLMRequest, thinking_id: str): - info_catcher = info_catcher_manager.get_info_catcher(thinking_id) if message.chat_stream.user_info.user_cardname and message.chat_stream.user_info.user_nickname: diff --git a/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py b/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py index 9da416e07..d37d65459 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_prompt_builder.py @@ -110,7 +110,6 @@ class PromptBuilder: "memory_prompt", related_memory_info=related_memory_info ) - # print(f"相关记忆:{related_memory_info}") # 日程构建 From 9a38aeafe1cf304c97f5c3be50caf94b7318d2d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=A5=E6=B2=B3=E6=99=B4?= Date: Thu, 17 Apr 2025 15:56:49 +0900 Subject: [PATCH 09/12] =?UTF-8?q?refactor:=20=E4=BD=BF=E7=94=A8itertools.c?= =?UTF-8?q?ombinations=E7=AE=80=E5=8C=96=E8=8A=82=E7=82=B9=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/memory_system/Hippocampus.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/plugins/memory_system/Hippocampus.py b/src/plugins/memory_system/Hippocampus.py index 7f2d954f7..9c8839ef4 100644 --- a/src/plugins/memory_system/Hippocampus.py +++ b/src/plugins/memory_system/Hippocampus.py @@ -4,6 +4,8 @@ import math import random import time import re +from itertools import combinations + import jieba import networkx as nx import numpy as np @@ -1553,11 +1555,10 @@ class ParahippocampalGyrus: last_modified=current_time, ) - for i in range(len(all_topics)): - for j in range(i + 1, len(all_topics)): - logger.debug(f"连接同批次节点: {all_topics[i]} 和 {all_topics[j]}") - all_added_edges.append(f"{all_topics[i]}-{all_topics[j]}") - self.memory_graph.connect_dot(all_topics[i], all_topics[j]) + for topic1, topic2 in combinations(all_topics, 2): + logger.debug(f"连接同批次节点: {topic1} 和 {topic2}") + all_added_edges.append(f"{topic1}-{topic2}") + self.memory_graph.connect_dot(topic1, topic2) logger.success(f"更新记忆: {', '.join(all_added_nodes)}") logger.debug(f"强化连接: {', '.join(all_added_edges)}") From 2e143d54696a2cb7dd8682a659755a62258b278d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=A5=E6=B2=B3=E6=99=B4?= Date: Thu, 17 Apr 2025 16:04:34 +0900 Subject: [PATCH 10/12] =?UTF-8?q?PEP8:=20=E5=87=BD=E6=95=B0=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E5=8F=98=E9=87=8F=E5=BA=94=E8=AF=A5=E5=B0=8F=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/chat/message_buffer.py | 10 +++++----- .../chat_module/reasoning_chat/reasoning_chat.py | 12 ++++++------ .../chat_module/think_flow_chat/think_flow_chat.py | 12 ++++++------ 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/plugins/chat/message_buffer.py b/src/plugins/chat/message_buffer.py index 10c61a298..d0ab56042 100644 --- a/src/plugins/chat/message_buffer.py +++ b/src/plugins/chat/message_buffer.py @@ -151,20 +151,20 @@ class MessageBuffer: keep_msgs[msg_id] = msg elif msg.result == "F": # 收集F消息的文本内容 - F_type = "seglist" + f_type = "seglist" if msg.message.message_segment.type != "seglist": - F_type = msg.message.message_segment.type + f_type = msg.message.message_segment.type else: if ( isinstance(msg.message.message_segment.data, list) and all(isinstance(x, Seg) for x in msg.message.message_segment.data) and len(msg.message.message_segment.data) == 1 ): - F_type = msg.message.message_segment.data[0].type + f_type = msg.message.message_segment.data[0].type if hasattr(msg.message, "processed_plain_text") and msg.message.processed_plain_text: - if F_type == "text": + if f_type == "text": combined_text.append(msg.message.processed_plain_text) - elif F_type != "text": + elif f_type != "text": is_update = False elif msg.result == "U": logger.debug(f"异常未处理信息id: {msg.message.message_info.message_id}") diff --git a/src/plugins/chat_module/reasoning_chat/reasoning_chat.py b/src/plugins/chat_module/reasoning_chat/reasoning_chat.py index efe37715c..5809e31da 100644 --- a/src/plugins/chat_module/reasoning_chat/reasoning_chat.py +++ b/src/plugins/chat_module/reasoning_chat/reasoning_chat.py @@ -195,21 +195,21 @@ class ReasoningChat: if not buffer_result: await willing_manager.bombing_buffer_message_handle(message.message_info.message_id) willing_manager.delete(message.message_info.message_id) - F_type = "seglist" + f_type = "seglist" if message.message_segment.type != "seglist": - F_type = message.message_segment.type + f_type = message.message_segment.type else: if ( isinstance(message.message_segment.data, list) and all(isinstance(x, Seg) for x in message.message_segment.data) and len(message.message_segment.data) == 1 ): - F_type = message.message_segment.data[0].type - if F_type == "text": + f_type = message.message_segment.data[0].type + if f_type == "text": logger.info(f"触发缓冲,已炸飞消息:{message.processed_plain_text}") - elif F_type == "image": + elif f_type == "image": logger.info("触发缓冲,已炸飞表情包/图片") - elif F_type == "seglist": + elif f_type == "seglist": logger.info("触发缓冲,已炸飞消息列") return diff --git a/src/plugins/chat_module/think_flow_chat/think_flow_chat.py b/src/plugins/chat_module/think_flow_chat/think_flow_chat.py index dc6a91677..4999cb1be 100644 --- a/src/plugins/chat_module/think_flow_chat/think_flow_chat.py +++ b/src/plugins/chat_module/think_flow_chat/think_flow_chat.py @@ -207,21 +207,21 @@ class ThinkFlowChat: if not buffer_result: await willing_manager.bombing_buffer_message_handle(message.message_info.message_id) willing_manager.delete(message.message_info.message_id) - F_type = "seglist" + f_type = "seglist" if message.message_segment.type != "seglist": - F_type = message.message_segment.type + f_type = message.message_segment.type else: if ( isinstance(message.message_segment.data, list) and all(isinstance(x, Seg) for x in message.message_segment.data) and len(message.message_segment.data) == 1 ): - F_type = message.message_segment.data[0].type - if F_type == "text": + f_type = message.message_segment.data[0].type + if f_type == "text": logger.info(f"触发缓冲,已炸飞消息:{message.processed_plain_text}") - elif F_type == "image": + elif f_type == "image": logger.info("触发缓冲,已炸飞表情包/图片") - elif F_type == "seglist": + elif f_type == "seglist": logger.info("触发缓冲,已炸飞消息列") return From df4e0c8494135f1ebc5eb6ae3c1359860a7a6fff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=A5=E6=B2=B3=E6=99=B4?= Date: Thu, 17 Apr 2025 16:12:21 +0900 Subject: [PATCH 11/12] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=96=87=E6=A1=A3=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 修正 change_mood.py 中 execute 函数的错误参数 2. 修正 change_relationship.py 中 execute 函数的错误参数 3. 修正 reply_generator.py 中 generate 函数的错误参数 4. 修正 schedule_generator.py 中 get_current_num_task 函数缺少参数 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .DS_Store | Bin 0 -> 6148 bytes src/do_tool/tool_can_use/change_mood.py | 3 +-- src/do_tool/tool_can_use/change_relationship.py | 4 +--- src/plugins/PFC/reply_generator.py | 7 ++----- src/plugins/schedule/schedule_generator.py | 1 + 5 files changed, 5 insertions(+), 10 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0387394593eb6a564c8dbd9de88228aceaa7c799 GIT binary patch literal 6148 zcmeH~JqiLr422W55Nx)zoW=uqgF*BJUO;rQ5(LG5j_%733$E58@&d`5$tEoO6+06V z(aob@i*zC~hnvdE!pIc+sodozr*nTl9k18RP%+7s)xbL$Js%3WAOR8}0TLhq68ISc zc5cJwi%>=qAOR8>2-yFjz)fpv3-wSKuI zy&YPzuBNuoXcx`lL-WmQQw&U_U9?~W)9S)N0wgdZFpYg@=l>4=Y5pIza7zLt@Mi>c zw%u Date: Thu, 17 Apr 2025 16:23:53 +0900 Subject: [PATCH 12/12] =?UTF-8?q?fix:=20=E9=87=8D=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E4=BB=A5=E9=81=BF=E5=85=8D=E4=B8=8E=E5=86=85?= =?UTF-8?q?=E7=BD=AE=E5=87=BD=E6=95=B0=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 将 Message 类中的 time 参数重命名为 timestamp,避免与 Python 内置模块 time 冲突 2. 在消息处理相关函数中统一使用 timestamp 变量名称 3. 优化 message_storage 查询条件构建方式 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/plugins/PFC/conversation.py | 2 +- src/plugins/PFC/message_storage.py | 4 +--- src/plugins/chat/message.py | 14 +++++++------- src/plugins/chat/utils.py | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/plugins/PFC/conversation.py b/src/plugins/PFC/conversation.py index ba1bf3a78..598468e89 100644 --- a/src/plugins/PFC/conversation.py +++ b/src/plugins/PFC/conversation.py @@ -124,7 +124,7 @@ class Conversation: return Message( message_id=msg_dict["message_id"], chat_stream=chat_stream, - time=msg_dict["time"], + timestamp=msg_dict["time"], user_info=user_info, processed_plain_text=msg_dict.get("processed_plain_text", ""), detailed_plain_text=msg_dict.get("detailed_plain_text", ""), diff --git a/src/plugins/PFC/message_storage.py b/src/plugins/PFC/message_storage.py index b57f5d2b5..cd6a01e34 100644 --- a/src/plugins/PFC/message_storage.py +++ b/src/plugins/PFC/message_storage.py @@ -51,11 +51,9 @@ class MongoDBMessageStorage(MessageStorage): """MongoDB消息存储实现""" async def get_messages_after(self, chat_id: str, message_time: float) -> List[Dict[str, Any]]: - query = {"chat_id": chat_id} + query = {"chat_id": chat_id, "time": {"$gt": message_time}} # print(f"storage_check_message: {message_time}") - query["time"] = {"$gt": message_time} - return list(db.messages.find(query).sort("time", 1)) async def get_messages_before(self, chat_id: str, time_point: float, limit: int = 5) -> List[Dict[str, Any]]: diff --git a/src/plugins/chat/message.py b/src/plugins/chat/message.py index 6279e8f25..525f9da29 100644 --- a/src/plugins/chat/message.py +++ b/src/plugins/chat/message.py @@ -31,7 +31,7 @@ class Message(MessageBase): def __init__( self, message_id: str, - time: float, + timestamp: float, chat_stream: ChatStream, user_info: UserInfo, message_segment: Optional[Seg] = None, @@ -43,7 +43,7 @@ class Message(MessageBase): message_info = BaseMessageInfo( platform=chat_stream.platform, message_id=message_id, - time=time, + time=timestamp, group_info=chat_stream.group_info, user_info=user_info, ) @@ -143,7 +143,7 @@ class MessageRecv(Message): def _generate_detailed_text(self) -> str: """生成详细文本,包含时间和用户信息""" # time_str = time.strftime("%m-%d %H:%M:%S", time.localtime(self.message_info.time)) - time = self.message_info.time + timestamp = self.message_info.time user_info = self.message_info.user_info # name = ( # f"{user_info.user_nickname}(ta的昵称:{user_info.user_cardname},ta的id:{user_info.user_id})" @@ -151,7 +151,7 @@ class MessageRecv(Message): # else f"{user_info.user_nickname}(ta的id:{user_info.user_id})" # ) name = f"<{self.message_info.platform}:{user_info.user_id}:{user_info.user_nickname}:{user_info.user_cardname}>" - return f"[{time}] {name}: {self.processed_plain_text}\n" + return f"[{timestamp}] {name}: {self.processed_plain_text}\n" @dataclass @@ -170,7 +170,7 @@ class MessageProcessBase(Message): # 调用父类初始化 super().__init__( message_id=message_id, - time=round(time.time(), 3), # 保留3位小数 + timestamp=round(time.time(), 3), # 保留3位小数 chat_stream=chat_stream, user_info=bot_user_info, message_segment=message_segment, @@ -242,7 +242,7 @@ class MessageProcessBase(Message): def _generate_detailed_text(self) -> str: """生成详细文本,包含时间和用户信息""" # time_str = time.strftime("%m-%d %H:%M:%S", time.localtime(self.message_info.time)) - time = self.message_info.time + timestamp = self.message_info.time user_info = self.message_info.user_info # name = ( # f"{user_info.user_nickname}(ta的昵称:{user_info.user_cardname},ta的id:{user_info.user_id})" @@ -250,7 +250,7 @@ class MessageProcessBase(Message): # else f"{user_info.user_nickname}(ta的id:{user_info.user_id})" # ) name = f"<{self.message_info.platform}:{user_info.user_id}:{user_info.user_nickname}:{user_info.user_cardname}>" - return f"[{time}] {name}: {self.processed_plain_text}\n" + return f"[{timestamp}] {name}: {self.processed_plain_text}\n" @dataclass diff --git a/src/plugins/chat/utils.py b/src/plugins/chat/utils.py index 06fa6de82..b3ffb9a13 100644 --- a/src/plugins/chat/utils.py +++ b/src/plugins/chat/utils.py @@ -135,7 +135,7 @@ async def get_recent_group_messages(chat_id: str, limit: int = 12) -> list: msg = Message( message_id=msg_data["message_id"], chat_stream=chat_stream, - time=msg_data["time"], + timestamp=msg_data["time"], user_info=user_info, processed_plain_text=msg_data.get("processed_text", ""), detailed_plain_text=msg_data.get("detailed_plain_text", ""),