diff --git a/chatarena/backends/openai.py b/chatarena/backends/openai.py index 2745d683..74e577ef 100644 --- a/chatarena/backends/openai.py +++ b/chatarena/backends/openai.py @@ -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 @@ -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, diff --git a/pyproject.toml b/pyproject.toml index 62a02845..658d259f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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",