OpenAI’s ChatGPT API does not provide built-in functionality for pagination because the concept of pagination inherently requires storage/memory of all previous dialogues. The API interaction happens on a case by case basis and doesn’t store any conversation history.
If you want to handle pagination at your end, you would essentially provide the conversation history yourself.
Here’s a basic example:
1. Start with the first API call with your messages.
2. When you want to “go to the next page”, make another API call and include the entire conversation history, adding the new messages.
3. If you want to “go back a page”, you would again make an API call with the conversation up to the point you want.
Remember, each API call should include a conversation history with your recent message as the system does not maintain state between requests.
Also, be aware of the maximum token limit (4096 tokens for gpt-3.5-turbo as of March 1, 2023) in each API call. If a conversation exceeds this limit, you will need to truncate, summarise or otherwise reduce your text until it fits.