i wanted to seek support on persistant chats with GPT because as in chatgpt official ui there we can talk on a specific topic contiousely and chatgpt know previous chat.
but in our api how we keep such sessions
You just need to append the old messages to the back of the new prompt you send…
Thanks for support
but wouldnt this cause alot of tokens?
Yup. Unfortunately, that’s the only way at the moment. One thing you can try to do is summarize the very old chats to get their tokens down. Good luck!
There are two mainstream ways to achieve long-term memory at the moment:
- Embeddings - divide the past conversations into parts, use embeddings to search for parts that are related to the last part of the conversation and include the related parts at the beginning of the prompt.
- Summarization - summarize the previous parts of the conversation and include summary at the beginning of the prompt.
I suppose Langchain library can help you achieve both.
Thanks i appreciate your support. I hope openAi keep this in consideration for upcoming updates
This is a thread I started discussing the very same question: Chat Completion Architechture
This is the new flowchart I put together which works to do exactly what you wish: Maintain the chat context between API calls:
And a video I put together showing the process in action: SolrAI: How the chat completion process with standalone question maintains conversational context - YouTube
In my experience, not as many as you may think. And, as the chat history grows, you can always “prune” it, removing the earliest responses.