Skip to content

Commit e6060a2

Browse files
committed
Fix operator precedence in exception handler conditions
Added parentheses to fix two conditions that incorrectly triggered due to operator precedence: - API key handler triggered on any "api key" error, ignoring offline status - Rate limit handler triggered on any "insufficient_quota" error, not just RateLimitError exceptions
1 parent 5a7af13 commit e6060a2

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

interpreter/core/respond.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,15 @@ def respond(interpreter):
107107
error_message = str(e).lower()
108108
if (
109109
interpreter.offline == False
110-
and "auth" in error_message
111-
or "api key" in error_message
110+
and ("auth" in error_message or "api key" in error_message)
112111
):
113112
output = traceback.format_exc()
114113
raise Exception(
115114
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"
116115
)
117116
elif (
118117
type(e) == litellm.exceptions.RateLimitError
119-
and "exceeded" in str(e).lower()
120-
or "insufficient_quota" in str(e).lower()
118+
and ("exceeded" in str(e).lower() or "insufficient_quota" in str(e).lower())
121119
):
122120
display_markdown_message(
123121
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.

0 commit comments

Comments
 (0)