Skip to content

Commit

Permalink
feat: Support openai 1.14 (#62)
Browse files Browse the repository at this point in the history
* feat: Support openai 1.14

* chore: Fix issue

* chore: Fix issue

* chore: Update version
  • Loading branch information
valeriosofi authored Mar 15, 2024
1 parent fbcb946 commit a588a18
Show file tree
Hide file tree
Showing 6 changed files with 295 additions and 1,413 deletions.
2 changes: 1 addition & 1 deletion nebuly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from .init import init

__all__ = ["init", "new_interaction"]
__version__ = "0.3.24"
__version__ = "0.3.25"
14 changes: 9 additions & 5 deletions nebuly/providers/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from openai import AsyncAzureOpenAI, AsyncOpenAI, AzureOpenAI, OpenAI, _ModuleClient
from openai._response import APIResponse
from openai.pagination import SyncCursorPage
from openai.types.beta.threads import ThreadMessage # type: ignore # noqa: E501
from openai.types.chat.chat_completion import ( # type: ignore # noqa: E501
ChatCompletion,
Choice,
Expand Down Expand Up @@ -47,6 +46,13 @@ class AsyncAPIResponse:
pass


try:
# This import is valid only before openai==1.14.0
from openai.types.beta.threads import ThreadMessage as Message
except ImportError:
from openai.types.beta.threads import Message


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -323,9 +329,7 @@ def _extract_output_generator(
f"or output type: {type(outputs)}"
)

def _openai_assistant_messages_join(
self, messages: list[ThreadMessage]
) -> List[str]:
def _openai_assistant_messages_join(self, messages: list[Message]) -> List[str]:
"""
Join messages from the openai assistant when same role has multiple
messages consecutively
Expand All @@ -346,7 +350,7 @@ def _openai_assistant_messages_join(
return joined_messages

def _openai_assistant_messages(
self, outputs: SyncCursorPage[ThreadMessage]
self, outputs: SyncCursorPage[Message]
) -> Tuple[List[str], List[str]]:
"""
Extract the messages from the openai assistant
Expand Down
Loading

0 comments on commit a588a18

Please sign in to comment.