Skip to content

Commit

Permalink
Merge pull request #54 from nebuly-ai/chore/add-media-field
Browse files Browse the repository at this point in the history
fix: Fix raw response with newer openai
  • Loading branch information
diegofiori authored Feb 26, 2024
2 parents c400a62 + d3b2cd8 commit ff5957f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion nebuly/providers/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)


Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit ff5957f

Please sign in to comment.