mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-18 06:24:20 +01:00
formatting
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import time
|
||||
|
||||
import openai
|
||||
from colorama import Fore
|
||||
|
||||
from autogpt.config import Config
|
||||
|
||||
cfg = Config()
|
||||
@@ -10,7 +12,9 @@ openai.api_key = cfg.openai_api_key
|
||||
|
||||
# Overly simple abstraction until we create something better
|
||||
# simple retry mechanism when getting a rate error or a bad gateway
|
||||
def create_chat_completion(messages, model=None, temperature=cfg.temperature, max_tokens=None)->str:
|
||||
def create_chat_completion(
|
||||
messages, model=None, temperature=cfg.temperature, max_tokens=None
|
||||
) -> str:
|
||||
"""Create a chat completion using the OpenAI API"""
|
||||
response = None
|
||||
num_retries = 5
|
||||
@@ -22,24 +26,30 @@ def create_chat_completion(messages, model=None, temperature=cfg.temperature, ma
|
||||
model=model,
|
||||
messages=messages,
|
||||
temperature=temperature,
|
||||
max_tokens=max_tokens
|
||||
max_tokens=max_tokens,
|
||||
)
|
||||
else:
|
||||
response = openai.ChatCompletion.create(
|
||||
model=model,
|
||||
messages=messages,
|
||||
temperature=temperature,
|
||||
max_tokens=max_tokens
|
||||
max_tokens=max_tokens,
|
||||
)
|
||||
break
|
||||
except openai.error.RateLimitError:
|
||||
if cfg.debug_mode:
|
||||
print(Fore.RED + "Error: ", "API Rate Limit Reached. Waiting 20 seconds..." + Fore.RESET)
|
||||
print(
|
||||
Fore.RED + "Error: ",
|
||||
"API Rate Limit Reached. Waiting 20 seconds..." + Fore.RESET,
|
||||
)
|
||||
time.sleep(20)
|
||||
except openai.error.APIError as e:
|
||||
if e.http_status == 502:
|
||||
if cfg.debug_mode:
|
||||
print(Fore.RED + "Error: ", "API Bad gateway. Waiting 20 seconds..." + Fore.RESET)
|
||||
print(
|
||||
Fore.RED + "Error: ",
|
||||
"API Bad gateway. Waiting 20 seconds..." + Fore.RESET,
|
||||
)
|
||||
time.sleep(20)
|
||||
else:
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user