Sitemap
TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Member-only story

Custom Memory for ChatGPT API

A Gentle Introduction to LangChain Memory Types

8 min readAug 20, 2023

--

Press enter or click to view image in full size
Self-made gif.

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.

--

--

TDS Archive
TDS Archive

Published in TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Andrea Valenzuela
Andrea Valenzuela

Written by Andrea Valenzuela

AI Researcher 🚀 | Writing about Artificial Intelligence & Large Language Models 👩🏻‍💻 | Sharing tricks and experiences✨