| | |
| | | from contextlib import asynccontextmanager |
| | | from fastapi import FastAPI |
| | | from app.api.auth import router as auth_router |
| | | from app.api.chat import router as chat_router |
| | | from app.api.agent import router as agent_router |
| | | from app.api.excel import router as excel_router |
| | | from app.api.files import router as files_router |
| | | from app.api.organization import dept_router |
| | | from app.api.report import router as report_router |
| | | from app.api.resource import menu_router |
| | | from app.api.user import user_router |
| | | from app.api.group import group_router |
| | | from app.api.role import role_router |
| | | from app.models.base_model import init_db |
| | | from app.task.fetch_agent import sync_agents, initialize_agents |
| | | |
| | | |
| | | # 使用 Lifespan 事件处理程序 |
| | | @asynccontextmanager |
| | | async def lifespan(app: FastAPI): |
| | | # 初始化代理 |
| | | initialize_agents() |
| | | # 在应用启动时同步代理 |
| | | sync_agents() |
| | | yield |
| | | # 在应用关闭时执行清理操作(如果需要) |
| | | pass |
| | | |
| | | init_db() |
| | | app = FastAPI( |
| | | title="basic_rag_gateway", |
| | | version="0.1", |
| | | description="", |
| | | title="basic_rag_gateway", |
| | | version="0.1", |
| | | description="", |
| | | lifespan=lifespan |
| | | ) |
| | | |
| | | app.include_router(auth_router, prefix='/auth', tags=["auth"]) |
| | | app.include_router(chat_router, prefix='/chat', tags=["chat"]) |
| | | app.include_router(agent_router, prefix='/agent', tags=["agent"]) |
| | | app.include_router(excel_router, prefix='/document', tags=["document"]) |
| | | |
| | | app.include_router(auth_router, prefix='/api/auth', tags=["auth"]) |
| | | app.include_router(chat_router, prefix='/api/chat', tags=["chat"]) |
| | | app.include_router(agent_router, prefix='/api/agent', tags=["agent"]) |
| | | app.include_router(excel_router, prefix='/api/document', tags=["document"]) |
| | | app.include_router(files_router, prefix='/api/files', tags=["files"]) |
| | | app.include_router(report_router, prefix='/api/report', tags=["report"]) |
| | | app.include_router(user_router, prefix='/api/user', tags=["user"]) |
| | | app.include_router(group_router, prefix='/api/group', tags=["group"]) |
| | | app.include_router(role_router, prefix='/api/role', tags=["role"]) |
| | | app.include_router(dept_router, prefix='/api/dept', tags=["dept"]) |
| | | app.include_router(menu_router, prefix='/api/menu', tags=["menu"]) |
| | | |
| | | if __name__ == "__main__": |
| | | import uvicorn |