38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
"""应用入口:四库异步生命周期 + 中间件 + 全局异常 + 路由装配。"""
|
|
from contextlib import asynccontextmanager
|
|
|
|
import uvicorn
|
|
from fastapi import FastAPI
|
|
|
|
from api.router import api_router
|
|
from config import database
|
|
from rag.milvus_collections import ensure_collections
|
|
from service.customer_agent.bootstrap import (
|
|
build_default_knowledge_upload_service,
|
|
build_default_runtime,
|
|
)
|
|
from utils.exceptions import register_exception_handlers
|
|
from utils.logger import setup_logging
|
|
from utils.request_id import RequestIdMiddleware
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
setup_logging()
|
|
await ensure_collections()
|
|
app.state.customer_agent_runtime = build_default_runtime()
|
|
app.state.knowledge_upload_service = build_default_knowledge_upload_service()
|
|
yield
|
|
await database.dispose()
|
|
|
|
|
|
app = FastAPI(title="智能公募基金系统", version="0.1.0", lifespan=lifespan)
|
|
|
|
app.add_middleware(RequestIdMiddleware)
|
|
register_exception_handlers(app)
|
|
app.include_router(api_router)
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {"message": "智能公募基金系统 API", "docs": "/docs"} |