Member-only story
Custom Memory for ChatGPT API
A Gentle Introduction to LangChain Memory Types
If you have ever used the OpenAI API, I am sure you have noticed the catch.
Got it?
Right! Every time you call the ChatGPT API, the model has no memory of the previous requests you have made. In other words: each API call is a standalone interaction.
And that is definitely annoying when you need to perform follow-up interactions with the model. A chatbot is the golden example where follow-up interactions are needed.
In this article, we will explore how to give memory to ChatGPT when using the OpenAI API, so that it remembers our previous interactions.
Warm-Up!
Let’s perform some interactions with the model so that we experience this default no-memory phenomenon:
prompt = "My name is Andrea"
response = chatgpt_call(prompt)
print(response)
# Output: Nice to meet you, Andrea! How can I assist you today?But when asked a follow-up question:
prompt = "Do you remember my name?"
response = chatgpt_call(prompt)
print(response)
# Output: I'm sorry, as an AI language model, I don't have the ability
# to remember specific information about individual users.
