Skip to content
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

fix: Set the max history messages to 9 #438

Merged
merged 2 commits into from
Sep 16, 2023
Merged

Conversation

iRedScarf
Copy link
Contributor

Description

Set the default context to send only the latest 9 historical messages to avoid exceeding the tokens limit error after chatting for a period of time.

Change the maximum number of history messages by setting the environment variable PUBLIC_MAX_HISTORY_MESSAGES if needed.

It's not recommended to set it too low, such as 2, as it can easily lead to AI making random mistakes, even if it is GPT-4.

Linked Issues

#309

Additional context

Anse is a very useful application, but ChatGPT-Demo is more suitable for deployment to relatives and friends who don’t know much about software.

However, during the use of ChatGPT-Demo, when the chat goes on for a long time, the context_length_exceeded error will easily occur.

After studying the file code of ChatGPT-Demo, I found that when it sends a message to the OpenAI API, it will send all historical messages together. No wonder it exceeds the token limit after chatting for a period of time.

This will also cause excessive consumption of tokens.

Therefore, I think it might be appropriate to set a certain length limit on the context messages sent to the OpenAI API. This can ensure that the chat continues in most cases.

Even though the AI might become "forgetful," it would still provide a better experience than clearing all chat history and starting over.

I set the default context message count to 9, which allows the OpenAI API to receive the latest 4 complete question and answer exchanges, as well as the most recent question.

Set the default context to only send the latest 10 historical messages (the AI reply is also counted as 1) to avoid exceeding the tokens limit error after chatting for a period of time.
Change the maximum number of history messages by setting the environment variable `PUBLIC_MAX_HISTORY_MESSAGES` if need to.
It's not recommended to set it too low, such as 2, as it can easily lead to AI making random mistakes, even if it is gpt-4.
@vercel
Copy link

vercel bot commented Sep 15, 2023

@iRedScarf is attempting to deploy a commit to the ddiu8081's Team Team on Vercel.

A member of the Team first needs to authorize it.

@yzh990918 yzh990918 merged commit d8d84d0 into anse-app:main Sep 16, 2023
4 of 5 checks passed
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

Successfully merging this pull request may close these issues.

2 participants