Merge branch 'dev' of https://github.com/MoFox-Studio/MoFox-Core into dev
This commit is contained in:
@@ -20,6 +20,7 @@ from src.common.logger import get_logger
|
|||||||
logger = get_logger("redis_cache")
|
logger = get_logger("redis_cache")
|
||||||
|
|
||||||
import redis.asyncio as aioredis
|
import redis.asyncio as aioredis
|
||||||
|
from redis.asyncio.connection import Connection, SSLConnection
|
||||||
|
|
||||||
|
|
||||||
class RedisCache(CacheBackend):
|
class RedisCache(CacheBackend):
|
||||||
@@ -98,7 +99,11 @@ class RedisCache(CacheBackend):
|
|||||||
return self._client
|
return self._client
|
||||||
|
|
||||||
try:
|
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(
|
self._pool = aioredis.ConnectionPool(
|
||||||
host=self.host,
|
host=self.host,
|
||||||
port=self.port,
|
port=self.port,
|
||||||
@@ -108,7 +113,7 @@ class RedisCache(CacheBackend):
|
|||||||
socket_timeout=self.socket_timeout,
|
socket_timeout=self.socket_timeout,
|
||||||
socket_connect_timeout=self.socket_timeout,
|
socket_connect_timeout=self.socket_timeout,
|
||||||
decode_responses=False, # 我们自己处理序列化
|
decode_responses=False, # 我们自己处理序列化
|
||||||
ssl=self.ssl,
|
connection_class=connection_class,
|
||||||
)
|
)
|
||||||
|
|
||||||
# 创建客户端
|
# 创建客户端
|
||||||
|
|||||||
@@ -506,24 +506,16 @@ def load_config(config_path: str) -> Config:
|
|||||||
with open(config_path, encoding="utf-8") as f:
|
with open(config_path, encoding="utf-8") as f:
|
||||||
config_data = tomlkit.load(f)
|
config_data = tomlkit.load(f)
|
||||||
|
|
||||||
|
# 将 tomlkit 对象转换为纯 Python 字典,避免 Pydantic 严格模式下的类型验证问题
|
||||||
|
# tomlkit 返回的是特殊类型(如 Array、String 等),虽然继承自 Python 标准类型,
|
||||||
|
# 但在 Pydantic 严格模式下可能导致类型验证失败
|
||||||
|
config_dict = config_data.unwrap()
|
||||||
|
|
||||||
# 创建Config对象(各个配置类会自动进行 Pydantic 验证)
|
# 创建Config对象(各个配置类会自动进行 Pydantic 验证)
|
||||||
try:
|
try:
|
||||||
logger.debug("正在解析和验证配置文件...")
|
logger.debug("正在解析和验证配置文件...")
|
||||||
config = Config.from_dict(config_data)
|
config = Config.from_dict(config_dict)
|
||||||
logger.debug("配置文件解析和验证完成")
|
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
|
return config
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.critical(f"配置文件解析失败: {e}")
|
logger.critical(f"配置文件解析失败: {e}")
|
||||||
@@ -581,4 +573,4 @@ def initialize_configs_once() -> tuple[Config, APIAdapterConfig]:
|
|||||||
# 同一进程只执行一次初始化,避免重复生成或覆盖配置
|
# 同一进程只执行一次初始化,避免重复生成或覆盖配置
|
||||||
global_config, model_config = initialize_configs_once()
|
global_config, model_config = initialize_configs_once()
|
||||||
|
|
||||||
logger.debug("非常的新鲜,非常的美味!")
|
logger.debug("非常的新鲜,非常的美味!")
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import asyncio
|
|||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
import uuid
|
import uuid
|
||||||
|
import json_repair
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@@ -186,8 +187,8 @@ class ShortTermMemoryManager:
|
|||||||
"importance": 0.7,
|
"importance": 0.7,
|
||||||
"attributes": {{
|
"attributes": {{
|
||||||
"time": "时间信息",
|
"time": "时间信息",
|
||||||
"attribute1": "其他属性1"
|
"attribute1": "其他属性1",
|
||||||
"attribute2": "其他属性2"
|
"attribute2": "其他属性2",
|
||||||
...
|
...
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
@@ -530,7 +531,7 @@ class ShortTermMemoryManager:
|
|||||||
json_str = re.sub(r"//.*", "", json_str)
|
json_str = re.sub(r"//.*", "", json_str)
|
||||||
json_str = re.sub(r"/\*.*?\*/", "", json_str, flags=re.DOTALL)
|
json_str = re.sub(r"/\*.*?\*/", "", json_str, flags=re.DOTALL)
|
||||||
|
|
||||||
data = json.loads(json_str)
|
data = json_repair.loads(json_str)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user