diff --git a/autogen/oai/client.py b/autogen/oai/client.py index f22562efca59..a6569ec0240e 100644 --- a/autogen/oai/client.py +++ b/autogen/oai/client.py @@ -14,7 +14,7 @@ TOOL_ENABLED = False try: import openai - from openai import OpenAI, APIError + from openai import OpenAI, APIError, __version__ as OPENAIVERSION from openai.types.chat import ChatCompletion from openai.types.chat.chat_completion import ChatCompletionMessage, Choice from openai.types.completion import Completion @@ -330,8 +330,8 @@ def _completions_create(self, client, params): ), ) for i in range(len(response_contents)): - try: - # OpenAI versions 0.1.5 and above + if OPENAIVERSION >= "1.5": # pragma: no cover + # OpenAI versions 1.5.0 and above choice = Choice( index=i, finish_reason=finish_reasons[i], @@ -340,8 +340,8 @@ def _completions_create(self, client, params): ), logprobs=None, ) - except ValidationError: - # OpenAI version up to 0.1.4 + else: + # OpenAI versions below 1.5.0 choice = Choice( index=i, finish_reason=finish_reasons[i], diff --git a/setup.py b/setup.py index bc06e10cc603..8c61cb085b50 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ __version__ = version["__version__"] install_requires = [ - "openai>=1,<1.5", # a temporary fix for breaking changes in 1.5 + "openai>=1.3,<1.5", "diskcache", "termcolor", "flaml",