diff --git a/nebuly/providers/openai.py b/nebuly/providers/openai.py index de52a89..f26e8b1 100644 --- a/nebuly/providers/openai.py +++ b/nebuly/providers/openai.py @@ -27,6 +27,17 @@ from nebuly.entities import HistoryEntry, ModelInput from nebuly.providers.base import PicklerHandler, ProviderDataExtractor +try: + # This import is valid only starting from openai==1.8.0 + from openai._legacy_response import ( # pylint: disable=ungrouped-imports # type: ignore # noqa: E501 + LegacyAPIResponse, + ) +except ImportError: + + class LegacyAPIResponse: + pass + + logger = logging.getLogger(__name__) @@ -230,7 +241,7 @@ def extract_output( # pylint: disable=too-many-return-statements ).message.function_call.arguments, } ) - if isinstance(outputs, APIResponse): + if isinstance(outputs, (APIResponse, LegacyAPIResponse)): payload_dict = json.loads(outputs.content.decode("utf-8")) if payload_dict.get("object") == "chat.completion": payload = ChatCompletion(**payload_dict) diff --git a/pyproject.toml b/pyproject.toml index e9dba2d..0a77b43 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nebuly" -version = "0.3.15" +version = "0.3.16" description = "The SDK for instrumenting applications for tracking AI costs." authors = ["Nebuly"] readme = "README.md"