Skip to content

Commit

Permalink
Update OpenAI backend to use 1.0.0 API (errors in local testing) (#95)
Browse files Browse the repository at this point in the history
Thanks @elliottower for fixing this!
  • Loading branch information
ZhengyaoJiang authored Nov 20, 2023
2 parents 679ca3a + 7b708bd commit e3282fa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions chatarena/backends/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
is_openai_available = False
# logging.warning("openai package is not installed")
else:
openai.api_key = os.environ.get("OPENAI_API_KEY")
if openai.api_key is None:
try:
client = openai.OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
is_openai_available = True
except openai.OpenAIError:
# logging.warning("OpenAI API key is not set. Please set the environment variable OPENAI_API_KEY")
is_openai_available = False
else:
is_openai_available = True

# Default config follows the OpenAI playground
DEFAULT_TEMPERATURE = 0.7
Expand Down Expand Up @@ -72,7 +72,7 @@ def __init__(

@retry(stop=stop_after_attempt(6), wait=wait_random_exponential(min=1, max=60))
def _get_response(self, messages):
completion = openai.ChatCompletion.create(
completion = client.chat.completions.create(
model=self.model,
messages=messages,
temperature=self.temperature,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [
"Operating System :: OS Independent",
]
dependencies = [
"openai>=0.27.2",
"openai>=1.0.0",
"tenacity==8.2.2",
"rich==13.3.3",
"prompt_toolkit==3.0.38",
Expand Down

0 comments on commit e3282fa

Please sign in to comment.