Skip to content

Commit c2692ef

Browse files
authored
Merge pull request #1349 from cyai/re/ratelimit_error
re: add markdown message for insufficient_quota error in openai
2 parents 8e5434c + c0909ad commit c2692ef

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

interpreter/core/respond.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
88
import litellm
9+
import openai
910

1011
from .render_message import render_message
1112

@@ -112,6 +113,20 @@ def respond(interpreter):
112113
raise Exception(
113114
f"{output}\n\nThere might be an issue with your API key(s).\n\nTo reset your API key (we'll use OPENAI_API_KEY for this example, but you may need to reset your ANTHROPIC_API_KEY, HUGGINGFACE_API_KEY, etc):\n Mac/Linux: 'export OPENAI_API_KEY=your-key-here'. Update your ~/.zshrc on MacOS or ~/.bashrc on Linux with the new key if it has already been persisted there.,\n Windows: 'setx OPENAI_API_KEY your-key-here' then restart terminal.\n\n"
114115
)
116+
elif (
117+
type(e) == litellm.exceptions.RateLimitError
118+
and "exceeded" in str(e).lower()
119+
or "insufficient_quota" in str(e).lower()
120+
):
121+
display_markdown_message(
122+
f""" > You ran out of current quota for OpenAI's API, please check your plan and billing details. You can either wait for the quota to reset or upgrade your plan.
123+
124+
To check your current usage and billing details, visit the [OpenAI billing page](https://platform.openai.com/settings/organization/billing/overview).
125+
126+
You can also use `interpreter --max_budget [higher USD amount]` to set a budget for your sessions.
127+
"""
128+
)
129+
115130
elif (
116131
interpreter.offline == False and "not have access" in str(e).lower()
117132
):

0 commit comments

Comments
 (0)