From 6c35704e70bcd1f2861f68b9e87f4309f67be22c Mon Sep 17 00:00:00 2001 From: jiajiu123 <1771663559@qq.com> Date: Sun, 9 Mar 2025 23:12:48 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20=E8=B0=83=E7=94=A8=E4=BA=86=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.py b/run.py index 5546d1faa..baea4d13c 100644 --- a/run.py +++ b/run.py @@ -98,7 +98,7 @@ def install_mongodb_compass(): run_cmd(r"powershell mongodb\bin\Install-Compass.ps1") input("按任意键启动麦麦") input("如不需要启动此窗口可直接关闭,无需等待 Compass 安装完成") - install_mongodb_compass() + run_maimbot() def install_napcat(): From 665c4593e12007bde95c7633c1e5fbfa8931372d Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Sun, 9 Mar 2025 23:19:12 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E4=BA=86=E5=8F=AF?= =?UTF-8?q?=E8=A7=86=E5=8C=96=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1 --- run_memory_vis.bat | 13 ++- src/plugins/memory_system/draw_memory.py | 79 +++---------------- .../memory_system/memory_manual_build.py | 2 +- 3 files changed, 23 insertions(+), 71 deletions(-) diff --git a/run_memory_vis.bat b/run_memory_vis.bat index 14b9c766f..b1feb0cb2 100644 --- a/run_memory_vis.bat +++ b/run_memory_vis.bat @@ -8,7 +8,18 @@ if errorlevel 1 ( exit /b 1 ) echo Conda 环境 "%CONDA_ENV%" 激活成功 -python src/plugins/memory_system/memory_manual_build.py + +set /p OPTION="请选择运行选项 (1: 运行全部绘制, 2: 运行简单绘制): " +if "%OPTION%"=="1" ( + python src/plugins/memory_system/memory_manual_build.py +) else if "%OPTION%"=="2" ( + python src/plugins/memory_system/draw_memory.py +) else ( + echo 无效的选项 + pause + exit /b 1 +) + if errorlevel 1 ( echo 命令执行失败,错误代码 %errorlevel% pause diff --git a/src/plugins/memory_system/draw_memory.py b/src/plugins/memory_system/draw_memory.py index 006991bcb..c2d04064d 100644 --- a/src/plugins/memory_system/draw_memory.py +++ b/src/plugins/memory_system/draw_memory.py @@ -201,67 +201,6 @@ def topic_what(text, topic): prompt = f'这是一段文字:{text}。我想知道这记忆里有什么关于{topic}的话题,帮我总结成一句自然的话,可以包含时间和人物。只输出这句话就好' return prompt -def visualize_graph(memory_graph: Memory_graph, color_by_memory: bool = False): - # 设置中文字体 - plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签 - plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号 - - G = memory_graph.G - - # 保存图到本地 - nx.write_gml(G, "memory_graph.gml") # 保存为 GML 格式 - - # 根据连接条数或记忆数量设置节点颜色 - node_colors = [] - nodes = list(G.nodes()) # 获取图中实际的节点列表 - - if color_by_memory: - # 计算每个节点的记忆数量 - memory_counts = [] - for node in nodes: - memory_items = G.nodes[node].get('memory_items', []) - if isinstance(memory_items, list): - count = len(memory_items) - else: - count = 1 if memory_items else 0 - memory_counts.append(count) - max_memories = max(memory_counts) if memory_counts else 1 - - for count in memory_counts: - # 使用不同的颜色方案:红色表示记忆多,蓝色表示记忆少 - if max_memories > 0: - intensity = min(1.0, count / max_memories) - color = (intensity, 0, 1.0 - intensity) # 从蓝色渐变到红色 - else: - color = (0, 0, 1) # 如果没有记忆,则为蓝色 - node_colors.append(color) - else: - # 使用原来的连接数量着色方案 - max_degree = max(G.degree(), key=lambda x: x[1])[1] if G.degree() else 1 - for node in nodes: - degree = G.degree(node) - if max_degree > 0: - red = min(1.0, degree / max_degree) - blue = 1.0 - red - color = (red, 0, blue) - else: - color = (0, 0, 1) - node_colors.append(color) - - # 绘制图形 - plt.figure(figsize=(12, 8)) - pos = nx.spring_layout(G, k=1, iterations=50) - nx.draw(G, pos, - with_labels=True, - node_color=node_colors, - node_size=200, - font_size=10, - font_family='SimHei', - font_weight='bold') - - title = '记忆图谱可视化 - ' + ('按记忆数量着色' if color_by_memory else '按连接数量着色') - plt.title(title, fontsize=16, fontfamily='SimHei') - plt.show() def visualize_graph_lite(memory_graph: Memory_graph, color_by_memory: bool = False): @@ -280,7 +219,7 @@ def visualize_graph_lite(memory_graph: Memory_graph, color_by_memory: bool = Fal memory_items = H.nodes[node].get('memory_items', []) memory_count = len(memory_items) if isinstance(memory_items, list) else (1 if memory_items else 0) degree = H.degree(node) - if memory_count < 5 or degree < 2: # 改为小于2而不是小于等于2 + if memory_count < 3 or degree < 2: # 改为小于2而不是小于等于2 nodes_to_remove.append(node) H.remove_nodes_from(nodes_to_remove) @@ -291,7 +230,7 @@ def visualize_graph_lite(memory_graph: Memory_graph, color_by_memory: bool = Fal return # 保存图到本地 - nx.write_gml(H, "memory_graph.gml") # 保存为 GML 格式 + # nx.write_gml(H, "memory_graph.gml") # 保存为 GML 格式 # 计算节点大小和颜色 node_colors = [] @@ -315,21 +254,23 @@ def visualize_graph_lite(memory_graph: Memory_graph, color_by_memory: bool = Fal memory_count = len(memory_items) if isinstance(memory_items, list) else (1 if memory_items else 0) # 使用指数函数使变化更明显 ratio = memory_count / max_memories - size = 500 + 5000 * (ratio ** 2) # 使用平方函数使差异更明显 + size = 500 + 5000 * (ratio ) # 使用1.5次方函数使差异不那么明显 node_sizes.append(size) # 计算节点颜色(基于连接数) degree = H.degree(node) # 红色分量随着度数增加而增加 - red = min(1.0, degree / max_degree) + r = (degree / max_degree) ** 0.3 + red = min(1.0, r) # 蓝色分量随着度数减少而增加 - blue = 1.0 - red - color = (red, 0, blue) + blue = max(0.0, 1 - red) + # blue = 1 + color = (red, 0.1, blue) node_colors.append(color) # 绘制图形 plt.figure(figsize=(12, 8)) - pos = nx.spring_layout(H, k=1.5, iterations=50) # 增加k值使节点分布更开 + pos = nx.spring_layout(H, k=1, iterations=50) # 增加k值使节点分布更开 nx.draw(H, pos, with_labels=True, node_color=node_colors, @@ -339,7 +280,7 @@ def visualize_graph_lite(memory_graph: Memory_graph, color_by_memory: bool = Fal font_weight='bold', edge_color='gray', width=0.5, - alpha=0.7) + alpha=0.9) title = '记忆图谱可视化 - 节点大小表示记忆数量,颜色表示连接数' plt.title(title, fontsize=16, fontfamily='SimHei') diff --git a/src/plugins/memory_system/memory_manual_build.py b/src/plugins/memory_system/memory_manual_build.py index 2e1151f93..db88febf2 100644 --- a/src/plugins/memory_system/memory_manual_build.py +++ b/src/plugins/memory_system/memory_manual_build.py @@ -944,7 +944,7 @@ async def main(): db = Database.get_instance() start_time = time.time() - test_pare = {'do_build_memory':True,'do_forget_topic':False,'do_visualize_graph':True,'do_query':False,'do_merge_memory':False} + test_pare = {'do_build_memory':False,'do_forget_topic':False,'do_visualize_graph':True,'do_query':False,'do_merge_memory':False} # 创建记忆图 memory_graph = Memory_graph() From 8661d949767de50664bde15f6736bfa1a5546cc2 Mon Sep 17 00:00:00 2001 From: CabLate Date: Mon, 10 Mar 2025 00:46:34 +0800 Subject: [PATCH 3/5] doc: README.md - telegram version information --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 575dc8232..0c02d1cba 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,10 @@ **交流群**: 571780722 另一个群(开发和建议相关讨论)不一定有空回复,会优先写文档和代码 **交流群**: 1035228475 另一个群(开发和建议相关讨论)不一定有空回复,会优先写文档和代码 +**其他平台版本** + +- (由 [CabLate](https://github.com/cablate) 贡献) [Telegram 与其他平台(未来可能会有)的版本](https://github.com/cablate/MaiMBot/tree/telegram) - [集中讨论串](https://github.com/SengokuCola/MaiMBot/discussions/149) + ##

📚 文档 ⬇️ 快速开始使用麦麦 ⬇️

From 536bb1d9238db77e79446b3a8f1684663679f53e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=B4=E7=8C=AB?= Date: Mon, 10 Mar 2025 02:26:13 +0900 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E6=83=85=E6=84=9F?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=A8=A1=E5=9E=8B=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/chat/emoji_manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/chat/emoji_manager.py b/src/plugins/chat/emoji_manager.py index 4f2637738..614bfe025 100644 --- a/src/plugins/chat/emoji_manager.py +++ b/src/plugins/chat/emoji_manager.py @@ -33,7 +33,7 @@ class EmojiManager: self.db = Database.get_instance() self._scan_task = None self.vlm = LLM_request(model=global_config.vlm, temperature=0.3, max_tokens=1000) - self.llm_emotion_judge = LLM_request(model=global_config.llm_normal_minor, max_tokens=60,temperature=0.8) #更高的温度,更少的token(后续可以根据情绪来调整温度) + self.llm_emotion_judge = LLM_request(model=global_config.llm_emotion_judge, max_tokens=60,temperature=0.8) #更高的温度,更少的token(后续可以根据情绪来调整温度) def _ensure_emoji_dir(self): """确保表情存储目录存在""" @@ -330,4 +330,4 @@ class EmojiManager: # 创建全局单例 -emoji_manager = EmojiManager() \ No newline at end of file +emoji_manager = EmojiManager() From a7f9d05c010689c5137a0a5007a6b112ad4a4056 Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Mon, 10 Mar 2025 01:40:06 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=B0=E5=BF=86?= =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BC=A0=E5=85=A5=E6=A0=BC=E5=BC=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/chat/utils.py | 40 ++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/plugins/chat/utils.py b/src/plugins/chat/utils.py index d166bcd27..f8331a148 100644 --- a/src/plugins/chat/utils.py +++ b/src/plugins/chat/utils.py @@ -98,37 +98,43 @@ def calculate_information_content(text): def get_cloest_chat_from_db(db, length: int, timestamp: str): - """从数据库中获取最接近指定时间戳的聊天记录,并记录读取次数""" - chat_text = '' + """从数据库中获取最接近指定时间戳的聊天记录,并记录读取次数 + + Returns: + list: 消息记录字典列表,每个字典包含消息内容和时间信息 + """ + chat_records = [] closest_record = db.db.messages.find_one({"time": {"$lte": timestamp}}, sort=[('time', -1)]) - - if closest_record and closest_record.get('memorized', 0) < 4: + + if closest_record and closest_record.get('memorized', 0) < 4: closest_time = closest_record['time'] - group_id = closest_record['group_id'] # 获取groupid + group_id = closest_record['group_id'] # 获取该时间戳之后的length条消息,且groupid相同 - chat_records = list(db.db.messages.find( + records = list(db.db.messages.find( {"time": {"$gt": closest_time}, "group_id": group_id} ).sort('time', 1).limit(length)) - + # 更新每条消息的memorized属性 - for record in chat_records: - # 检查当前记录的memorized值 + for record in records: current_memorized = record.get('memorized', 0) if current_memorized > 3: - # print(f"消息已读取3次,跳过") + print("消息已读取3次,跳过") return '' - + # 更新memorized值 db.db.messages.update_one( {"_id": record["_id"]}, {"$set": {"memorized": current_memorized + 1}} ) - - chat_text += record["detailed_plain_text"] - - return chat_text - # print(f"消息已读取3次,跳过") - return '' + + # 添加到记录列表中 + chat_records.append({ + 'text': record["detailed_plain_text"], + 'time': record["time"], + 'group_id': record["group_id"] + }) + + return chat_records async def get_recent_group_messages(db, group_id: int, limit: int = 12) -> list: