Skip to content

Commit

Permalink
feat: Raise 500 fallback HTTPExceptions with their original exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
reindervdw-cmi committed Jan 13, 2025
1 parent 3046430 commit 1a5df56
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/cloaiservice/routes/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
router = APIRouter()


async def get_llm_client(id: str) -> cloai.LargeLanguageModel:
def get_llm_client(id: str) -> cloai.LargeLanguageModel:
"""Get an LLM client by its ID."""
client = get_config().clients.get(id)
if client is None:
Expand All @@ -39,8 +39,8 @@ async def run_prompt(
system_prompt=request.system_prompt, user_prompt=request.user_prompt
)
return LLMResponse(result=result)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
except Exception as exc_info:
raise HTTPException(status_code=500, detail=str(exc_info)) from exc_info


@router.post("/instructor", response_model=LLMResponse)
Expand All @@ -59,8 +59,8 @@ async def run_instructor(
max_tokens=request.max_tokens,
)
return LLMResponse(result=result)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
except Exception as exc_info:
raise HTTPException(status_code=500, detail=str(exc_info)) from exc_info


@router.post("/cov", response_model=LLMResponse)
Expand All @@ -70,7 +70,7 @@ async def chain_of_verification(
) -> LLMResponse:
"""Run chain of verification on a prompt."""
try:
result = await llm.chain_of_verification( # type: ignore # pycharm is confused
result = await llm.chain_of_verification( # type: ignore[call-arg] # pycharm is confused
system_prompt=request.system_prompt,
user_prompt=request.user_prompt,
response_model=str,
Expand All @@ -80,5 +80,5 @@ async def chain_of_verification(
error_on_iteration_limit=request.error_on_iteration_limit,
)
return LLMResponse(result=result)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
except Exception as exc_info:
raise HTTPException(status_code=500, detail=str(exc_info)) from exc_info

0 comments on commit 1a5df56

Please sign in to comment.