Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'MessageContentText' from 'openai.types.beta.threads' #1369

Open
utkarsh27a opened this issue May 16, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@utkarsh27a
Copy link

馃悰 Describe the bug

Issue: ImportError with OpenAI Version > 1.13.4

Description:

When using OpenAI version > 1.13.4 in pip dependencies, the following error occurs:

ImportError: cannot import name 'MessageContentText' from 'openai.types.beta.threads'

This error arises because MessageContentText is not present in openai.types.beta.threads.

Steps to Reproduce:

  1. Use OpenAI assistants.
  2. Import OpenAIAssistant using:
    from embedchain.store.assistants import OpenAIAssistant
  3. The error mentioned above will be triggered.

Please ensure the OpenAI version in your dependencies is <= 1.13.4 to avoid this issue.

@jstnmthw
Copy link

It looks like they changed up the typing to do unions of Image and Text on MessageContent

You can take a look at these types: MessageContent and TextContentBlock

from openai.types.beta.threads.message_content import MessageContent
from openai.types.beta.threads.text_content_block import TextContentBlock

In my case, I had to update:

From:
if isinstance(messages.data[0].content[0], MessageContentText):

To:
if isinstance(messages.data[0].content[0], TextContentBlock):

@Dev-Khant Dev-Khant added the bug Something isn't working label Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants