init
This commit is contained in:
33
main.py
Normal file
33
main.py
Normal file
@@ -0,0 +1,33 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user