From ef24213314cd84119c605f47e696733b131b89a6 Mon Sep 17 00:00:00 2001 From: TheFirstRandom <160148761+TheFirstRandom@users.noreply.github.com> Date: Mon, 17 Mar 2025 21:12:36 +0100 Subject: [PATCH 1/2] Improved litellm exception handler --- interpreter/core/llm/llm.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/interpreter/core/llm/llm.py b/interpreter/core/llm/llm.py index 980672db58..7258f4a5f2 100644 --- a/interpreter/core/llm/llm.py +++ b/interpreter/core/llm/llm.py @@ -458,6 +458,16 @@ def fixed_litellm_completions(**params): ) # So, let's try one more time with a dummy API key: params["api_key"] = "x" + if isinstance(e, litellm.exceptions.RateLimitError): + # On the second attempt, raise the error + if attempt == 1: + # RateLimitError can be caused if you have no credit left + print("You still exceeded the rate limit. Try again later and check if you have credit left.") + raise first_error + # Wait and try again + print("You exceeded the rate limit. Trying again in 15 seconds...") + time.sleep(15) + continue if attempt == 1: # Try turning up the temperature? params["temperature"] = params.get("temperature", 0.0) + 0.1 From e2c986079ada49fdcf99574ddbafe6e91a3e5617 Mon Sep 17 00:00:00 2001 From: TheFirstRandom <160148761+TheFirstRandom@users.noreply.github.com> Date: Mon, 17 Mar 2025 21:30:46 +0100 Subject: [PATCH 2/2] Improved litellm exception handler --- interpreter/core/llm/llm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interpreter/core/llm/llm.py b/interpreter/core/llm/llm.py index 7258f4a5f2..80e2f0d9ef 100644 --- a/interpreter/core/llm/llm.py +++ b/interpreter/core/llm/llm.py @@ -461,8 +461,8 @@ def fixed_litellm_completions(**params): if isinstance(e, litellm.exceptions.RateLimitError): # On the second attempt, raise the error if attempt == 1: - # RateLimitError can be caused if you have no credit left - print("You still exceeded the rate limit. Try again later and check if you have credit left.") + # RateLimitError can be caused if you have no tokens left + print("You still exceeded the rate limit. Try again later. If you use an API, ensure you have tokens left.") raise first_error # Wait and try again print("You exceeded the rate limit. Trying again in 15 seconds...")