From 040dc1f23e7a29147a18221e66f18eaf0c58b49c Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 6 May 2024 16:43:42 -0700 Subject: [PATCH 1/7] fix retry policy --- litellm/router.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/litellm/router.py b/litellm/router.py index 303fab128..9fff3015c 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -3268,6 +3268,8 @@ class Router: if retry_policy is None: return None + if isinstance(retry_policy, dict): + retry_policy = RetryPolicy(**retry_policy) if ( isinstance(exception, litellm.BadRequestError) and retry_policy.BadRequestErrorRetries is not None From 57a78703481f3bd80274ee5befbcf2e0bb54b114 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 6 May 2024 17:23:51 -0700 Subject: [PATCH 2/7] ui - show retry policy per model group --- .../src/components/model_dashboard.tsx | 52 ++++++++++++------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/ui/litellm-dashboard/src/components/model_dashboard.tsx b/ui/litellm-dashboard/src/components/model_dashboard.tsx index 43ca9fdff..1297db295 100644 --- a/ui/litellm-dashboard/src/components/model_dashboard.tsx +++ b/ui/litellm-dashboard/src/components/model_dashboard.tsx @@ -1275,24 +1275,40 @@ const handleEditSubmit = async (formValues: Record) => { How many retries should be attempted based on the Exception {retry_policy_map && - - {Object.keys(retry_policy_map).map((key, idx) => ( - - - - - ))} - -
- {key} - - -
+ + {Object.entries(retry_policy_map).map(([exceptionType, retryPolicyKey], idx) => { + let retryCount = (modelGroupRetryPolicy[selectedModelGroup] ?? {})[retryPolicyKey]; + if (retryCount == null) { + retryCount = defaultRetry; + } + + return ( + + + {exceptionType} + + + { + setModelGroupRetryPolicy({ + ...modelGroupRetryPolicy, + [selectedModelGroup]: { + ...modelGroupRetryPolicy[selectedModelGroup], + [retryPolicyKey]: value, + }, + }); + }} + /> + + + ); + })} + + } From eb5dc38fc9200b360be0cefbc17a1bfefa136ac2 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 6 May 2024 17:57:07 -0700 Subject: [PATCH 5/7] fix - set retry policy on ui --- .../src/components/model_dashboard.tsx | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/ui/litellm-dashboard/src/components/model_dashboard.tsx b/ui/litellm-dashboard/src/components/model_dashboard.tsx index a62365474..2b7cf923d 100644 --- a/ui/litellm-dashboard/src/components/model_dashboard.tsx +++ b/ui/litellm-dashboard/src/components/model_dashboard.tsx @@ -60,6 +60,10 @@ interface EditModelModalProps { onSubmit: (data: FormData) => void; // Assuming FormData is the type of data to be submitted } +interface RetryPolicyObject { + [key: string]: { [retryPolicyKey: string]: number } | undefined; +} + //["OpenAI", "Azure OpenAI", "Anthropic", "Gemini (Google AI Studio)", "Amazon Bedrock", "OpenAI-Compatible Endpoints (Groq, Together AI, Mistral AI, etc.)"] enum Providers { @@ -222,7 +226,7 @@ const ModelDashboard: React.FC = ({ to: new Date(), }); - const [modelGroupRetryPolicy, setModelGroupRetryPolicy] = useState>({}); + const [modelGroupRetryPolicy, setModelGroupRetryPolicy] = useState(null); const [defaultRetry, setDefaultRetry] = useState(0); @@ -1301,7 +1305,7 @@ const handleEditSubmit = async (formValues: Record) => { {Object.entries(retry_policy_map).map(([exceptionType, retryPolicyKey], idx) => { - let retryCount = modelGroupRetryPolicy?.[selectedModelGroup]?.[retryPolicyKey] + let retryCount = modelGroupRetryPolicy?.[selectedModelGroup!]?.[retryPolicyKey] if (retryCount == null) { retryCount = defaultRetry; } @@ -1318,12 +1322,15 @@ const handleEditSubmit = async (formValues: Record) => { min={0} step={1} onChange={(value) => { - setModelGroupRetryPolicy({ - ...modelGroupRetryPolicy, - [selectedModelGroup]: { - ...modelGroupRetryPolicy[selectedModelGroup], - [retryPolicyKey]: value, - }, + setModelGroupRetryPolicy(prevModelGroupRetryPolicy => { + const prevRetryPolicy = prevModelGroupRetryPolicy?.[selectedModelGroup!] ?? {}; + return { + ...prevModelGroupRetryPolicy ?? {}, + [selectedModelGroup!]: { + ...prevRetryPolicy, + [retryPolicyKey!]: value, + }, + } as RetryPolicyObject; }); }} /> From f04f45a80d751dc0bda274c9b00e3bf1a44e379c Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 6 May 2024 17:58:56 -0700 Subject: [PATCH 6/7] ui - fix show num retries for 500 error --- ui/litellm-dashboard/src/components/model_dashboard.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ui/litellm-dashboard/src/components/model_dashboard.tsx b/ui/litellm-dashboard/src/components/model_dashboard.tsx index 2b7cf923d..6e207b430 100644 --- a/ui/litellm-dashboard/src/components/model_dashboard.tsx +++ b/ui/litellm-dashboard/src/components/model_dashboard.tsx @@ -93,7 +93,8 @@ const retry_policy_map: Record = { "AuthenticationError (401)": "AuthenticationErrorRetries", "TimeoutError (408)": "TimeoutErrorRetries", "RateLimitError (429)": "RateLimitErrorRetries", - "ContentPolicyViolationError (400)": "ContentPolicyViolationErrorRetries" + "ContentPolicyViolationError (400)": "ContentPolicyViolationErrorRetries", + "InternalServerError (500)": "InternalServerErrorRetries" }; From 6a056c0c1724b881b897091099bebda548d87024 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 6 May 2024 17:59:38 -0700 Subject: [PATCH 7/7] fix support InternalServerErrorRetries --- litellm/types/router.py | 1 + 1 file changed, 1 insertion(+) diff --git a/litellm/types/router.py b/litellm/types/router.py index 4b54d8f41..4a62a267e 100644 --- a/litellm/types/router.py +++ b/litellm/types/router.py @@ -345,3 +345,4 @@ class RetryPolicy(BaseModel): TimeoutErrorRetries: Optional[int] = None RateLimitErrorRetries: Optional[int] = None ContentPolicyViolationErrorRetries: Optional[int] = None + InternalServerErrorRetries: Optional[int] = None