diff --git a/src/common/database/optimization/redis_cache.py b/src/common/database/optimization/redis_cache.py index 8dd00a44c..558ec8544 100644 --- a/src/common/database/optimization/redis_cache.py +++ b/src/common/database/optimization/redis_cache.py @@ -20,6 +20,7 @@ from src.common.logger import get_logger logger = get_logger("redis_cache") import redis.asyncio as aioredis +from redis.asyncio.connection import Connection, SSLConnection class RedisCache(CacheBackend): @@ -98,7 +99,11 @@ class RedisCache(CacheBackend): return self._client try: - # 创建连接池 (使用 aioredis 模块确保类型安全) + # redis-py 7.x+ 使用 connection_class 来指定 SSL 连接 + # 不再支持直接传递 ssl=True/False 给 ConnectionPool + connection_class = SSLConnection if self.ssl else Connection + + # 创建连接池 self._pool = aioredis.ConnectionPool( host=self.host, port=self.port, @@ -108,7 +113,7 @@ class RedisCache(CacheBackend): socket_timeout=self.socket_timeout, socket_connect_timeout=self.socket_timeout, decode_responses=False, # 我们自己处理序列化 - ssl=self.ssl, + connection_class=connection_class, ) # 创建客户端 diff --git a/src/config/config.py b/src/config/config.py index 43b0d2229..cf2c0387d 100644 --- a/src/config/config.py +++ b/src/config/config.py @@ -506,24 +506,16 @@ def load_config(config_path: str) -> Config: with open(config_path, encoding="utf-8") as f: config_data = tomlkit.load(f) + # 将 tomlkit 对象转换为纯 Python 字典,避免 Pydantic 严格模式下的类型验证问题 + # tomlkit 返回的是特殊类型(如 Array、String 等),虽然继承自 Python 标准类型, + # 但在 Pydantic 严格模式下可能导致类型验证失败 + config_dict = config_data.unwrap() + # 创建Config对象(各个配置类会自动进行 Pydantic 验证) try: logger.debug("正在解析和验证配置文件...") - config = Config.from_dict(config_data) + config = Config.from_dict(config_dict) logger.debug("配置文件解析和验证完成") - - # 【临时修复】在验证后,手动从原始数据重新加载 master_users - try: - # 先将 tomlkit 对象转换为纯 Python 字典 - config_dict = config_data.unwrap() - if "permission" in config_dict and "master_users" in config_dict["permission"]: - raw_master_users = config_dict["permission"]["master_users"] - # 现在 raw_master_users 就是一个标准的 Python 列表了 - config.permission.master_users = raw_master_users - logger.debug(f"【临时修复】已手动将 master_users 设置为: {config.permission.master_users}") - except Exception as patch_exc: - logger.error(f"【临时修复】手动设置 master_users 失败: {patch_exc}") - return config except Exception as e: logger.critical(f"配置文件解析失败: {e}") @@ -581,4 +573,4 @@ def initialize_configs_once() -> tuple[Config, APIAdapterConfig]: # 同一进程只执行一次初始化,避免重复生成或覆盖配置 global_config, model_config = initialize_configs_once() -logger.debug("非常的新鲜,非常的美味!") \ No newline at end of file +logger.debug("非常的新鲜,非常的美味!") diff --git a/src/memory_graph/short_term_manager.py b/src/memory_graph/short_term_manager.py index cc75cd5c7..2f94059ec 100644 --- a/src/memory_graph/short_term_manager.py +++ b/src/memory_graph/short_term_manager.py @@ -11,6 +11,7 @@ import asyncio import json import re import uuid +import json_repair from pathlib import Path from typing import Any @@ -186,8 +187,8 @@ class ShortTermMemoryManager: "importance": 0.7, "attributes": {{ "time": "时间信息", - "attribute1": "其他属性1" - "attribute2": "其他属性2" + "attribute1": "其他属性1", + "attribute2": "其他属性2", ... }} }} @@ -530,7 +531,7 @@ class ShortTermMemoryManager: json_str = re.sub(r"//.*", "", json_str) json_str = re.sub(r"/\*.*?\*/", "", json_str, flags=re.DOTALL) - data = json.loads(json_str) + data = json_repair.loads(json_str) return data except json.JSONDecodeError as e: