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

A Light Introduction to LangChain Reminiscence Varieties

Self-made gif.

You probably 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 positively annoying when it is advisable 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 the best way to 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 keep in mind my title?"
response = chatgpt_call(immediate)

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

Proper, so in actual fact the mannequin doesn’t keep in mind my title despite the fact that it was given on the primary interplay.

Notice: The strategy 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 wish to test it out!

Some folks usually work round this memoryless scenario by pre-feeding the earlier dialog historical past to the mannequin each time they do a brand new API name. However, this follow isn’t cost-optimized and it has definitely a restrict for lengthy conversations.

With a view to create a reminiscence for ChatGPT in order that it’s conscious of the earlier interactions, we can be utilizing the favored langchain framework. This framework lets you simply handle the ChatGPT dialog historical past and optimize it by selecting the best reminiscence kind on your software.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button