mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-21 07:54:21 +01:00
Merge pull request #1987 from cryptidv/fix-oai-error-msgs
Improve the error logging for OAI Issues
This commit is contained in:
@@ -5,9 +5,10 @@ import time
|
|||||||
|
|
||||||
import openai
|
import openai
|
||||||
from openai.error import APIError, RateLimitError
|
from openai.error import APIError, RateLimitError
|
||||||
from colorama import Fore
|
from colorama import Fore, Style
|
||||||
|
|
||||||
from autogpt.config import Config
|
from autogpt.config import Config
|
||||||
|
from autogpt.logs import logger
|
||||||
|
|
||||||
CFG = Config()
|
CFG = Config()
|
||||||
|
|
||||||
@@ -70,6 +71,7 @@ def create_chat_completion(
|
|||||||
"""
|
"""
|
||||||
response = None
|
response = None
|
||||||
num_retries = 10
|
num_retries = 10
|
||||||
|
warned_user = False
|
||||||
if CFG.debug_mode:
|
if CFG.debug_mode:
|
||||||
print(
|
print(
|
||||||
Fore.GREEN
|
Fore.GREEN
|
||||||
@@ -101,6 +103,11 @@ def create_chat_completion(
|
|||||||
Fore.RED + "Error: ",
|
Fore.RED + "Error: ",
|
||||||
f"Reached rate limit, passing..." + Fore.RESET,
|
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:
|
except APIError as e:
|
||||||
if e.http_status == 502:
|
if e.http_status == 502:
|
||||||
pass
|
pass
|
||||||
@@ -115,7 +122,17 @@ def create_chat_completion(
|
|||||||
)
|
)
|
||||||
time.sleep(backoff)
|
time.sleep(backoff)
|
||||||
if response is None:
|
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"]
|
return response.choices[0].message["content"]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user