from fastapi import Depends, FastAPI, HTTPException from app.config import get_settings from app.models import LeaveDraftSuggestionRequest, LeaveDraftSuggestionResponse, LeaveProgressAnswerRequest, LeaveProgressAnswerResponse from app.qwen import ( QwenConfigurationError, QwenSuggestionGateway, QwenUpstreamError, SuggestionGateway, ProgressGateway, ) app = FastAPI(title="AIOA AI Service", version="0.1.0") def get_gateway() -> SuggestionGateway: return QwenSuggestionGateway(get_settings()) def get_progress_gateway() -> ProgressGateway: return QwenSuggestionGateway(get_settings()) @app.get("/health") async def health() -> dict[str, str]: return {"status": "UP"} @app.post("/v1/leave-drafts/suggest", response_model=LeaveDraftSuggestionResponse) async def suggest_leave_draft( request: LeaveDraftSuggestionRequest, gateway: SuggestionGateway = Depends(get_gateway), ) -> LeaveDraftSuggestionResponse: try: suggestion = await gateway.suggest(request) except QwenConfigurationError as exc: raise HTTPException(status_code=503, detail=str(exc)) from exc except QwenUpstreamError as exc: raise HTTPException(status_code=502, detail=str(exc)) from exc return LeaveDraftSuggestionResponse( suggestion=suggestion, model=get_settings().qwen_model, ) @app.post("/v1/leave-progress/answer", response_model=LeaveProgressAnswerResponse) async def answer_leave_progress( request: LeaveProgressAnswerRequest, gateway: ProgressGateway = Depends(get_progress_gateway), ) -> LeaveProgressAnswerResponse: try: answer = await gateway.answer_progress(request) except QwenConfigurationError as exc: raise HTTPException(status_code=503, detail=str(exc)) from exc except QwenUpstreamError as exc: raise HTTPException(status_code=502, detail=str(exc)) from exc return LeaveProgressAnswerResponse(answer=answer, model=get_settings().qwen_model)