Closed hkaraoguz closed 1 day ago
I can see how this isn't intuitive but this is happening because the iterator is making multiple requests, if you just want the single page then you need to use .data
import openai
import os
client = openai.Client(api_key=os.getenv("OPENAI_API_KEY"))
thread = client.beta.threads.retrieve(thread_id="<thread_id>")
messages = client.beta.threads.messages.list(thread_id=thread.id, limit=3)
for i,message in enumerate(messages.data):
print(message.role)
print(message.created_at)
Unfortunately I'm not sure if there's anything we can change to make this easier to understand...
Thank you @RobertCraigie for your prompt reply. I suspected that I was misunderstanding the usage and now I learned.
Confirm this is an issue with the Python library and not an underlying OpenAI API
Describe the bug
When I try to fetch a limited number of messages from a thread, I receive all the messages instead.
To Reproduce
Code snippets
OS
Ubuntu 22.04
Python version
Python v3.10.12
Library version
openai v1.54.3