Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update OpenAI backend to use 1.0.0 API (errors in local testing) #95

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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