Skip to content

Commit 3b2ca3d

Browse files
authored
Fix error message on invalid model name and groq access to open inter…
Fix error message on invalid model name and groq access to open inter…
2 parents ea2eaa7 + 9123baa commit 3b2ca3d

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

interpreter/core/respond.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ def respond(interpreter):
101101
# Provide extra information on how to change API keys, if we encounter that error
102102
# (Many people writing GitHub issues were struggling with this)
103103
except Exception as e:
104+
error_message = str(e).lower()
104105
if (
105106
interpreter.offline == False
106-
and "auth" in str(e).lower()
107-
or "api key" in str(e).lower()
107+
and "auth" in error_message
108+
or "api key" in error_message
108109
):
109110
output = traceback.format_exc()
110111
raise Exception(
@@ -113,9 +114,20 @@ def respond(interpreter):
113114
elif (
114115
interpreter.offline == False and "not have access" in str(e).lower()
115116
):
116-
response = input(
117-
f" You do not have access to {interpreter.llm.model}. You will need to add a payment method and purchase credits for the OpenAI API billing page (different from ChatGPT) to use `GPT-4`.\n\nhttps://platform.openai.com/account/billing/overview\n\nWould you like to try GPT-3.5-TURBO instead? (y/n)\n\n "
118-
)
117+
"""
118+
Check for invalid model in error message and then fallback to groq, then OpenAI.
119+
"""
120+
if (
121+
"invalid model" in error_message
122+
or "model does not exist" in error_message
123+
):
124+
provider_message = f" The model '{interpreter.llm.model}' does not exist or is invalid. Please check the model name and try again.\n\nWould you like to try an alternative model instead? (y/n)\n\n "
125+
elif "groq" in error_message:
126+
provider_message = f" You do not have access to {interpreter.llm.model}. Please check with Groq for more details.\n\nWould you like to try an alternative model instead? (y/n)\n\n "
127+
else:
128+
provider_message = f" You do not have access to {interpreter.llm.model}. You will need to add a payment method and purchase credits for the OpenAI API billing page (different from ChatGPT) to use `GPT-4`.\n\nhttps://platform.openai.com/account/billing/overview\n\nWould you like to try GPT-3.5-TURBO instead? (y/n)\n\n "
129+
130+
response = input(provider_message)
119131
print("") # <- Aesthetic choice
120132

121133
if response.strip().lower() == "y":

0 commit comments

Comments
 (0)