34 lines
808 B
Python
34 lines
808 B
Python
import logging
|
|
from fastapi import FastAPI
|
|
from contextlib import asynccontextmanager
|
|
from app.config import settings
|
|
from app.core.rag import initialize_rag_manager
|
|
from app.core.prompts import patch_prompts
|
|
from app.api.routes import router
|
|
|
|
# 配置日志
|
|
logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.INFO)
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
"""应用生命周期管理"""
|
|
# 1. Patch Prompts
|
|
patch_prompts()
|
|
|
|
# 2. Init RAG Manager
|
|
initialize_rag_manager()
|
|
|
|
yield
|
|
|
|
app = FastAPI(
|
|
title=settings.APP_TITLE,
|
|
version=settings.APP_VERSION,
|
|
lifespan=lifespan
|
|
)
|
|
|
|
app.include_router(router)
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run("app.main:app", host=settings.HOST, port=settings.PORT, reload=True)
|