You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.
Max number of tokens per request (prompt + completion) is 4096.
Two ways to get the number of tokens used:
Use the num_tokens_from_messagesbefore making the API call (Best way, we don't need any API call)
Access response['usage']['total_tokens']
What happens if tokens > 4096?
Add a warning message to the logfile
Build a new messages list containing the prompt for the assistant (if any, should be the very first message) plus the last 3 messages in the chat history. The number of messages kept should be configurable by the user
The text was updated successfully, but these errors were encountered:
edoardob90
changed the title
Handle chat history exceeding max number of tokens per request (4096)
Handle chat history exceeding max tokens
Mar 9, 2023
Another option to fit a long conversation into the max tokens limit: First, ask the model to summarize in Q&A the conversation up to know, using less than a given number of tokens. Then, the summarized version of the chat can be passed in as chat history.
Create a history_max_length settings (default is None). If set, the messages sent for a chat completion are at most this many.
The finish_reason in the API response indicates why the model stopped generating (docs). If finish_reason == length, it means the output is incomplete due to the max tokens limit reached. In this case, a warning message should be sent to the user, asking them to start a new chat.
Max number of tokens per request (prompt + completion) is 4096.
Two ways to get the number of tokens used:
num_tokens_from_messages
before making the API call (Best way, we don't need any API call)response['usage']['total_tokens']
What happens if tokens > 4096?
messages
list containing the prompt for the assistant (if any, should be the very first message) plus the last 3 messages in the chat history. The number of messages kept should be configurable by the userThe text was updated successfully, but these errors were encountered: