Improve the error logging for OAI Issues

pull/1987/head
Eesa Hamza 2023-04-16 22:10:48 +03:00
parent a91ef56954
commit 9b6bce4592
1 changed files with 19 additions and 2 deletions

View File

@ -5,9 +5,10 @@ import time
import openai
from openai.error import APIError, RateLimitError
from colorama import Fore
from colorama import Fore, Style
from autogpt.config import Config
from autogpt.logs import logger
CFG = Config()
@ -70,6 +71,7 @@ def create_chat_completion(
"""
response = None
num_retries = 10
warned_user = False
if CFG.debug_mode:
print(
Fore.GREEN
@ -101,6 +103,11 @@ def create_chat_completion(
Fore.RED + "Error: ",
f"Reached rate limit, passing..." + Fore.RESET,
)
if not warned_user:
logger.double_check(
f"Please double check that you have setup a {Fore.CYAN + Style.BRIGHT}PAID{Style.RESET_ALL} OpenAI API Account. " +
f"You can read more here: {Fore.CYAN}https://github.com/Significant-Gravitas/Auto-GPT#openai-api-keys-configuration{Fore.RESET}")
warned_user = True
except APIError as e:
if e.http_status == 502:
pass
@ -115,7 +122,17 @@ def create_chat_completion(
)
time.sleep(backoff)
if response is None:
raise RuntimeError(f"Failed to get response after {num_retries} retries")
logger.typewriter_log(
"FAILED TO GET RESPONSE FROM OPENAI",
Fore.RED,
"Auto-GPT has failed to get a response from OpenAI's services. " +
f"Try running Auto-GPT again, and if the problem the persists try running it with `{Fore.CYAN}--debug{Fore.RESET}`."
)
logger.double_check()
if CFG.debug_mode:
raise RuntimeError(f"Failed to get response after {num_retries} retries")
else:
quit(1)
return response.choices[0].message["content"]