Customized Reminiscence for ChatGPT API. A Mild Introduction to LangChain… | by Andrea Valenzuela | Aug, 2023

A Mild Introduction to LangChain Reminiscence Varieties

Self-made gif.

When you have ever used the OpenAI API, I’m certain you’ve gotten seen the catch.

Obtained it?

Proper! Each time you name the ChatGPT API, the mannequin has no reminiscence of the earlier requests you’ve gotten made. In different phrases: every API name is a standalone interplay.

And that’s undoubtedly annoying when you could carry out follow-up interactions with the mannequin. A chatbot is the golden instance the place follow-up interactions are wanted.

On this article, we’ll discover give reminiscence to ChatGPT when utilizing the OpenAI API, in order that it remembers our earlier interactions.

Let’s carry out some interactions with the mannequin in order that we expertise this default no-memory phenomenon:

immediate = "My title is Andrea"
response = chatgpt_call(immediate)

# Output: Good to satisfy you, Andrea! How can I help you as we speak?

However when requested a follow-up query:

immediate = "Do you bear in mind my title?"
response = chatgpt_call(immediate)

# Output: I am sorry, as an AI language mannequin, I haven't got the flexibility
# to recollect particular details about particular person customers.

Proper, so the truth is the mannequin doesn’t bear in mind my title although it was given on the primary interplay.

Observe: The tactic chatgpt_call() is only a wrapper across the OpenAI API. We already gave a shot on how simply name GPT fashions at ChatGPT API Calls: A Gentle Introduction in case you need to test it out!

Some individuals usually work round this memoryless state of affairs by pre-feeding the earlier dialog historical past to the mannequin each time they do a brand new API name. However, this follow will not be cost-optimized and it has actually a restrict for lengthy conversations.

With the intention to create a reminiscence for ChatGPT in order that it’s conscious of the earlier interactions, we will probably be utilizing the favored langchain framework. This framework permits you to simply handle the ChatGPT dialog historical past and optimize it by choosing the proper reminiscence kind in your software.

Hierarchical partial pooling with tfprobability

BERT vs GPT: Evaluating the NLP Giants | by Thao Vu | Aug, 2023