""" FastAPI 主应用 """ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from app.config import settings from app.api import router # 创建 FastAPI 应用实例 app = FastAPI( title=settings.app_name, version=settings.app_version, description="一个基于 FastAPI 的 AI 调用示例工程,支持对话和工具调用" ) # 配置 CORS 中间件 app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # 注册路由 app.include_router(router, prefix="/api/v1", tags=["AI Chat"]) @app.get("/") async def root(): """根路径""" return { "message": f"欢迎使用 {settings.app_name}", "version": settings.app_version, "docs": "/docs", "redoc": "/redoc" } @app.get("/health") async def health(): """健康检查接口""" return {"status": "healthy"} if __name__ == "__main__": import uvicorn uvicorn.run( "main:app", host=settings.host, port=settings.port, reload=settings.debug )