Files
2026-07-31 12:27:41 +08:00

76 lines
1.7 KiB
Python

from __future__ import annotations
import logging
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api import health, imaging, llm_config, rag, report, yolo
from app.config import get_settings
from app.services.llm_client import get_llm
from app.services.rag_pipeline import get_rag
from app.services.yolo_detector import get_detector
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s - %(message)s",
)
logger = logging.getLogger("ai-service")
settings = get_settings()
app = FastAPI(
title="Smart Hospital AI Service",
description="YOLO/MONAI 影像识别 + LangChain RAG + 报告/决策生成(实训演示)",
version="1.0.0",
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(health.router)
app.include_router(imaging.router)
app.include_router(rag.router)
app.include_router(report.router)
app.include_router(yolo.router)
app.include_router(llm_config.router)
@app.on_event("startup")
def on_startup() -> None:
rag_pipe = get_rag()
det_info = get_detector().info()
llm_info = get_llm().info()
logger.info(
"AI 服务启动 port=%s knowledge_chunks=%s llm=%s yolo_mode=%s",
settings.ai_port,
rag_pipe.doc_count(),
llm_info.get("enabled"),
det_info.get("runtime_mode"),
)
@app.get("/")
def root() -> dict:
return {
"service": "smart-hospital-ai",
"docs": "/docs",
"health": "/health",
}
if __name__ == "__main__":
import uvicorn
uvicorn.run(
"app.main:app",
host=settings.ai_host,
port=settings.ai_port,
reload=False,
)