From 046089d38cb4cceab5e572f5f9510607897033f4 Mon Sep 17 00:00:00 2001 From: jnichols0 Date: Thu, 15 Jun 2023 01:10:42 -0400 Subject: [PATCH] revert to gpt-3.5-turbo when gpt-4 is not available --- ai.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ai.py b/ai.py index dc332cf..7ed0a3f 100644 --- a/ai.py +++ b/ai.py @@ -6,6 +6,14 @@ class AI: def __init__(self, **kwargs): self.kwargs = kwargs + try: + openai.Model.retrieve("gpt-4") + except openai.error.InvalidRequestError: + print("Model gpt-4 not available for provided api key reverting " + "to gpt-3.5.turbo. Sign up for the gpt-4 wait list here: " + "https://openai.com/waitlist/gpt-4-api") + self.kwargs['model'] = "gpt-3.5-turbo" + def start(self, system, user): messages = [ {"role": "system", "content": system}, @@ -36,4 +44,4 @@ class AI: msg = delta.get('content', '') print(msg, end="") chat.append(msg) - return messages + [{"role": "assistant", "content": "".join(chat)}] \ No newline at end of file + return messages + [{"role": "assistant", "content": "".join(chat)}]