Skip to content

Limit not working when listing messages #1045

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
cajomferro opened this issue Jan 4, 2024 · 1 comment
Closed
1 task done

Limit not working when listing messages #1045

cajomferro opened this issue Jan 4, 2024 · 1 comment

Comments

@cajomferro
Copy link

cajomferro commented Jan 4, 2024

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

  • This is an issue with the Python library

Describe the bug

I'm not able to list messages of a thread filtering by a certain limit.

To Reproduce

See the code snippet below.

Code snippets

# Assuming we have 20 messages in a thread with id "XYZ".


raw_messages = []
async for m in assistant.async_beta_client.threads.messages.list("XYZ", order="asc", limit=1):
    print(m)
    raw_messages.append(m) 
print(len(raw_messages))

# At the end of this code, the result is 20 and the loop runs 20 times. I was expecting a single result.

OS

macOS

Python version

Python v3.11

Library version

openai v1.6.1 (but also previous versions)

@cajomferro cajomferro added the bug Something isn't working label Jan 4, 2024
@rattrayalex rattrayalex closed this as not planned Won't fix, can't repro, duplicate, stale Jan 10, 2024
@rattrayalex
Copy link
Collaborator

Ah, you are actually making 20 API calls here, thanks to our auto-pagination feature (see the README). To make just a few:

raw_messages = []
page = await assistant.async_beta_client.threads.messages.list("XYZ", order="asc", limit=1)
for m in page.data:
    print(m)
    raw_messages.append(m) 
print(len(raw_messages))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants