diff --git a/docs/manual_deploy.md b/docs/manual_deploy.md index ef58a6d9c..6d53beb4e 100644 --- a/docs/manual_deploy.md +++ b/docs/manual_deploy.md @@ -26,7 +26,25 @@ ## 如果准备好了,就可以开始部署了 -### 1️⃣ **我们需要创建一个Python环境来运行程序** +### 1️⃣ **首先,我们需要安装正确版本的Python** + +在创建虚拟环境之前,请确保你的电脑上安装了Python 3.9及以上版本。如果没有,可以按以下步骤安装: + +1. 访问Python官网下载页面:https://www.python.org/downloads/release/python-3913/ +2. 下载Windows安装程序 (64-bit): `python-3.9.13-amd64.exe` +3. 运行安装程序,并确保勾选"Add Python 3.9 to PATH"选项 +4. 点击"Install Now"开始安装 + +或者使用PowerShell自动下载安装(需要管理员权限): +```powershell +# 下载并安装Python 3.9.13 +$pythonUrl = "https://www.python.org/ftp/python/3.9.13/python-3.9.13-amd64.exe" +$pythonInstaller = "$env:TEMP\python-3.9.13-amd64.exe" +Invoke-WebRequest -Uri $pythonUrl -OutFile $pythonInstaller +Start-Process -Wait -FilePath $pythonInstaller -ArgumentList "/quiet", "InstallAllUsers=0", "PrependPath=1" -Verb RunAs +``` + +### 2️⃣ **创建Python虚拟环境来运行程序** 你可以选择使用以下两种方法之一来创建Python环境: diff --git a/run_maimai.bat b/run_maimai.bat index ff00cc5c1..3a099fd7f 100644 --- a/run_maimai.bat +++ b/run_maimai.bat @@ -1,5 +1,5 @@ chcp 65001 -call conda activate niuniu +call conda activate maimbot cd . REM 执行nb run命令 diff --git a/src/plugins/chat/config.py b/src/plugins/chat/config.py index 92b259ebd..0b47e5d3d 100644 --- a/src/plugins/chat/config.py +++ b/src/plugins/chat/config.py @@ -148,15 +148,6 @@ class BotConfig: if "rerank" in model_config: config.rerank = model_config["rerank"] - if 'topic' in toml_dict: - topic_config=toml_dict['topic'] - if 'topic_extract' in topic_config: - config.topic_extract=topic_config.get('topic_extract',config.topic_extract) - logger.info(f"载入自定义主题提取为{config.topic_extract}") - if config.topic_extract=='llm' and 'llm_topic' in topic_config: - config.llm_topic_extract=topic_config['llm_topic'] - logger.info(f"载入自定义主题提取模型为{config.llm_topic_extract['name']}") - # 消息配置 if "message" in toml_dict: msg_config = toml_dict["message"] @@ -190,13 +181,13 @@ class BotConfig: bot_config_floder_path = BotConfig.get_config_dir() print(f"正在品鉴配置文件目录: {bot_config_floder_path}") -bot_config_path = os.path.join(bot_config_floder_path, "bot_config_dev.toml") -if not os.path.exists(bot_config_path): +bot_config_path = os.path.join(bot_config_floder_path, "bot_config.toml") +if os.path.exists(bot_config_path): # 如果开发环境配置文件不存在,则使用默认配置文件 - bot_config_path = os.path.join(bot_config_floder_path, "bot_config.toml") + print(f"异常的新鲜,异常的美味: {bot_config_path}") logger.info("使用bot配置文件") else: - logger.info("已找到开发bot配置文件") + logger.info("没有找到美味") global_config = BotConfig.load_config(config_path=bot_config_path) diff --git a/src/plugins/chat/topic_identifier.py b/src/plugins/chat/topic_identifier.py index 4580c1e91..8e6d41c7d 100644 --- a/src/plugins/chat/topic_identifier.py +++ b/src/plugins/chat/topic_identifier.py @@ -12,9 +12,7 @@ config = driver.config class TopicIdentifier: def __init__(self): self.llm_client = LLM_request(model=global_config.llm_topic_extract) - self.select=global_config.topic_extract - async def identify_topic_llm(self, text: str) -> Optional[List[str]]: """识别消息主题,返回主题列表""" diff --git a/src/plugins/memory_system/memory.py b/src/plugins/memory_system/memory.py index a25e15bdf..fd001e791 100644 --- a/src/plugins/memory_system/memory.py +++ b/src/plugins/memory_system/memory.py @@ -578,14 +578,11 @@ class Hippocampus: async def memory_activate_value(self, text: str, max_topics: int = 5, similarity_threshold: float = 0.3) -> int: """计算输入文本对记忆的激活程度""" - print(f"\033[1;32m[记忆激活]\033[0m 开始计算文本的记忆激活度: {text}") + print(f"\033[1;32m[记忆激活]\033[0m 识别主题: {await self._identify_topics(text)}") # 识别主题 identified_topics = await self._identify_topics(text) - print(f"\033[1;32m[记忆激活]\033[0m 识别出的主题: {identified_topics}") - if not identified_topics: - # print(f"\033[1;32m[记忆激活]\033[0m 未识别出主题,返回0") return 0 # 查找相似主题 @@ -596,7 +593,6 @@ class Hippocampus: ) if not all_similar_topics: - print(f"\033[1;32m[记忆激活]\033[0m 未找到相似主题,返回0") return 0 # 获取最相关的主题 @@ -605,19 +601,29 @@ class Hippocampus: # 如果只找到一个主题,进行惩罚 if len(top_topics) == 1: topic, score = top_topics[0] - activation = int(score * 50) # 单主题情况下,直接用相似度*50作为激活值 - print(f"\033[1;32m[记忆激活]\033[0m 只找到一个主题,进行惩罚:") - print(f"\033[1;32m[记忆激活]\033[0m - 主题: {topic}") - print(f"\033[1;32m[记忆激活]\033[0m - 相似度: {score:.3f}") - print(f"\033[1;32m[记忆激活]\033[0m - 最终激活值: {activation}") + # 获取主题内容数量并计算惩罚系数 + memory_items = self.memory_graph.G.nodes[topic].get('memory_items', []) + if not isinstance(memory_items, list): + memory_items = [memory_items] if memory_items else [] + content_count = len(memory_items) + penalty = 1.0 / (1 + math.log(content_count + 1)) + + activation = int(score * 50 * penalty) + print(f"\033[1;32m[记忆激活]\033[0m 单主题「{topic}」- 相似度: {score:.3f}, 内容数: {content_count}, 激活值: {activation}") return activation - # 计算关键词匹配率 + # 计算关键词匹配率,同时考虑内容数量 matched_topics = set() topic_similarities = {} - print(f"\033[1;32m[记忆激活]\033[0m 计算关键词匹配情况:") for memory_topic, similarity in top_topics: + # 计算内容数量惩罚 + memory_items = self.memory_graph.G.nodes[memory_topic].get('memory_items', []) + if not isinstance(memory_items, list): + memory_items = [memory_items] if memory_items else [] + content_count = len(memory_items) + penalty = 1.0 / (1 + math.log(content_count + 1)) + # 对每个记忆主题,检查它与哪些输入主题相似 for input_topic in identified_topics: topic_vector = text_to_vector(input_topic) @@ -628,27 +634,19 @@ class Hippocampus: sim = cosine_similarity(v1, v2) if sim >= similarity_threshold: matched_topics.add(input_topic) - topic_similarities[input_topic] = max(topic_similarities.get(input_topic, 0), sim) - print(f"\033[1;32m[记忆激活]\033[0m - 输入主题「{input_topic}」匹配到记忆「{memory_topic}」, 相似度: {sim:.3f}") + adjusted_sim = sim * penalty + topic_similarities[input_topic] = max(topic_similarities.get(input_topic, 0), adjusted_sim) + print(f"\033[1;32m[记忆激活]\033[0m 主题「{input_topic}」-> 「{memory_topic}」(内容数: {content_count}, 相似度: {adjusted_sim:.3f})") - # 计算主题匹配率 + # 计算主题匹配率和平均相似度 topic_match = len(matched_topics) / len(identified_topics) - print(f"\033[1;32m[记忆激活]\033[0m 主题匹配率:") - print(f"\033[1;32m[记忆激活]\033[0m - 匹配主题数: {len(matched_topics)}") - print(f"\033[1;32m[记忆激活]\033[0m - 总主题数: {len(identified_topics)}") - print(f"\033[1;32m[记忆激活]\033[0m - 匹配率: {topic_match:.3f}") - - # 计算匹配主题的平均相似度 average_similarities = sum(topic_similarities.values()) / len(topic_similarities) if topic_similarities else 0 - print(f"\033[1;32m[记忆激活]\033[0m 平均相似度:") - print(f"\033[1;32m[记忆激活]\033[0m - 各主题相似度: {[f'{k}:{v:.3f}' for k,v in topic_similarities.items()]}") - print(f"\033[1;32m[记忆激活]\033[0m - 平均相似度: {average_similarities:.3f}") # 计算最终激活值 - activation = (topic_match + average_similarities) / 2 * 100 - print(f"\033[1;32m[记忆激活]\033[0m 最终激活值: {int(activation)}") + activation = int((topic_match + average_similarities) / 2 * 100) + print(f"\033[1;32m[记忆激活]\033[0m 匹配率: {topic_match:.3f}, 平均相似度: {average_similarities:.3f}, 激活值: {activation}") - return int(activation) + return activation async def get_relevant_memories(self, text: str, max_topics: int = 5, similarity_threshold: float = 0.4, max_memory_num: int = 5) -> list: """根据输入文本获取相关的记忆内容"""