Files
YG_FT/backend/app/main.py

38 lines
1.1 KiB
Python
Raw Normal View History

2026-07-31 16:10:34 +08:00
from contextlib import asynccontextmanager
2026-07-27 09:12:47 +08:00
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api.v1.router import api_router
from app.core.config import get_settings
from app.core.logging import configure_logging, setup_request_logging
2026-07-31 16:10:34 +08:00
@asynccontextmanager
async def _lifespan(app: FastAPI):
# 启动算力状态轮询线程(同步派发到算力的训练任务状态/日志/指标)
from app.modules.fine_tune.service import start_compute_sync_worker, stop_compute_sync_worker
start_compute_sync_worker()
yield
stop_compute_sync_worker()
2026-07-27 09:12:47 +08:00
def create_app() -> FastAPI:
settings = get_settings()
configure_logging(settings)
2026-07-31 16:10:34 +08:00
app = FastAPI(title=settings.app_name, lifespan=_lifespan)
2026-07-27 09:12:47 +08:00
app.add_middleware(
CORSMiddleware,
allow_origins=settings.cors_allow_origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
setup_request_logging(app)
app.include_router(api_router, prefix=settings.route_prefix)
return app
app = create_app()