From 3b2c97b7bc1802a95024e9a59ce219266b883062 Mon Sep 17 00:00:00 2001 From: Charlie Wang Date: Thu, 20 Mar 2025 22:29:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86bot=E7=AD=89?= =?UTF-8?q?=E5=BE=85=E4=B8=80=E4=B8=AA=E4=BA=BA=E8=AF=B4=E5=AE=8C=E6=89=80?= =?UTF-8?q?=E6=9C=89=E8=AF=9D=E7=9A=84=E5=8A=9F=E8=83=BD=E5=92=8C=E9=80=9A?= =?UTF-8?q?=E8=BF=87at=E5=BF=AB=E9=80=9F=E5=A2=9E=E5=8A=A0=E5=A5=BD?= =?UTF-8?q?=E6=84=9F=E5=BA=A6=E7=9A=84=E5=8A=9F=E8=83=BD(sec/plugins/chat/?= =?UTF-8?q?bot.py)=20=E7=BB=99=E5=8F=AF=E8=A7=86=E5=8C=96=E6=8E=A8?= =?UTF-8?q?=E7=90=86/=E8=AE=B0=E5=BF=86=E5=8A=A0=E4=BA=86sys.path.insert?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=E6=89=BE=E4=B8=8D=E5=88=B0src=20requirements?= =?UTF-8?q?=E5=8A=A0=E4=BA=86scipy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | Bin 658 -> 672 bytes src/gui/reasoning_gui.py | 2 + src/plugins/chat/bot.py | 49 ++++++++++++++++-- .../memory_system/memory_manual_build.py | 6 +++ 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index 1e9e5ff25b8c4ccae9904607247966efcd269ab7..0dfd751484930ec11fed6da3b69ff72e6f5be121 100644 GIT binary patch delta 22 dcmbQlx`1`VBqlyy1}=tThGd3Jh60941^_ None: + groupinfo = message.message_info.group_info + userinfo = message.message_info.user_info + messageinfo = message.message_info + # 过滤词 for word in global_config.ban_words: if word in message.processed_plain_text: @@ -120,7 +137,15 @@ class ChatBot: await self.storage.store_message(message, chat, topic[0] if topic else None) - is_mentioned = is_mentioned_bot_in_message(message) + is_mentioned = is_mentioned_bot_in_message(message) or groupID == -1 + if is_mentioned: + relationship_value = relationship_manager.get_relationship(chat).relationship_value if relationship_manager.get_relationship(chat) else 0.0 + await relationship_manager.update_relationship( + chat_stream=chat, + ) + await relationship_manager.update_relationship_value( + chat_stream=chat, relationship_value = min(max(40 - relationship_value, 2)/2, 10000) + ) reply_probability = await willing_manager.change_reply_willing_received( chat_stream=chat, is_mentioned_bot=is_mentioned, @@ -130,15 +155,27 @@ class ChatBot: sender_id=str(message.message_info.user_info.user_id), ) current_willing = willing_manager.get_willing(chat_stream=chat) - + actual_prob = random() logger.info( f"[{current_time}][{chat.group_info.group_name if chat.group_info else '私聊'}]{chat.user_info.user_nickname}:" f"{message.processed_plain_text}[回复意愿:{current_willing:.2f}][概率:{reply_probability * 100:.1f}%]" ) - + reply_probability = 1 if is_mentioned else reply_probability + logger.info("!!!决定回复!!!" if actual_prob < reply_probability else "===不理===") + response = None # 开始组织语言 - if random() < reply_probability: + if groupID not in self.group_message_dict: + self.group_message_dict[groupID] = {} + this_msg_time = time.time() + if userinfo.user_id not in self.group_message_dict[groupID].keys(): + self.group_message_dict[groupID][userinfo.user_id] = -1 + + if (actual_prob < reply_probability) or (self.group_message_dict[groupID][userinfo.user_id] != -1): + self.group_message_dict[groupID][userinfo.user_id] = this_msg_time + await asyncio.sleep(30) + if this_msg_time != self.group_message_dict[groupID][userinfo.user_id]: + return bot_user_info = UserInfo( user_id=global_config.BOT_QQ, user_nickname=global_config.BOT_NICKNAME, @@ -168,6 +205,8 @@ class ChatBot: # print(f"response: {response}") if response: # print(f"有response: {response}") + if this_msg_time == self.group_message_dict[groupID][userinfo.user_id]: + self.group_message_dict[groupID][userinfo.user_id] = -1 container = message_manager.get_container(chat.stream_id) thinking_message = None # 找到message,删除 diff --git a/src/plugins/memory_system/memory_manual_build.py b/src/plugins/memory_system/memory_manual_build.py index 9b01640a9..3b4b2af82 100644 --- a/src/plugins/memory_system/memory_manual_build.py +++ b/src/plugins/memory_system/memory_manual_build.py @@ -11,6 +11,12 @@ from pathlib import Path import matplotlib.pyplot as plt import networkx as nx from dotenv import load_dotenv +sys.path.insert(0, sys.path[0]+"/../") +sys.path.insert(0, sys.path[0]+"/../") +sys.path.insert(0, sys.path[0]+"/../") +sys.path.insert(0, sys.path[0]+"/../") +sys.path.insert(0, sys.path[0]+"/../") +print(sys.path) from src.common.logger import get_module_logger import jieba