Files
label_ai_service/app/main.py

52 lines
1.4 KiB
Python
Raw Normal View History

from contextlib import asynccontextmanager
from fastapi import FastAPI
from app.core.exceptions import (
AIServiceError,
ai_service_exception_handler,
unhandled_exception_handler,
)
from app.core.logging import RequestLoggingMiddleware, get_logger
logger = get_logger(__name__)
@asynccontextmanager
async def lifespan(app: FastAPI):
logger.info("startup", extra={"message": "AI service starting"})
yield
logger.info("shutdown", extra={"message": "AI service stopping"})
app = FastAPI(
title="Label AI Service",
description="知识图谱标注平台 AI 计算服务",
version="1.0.0",
lifespan=lifespan,
)
app.add_middleware(RequestLoggingMiddleware)
app.add_exception_handler(AIServiceError, ai_service_exception_handler)
app.add_exception_handler(Exception, unhandled_exception_handler)
@app.get("/health", tags=["Health"])
async def health():
return {"status": "ok"}
# Routers registered after implementation (imported lazily to avoid circular deps)
from app.routers import text, image, video, qa, finetune # noqa: E402
app.include_router(text.router, prefix="/api/v1")
app.include_router(image.router, prefix="/api/v1")
app.include_router(video.router, prefix="/api/v1")
app.include_router(qa.router, prefix="/api/v1")
app.include_router(finetune.router, prefix="/api/v1")
2026-04-15 11:09:09 +08:00
if __name__ == "__main__":
import uvicorn
2026-04-16 10:17:54 +08:00
2026-04-15 11:09:09 +08:00
uvicorn.run(app, host="0.0.0.0", port=8000)