Skip to content

Commit d8dd026

Browse files
committed
fix(ai): handle groq model NotFoundError explicitly
1 parent 3f33860 commit d8dd026

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

  • apps/python-service/routers

‎apps/python-service/routers/ai.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ async def query_builder(request: QueryBuilderRequest, req: Request):
169169
error_name = e.__class__.__name__
170170
logger.error("[Trace: %s] ❌ AI Query Builder unhandled failure for developer_id=%s: %s", trace_id, request.developer_id, e, exc_info=True)
171171
if "Tool use is not supported" in str(e) or "tools" in str(e).lower():
172-
raise HTTPException(status_code=400, detail="This model doesn't support complex structured outputs. Please switch to llama-3.3-70b-versatile.") from e
172+
raise HTTPException(status_code=400, detail="This model doesn't support complex structured outputs. Please select a different model.") from e
173+
if "NotFoundError" in error_name or "does not exist" in str(e):
174+
raise HTTPException(status_code=400, detail="The selected AI model is currently unavailable or doesn't exist. Please select a different model.") from e
173175
if "BadRequest" in error_name or "Validation" in error_name:
174176
raise HTTPException(status_code=400, detail="The AI generated an invalid query format. Please rephrase or simplify your prompt.") from e
175177
raise HTTPException(status_code=500, detail="Internal server error") from e
@@ -245,7 +247,9 @@ async def collection_creator(request: CollectionCreatorRequest, req: Request):
245247
error_name = e.__class__.__name__
246248
logger.error("[Trace: %s] ❌ AI Collection Creator unhandled failure for developer_id=%s: %s", trace_id, request.developer_id, e, exc_info=True)
247249
if "Tool use is not supported" in str(e) or "tools" in str(e).lower():
248-
raise HTTPException(status_code=400, detail="This model doesn't support complex structured outputs. Please switch to llama-3.3-70b-versatile.") from e
250+
raise HTTPException(status_code=400, detail="This model doesn't support complex structured outputs. Please select a different model.") from e
251+
if "NotFoundError" in error_name or "does not exist" in str(e):
252+
raise HTTPException(status_code=400, detail="The selected AI model is currently unavailable or doesn't exist. Please select a different model from the dropdown.") from e
249253
if "BadRequest" in error_name or "Validation" in error_name:
250254
raise HTTPException(status_code=400, detail="The AI generated an invalid response format. Please rephrase or simplify your prompt.") from e
251255
raise HTTPException(status_code=500, detail="Internal server error") from e

0 commit comments

Comments
 (0)