CoolFace
Apppublic

chwellofficial/nt360Slides

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
llm_client_error_handler.py20 linesDownload Raw Back to utils
1from fastapi import HTTPException2from openai import APIError as OpenAIAPIError3from google.genai.errors import APIError as GoogleAPIError4import traceback5 6from llmai.shared.errors import BaseError as LLMAIBaseError7 8 9def handle_llm_client_exceptions(e: Exception) -> HTTPException:10    traceback.print_exc()11    if isinstance(e, HTTPException):12        return e13    if isinstance(e, LLMAIBaseError):14        return HTTPException(status_code=e.status_code, detail=e.message)15    if isinstance(e, OpenAIAPIError):16        return HTTPException(status_code=500, detail=f"OpenAI API error: {e.message}")17    if isinstance(e, GoogleAPIError):18        return HTTPException(status_code=500, detail=f"Google API error: {e.message}")19    return HTTPException(status_code=500, detail=f"LLM API error: {e}")20