From 695d59b615af39f1ca1e6da1012f33d388ab2ddb Mon Sep 17 00:00:00 2001 From: Wh1isper Date: Thu, 9 Jan 2025 17:36:41 +0800 Subject: [PATCH] feat: Response 429 if ThrottlingException --- src/api/models/bedrock.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/api/models/bedrock.py b/src/api/models/bedrock.py index 4b58951..c05400c 100644 --- a/src/api/models/bedrock.py +++ b/src/api/models/bedrock.py @@ -178,6 +178,9 @@ def _invoke_bedrock(self, chat_request: ChatRequest, stream=False): except bedrock_runtime.exceptions.ValidationException as e: logger.error("Validation Error: " + str(e)) raise HTTPException(status_code=400, detail=str(e)) + except bedrock_runtime.exceptions.ThrottlingException as e: + logger.error("Throttling Error: " + str(e)) + raise HTTPException(status_code=429, detail=str(e)) except Exception as e: logger.error(e) raise HTTPException(status_code=500, detail=str(e)) @@ -724,6 +727,9 @@ def _invoke_model(self, args: dict, model_id: str): except bedrock_runtime.exceptions.ValidationException as e: logger.error("Validation Error: " + str(e)) raise HTTPException(status_code=400, detail=str(e)) + except bedrock_runtime.exceptions.ThrottlingException as e: + logger.error("Throttling Error: " + str(e)) + raise HTTPException(status_code=429, detail=str(e)) except Exception as e: logger.error(e) raise HTTPException(status_code=500, detail=str(e))