52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
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")
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
|
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|