openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

Threads messages list misinterprets the block type

Open sketch873 opened this issue 1 year ago • 0 comments

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • [x] This is an issue with the Python library

Describe the bug

When getting the messages list for the last response in a run, I sometimes get the following content content=[ImageFileContentBlock(image_file=None, type='text', text={'value': '...'}, (...) ) ] instead of content=[TextContentBlock(text=Text(annotations=[], value="..."), (...))]

The ImageFileContentBlock comes when asking for data from files and the TextContentBlock when asking generic questions like "how are you?". Even if it is the default behavior (not sure why image file of type text), these structures are not structured in the same way, the first one has the 'text' field a dictionary and the second one has a Text object

To Reproduce

  1. create a message (client.beta.threads.messages.create)
  2. create a run and wait for response (client.beta.threads.runs.create_and_poll)
  3. get response (client.beta.threads.messages.list)

Code snippets

messages = client.beta.threads.messages.list(
            thread_id=thread_id,
            run_id=run_id,
            timeout=requests_timeout
        )

OS

Linux

Python version

Python v3.11.4

Library version

openai v1.23.1

sketch873 avatar Apr 19 '24 14:04 sketch873