""" FastAPI 服务器 """ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware import uvicorn from finetunex.api.routes import router app = FastAPI( title="FineTuneX API", description="大模型微调服务 API", version="0.1.0", ) # CORS 配置 app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # 注册路由 app.include_router(router, prefix="/api/v1") @app.get("/") async def root(): """根路径""" return { "message": "欢迎使用 FineTuneX API", "version": "0.1.0", "docs": "/docs", } @app.get("/health") async def health_check(): """健康检查""" return {"status": "healthy"} def run_server(host: str = "0.0.0.0", port: int = 8000, reload: bool = True): """ 运行服务器 Args: host: 主机地址 port: 端口号 reload: 是否自动重载 """ uvicorn.run( "finetunex.api.server:app", host=host, port=port, reload=reload, )