- 新增知识库、知识文件、评估基准、评估结果等数据模型 - 实现知识库相关Repository类提供CRUD操作 - 修改知识库实现类使用PostgreSQL存储元数据 - 添加PostgreSQL数据库管理器和初始化逻辑 - 更新相关路由和工具类适配新的存储方式 - 添加数据库迁移脚本和测试工具 - 在docker-compose中配置PostgreSQL服务
37 lines
1021 B
Python
37 lines
1021 B
Python
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
|
|
from server.services import tasker
|
|
from src.services.mcp_service import init_mcp_servers
|
|
from src.storage.postgres.manager import pg_manager
|
|
from src.knowledge import knowledge_base
|
|
from src.utils import logger
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
"""FastAPI lifespan事件管理器"""
|
|
# 初始化 MCP 服务器配置
|
|
try:
|
|
await init_mcp_servers()
|
|
except Exception as e:
|
|
logger.error(f"Failed to initialize MCP servers during startup: {e}")
|
|
|
|
# 初始化数据库连接
|
|
try:
|
|
pg_manager.initialize()
|
|
except Exception as e:
|
|
logger.error(f"Failed to initialize database during startup: {e}")
|
|
|
|
# 初始化知识库管理器
|
|
try:
|
|
await knowledge_base.initialize()
|
|
except Exception as e:
|
|
logger.error(f"Failed to initialize knowledge base manager: {e}")
|
|
|
|
await tasker.start()
|
|
yield
|
|
await tasker.shutdown()
|
|
await pg_manager.close()
|