Files
geo-setp/main.py
2026-04-13 16:29:27 +08:00

34 lines
1.1 KiB
Python

import httpx
from fastapi import FastAPI, HTTPException
from openai import APITimeoutError
from schemas import RoutePlanRequest, RoutePlanResult
from agent import ConfigurationError, GuardrailError, run_route_plan
app = FastAPI(title="Geo Route Agent", version="0.1.0")
@app.post("/route/plan", response_model=RoutePlanResult)
async def route_plan(request: RoutePlanRequest) -> RoutePlanResult:
try:
return await run_route_plan(request)
except ConfigurationError as exc:
raise HTTPException(status_code=503, detail=str(exc)) from exc
except GuardrailError as exc:
raise HTTPException(status_code=422, detail=str(exc)) from exc
except (httpx.TimeoutException, APITimeoutError, TimeoutError) as exc:
raise HTTPException(status_code=504, detail=f"Upstream request timed out: {exc}") from exc
except Exception as exc:
raise HTTPException(status_code=500, detail=str(exc)) from exc
@app.get("/healthz")
async def healthz() -> dict[str, str]:
return {"status": "ok"}
if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)