Skip to content

Improved litellm exception handler #1604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions interpreter/core/llm/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 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...")
time.sleep(15)
continue
if attempt == 1:
# Try turning up the temperature?
params["temperature"] = params.get("temperature", 0.0) + 0.1
Expand Down