refactor(core): 提高配置访问安全性并优化记忆判断提示
此提交引入了若干关键改进,以增强应用程序的稳定性和智能性。 首先,通过在 `main.py` 和 `memory_graph/manager_singleton.py` 的关键初始化路径中为 `global_config` 及其嵌套属性添加全面的空值检查,增强了系统的稳健性。这可以防止在配置加载失败或不完整时出现潜在的 `AttributeError` 异常,使应用程序的启动过程更加可靠。 其次,在 `UnifiedMemoryManager` 中的“记忆判断”模型提示已大幅优化。新的提示提供了更严格的指导,避免在简单交互(如问候或闲聊)中进行不必要的长期记忆查询。这一优化通过使记忆检索过程更加高效和具上下文意识,提高了响应速度并降低了计算开销。 最后,新配置已在 Napcat 适配器中添加了选项,以更精细地控制消息处理,包括启用/禁用视频处理和配置自动@回复。
This commit is contained in:
@@ -50,7 +50,7 @@ async def initialize_memory_manager(
|
||||
from src.config.config import global_config
|
||||
|
||||
# 检查是否启用
|
||||
if not global_config.memory or not getattr(global_config.memory, "enable", False):
|
||||
if not global_config or not global_config.memory or not getattr(global_config.memory, "enable", False):
|
||||
logger.info("记忆图系统已在配置中禁用")
|
||||
_initialized = False
|
||||
_memory_manager = None
|
||||
@@ -58,7 +58,7 @@ async def initialize_memory_manager(
|
||||
|
||||
# 处理数据目录
|
||||
if data_dir is None:
|
||||
data_dir = getattr(global_config.memory, "data_dir", "data/memory_graph")
|
||||
data_dir = getattr(global_config.memory, "data_dir", "data/memory_graph") if global_config and global_config.memory else "data/memory_graph"
|
||||
if isinstance(data_dir, str):
|
||||
data_dir = Path(data_dir)
|
||||
|
||||
@@ -136,12 +136,15 @@ async def initialize_unified_memory_manager():
|
||||
from src.memory_graph.unified_manager import UnifiedMemoryManager
|
||||
|
||||
# 检查是否启用三层记忆系统
|
||||
if not hasattr(global_config, "memory") or not getattr(
|
||||
if not global_config or not global_config.memory or not getattr(
|
||||
global_config.memory, "enable", False
|
||||
):
|
||||
logger.warning("三层记忆系统未启用,跳过初始化")
|
||||
return None
|
||||
|
||||
if not global_config or not global_config.memory:
|
||||
logger.warning("未找到内存配置,跳过统一内存管理器初始化。")
|
||||
return None
|
||||
config = global_config.memory
|
||||
|
||||
# 创建管理器实例
|
||||
|
||||
Reference in New Issue
Block a user