Memory Chatbot
Build a Memory Chatbot flow for a chatbot application using Chat Memory.
This flow extends the Basic Prompting flow with a Chat memory component that stores previous chat messages and uses them to provide context for the current conversation.
Open Langflow and start a new project
-
In the Astra Portal header, switch your active app from Astra DB Serverless to Langflow.
-
In Langflow, click New Project, and then select the Memory Chatbot project.
This opens a starter project with the necessary components to run a chatbot application using Chat Memory.
Memory Chatbot flow
The Memory Chatbot flow consists of these components:
-
The Chat Input component accepts user input to the chat.
-
The Prompt component combines the user input with a user-defined prompt.
-
The OpenAI model component sends the user input and prompt to the OpenAI API and receives a response.
-
The Chat Output component prints the flow’s output to the chat.
-
The Chat Memory component retrieves previous messages and sends them to the Prompt component to fill the template with context.
Run the Memory Chatbot flow
-
Add your credentials to the Open AI component. The fastest and most secure way to add credentials is with Langflow’s Global Variables.
-
Click
Settings, and then click Global Variables. -
Click Add New.
-
Name your variable. Paste your API key in the Value field.
-
In the Apply To Fields field, select the field you want to globally apply this variable to.
-
Click Save Variable.
-
-
Click
Playground to start a chat session. -
Enter a query, and then make sure the bot responds according to the prompt you set in the Prompt component.
-
Click the Memories tab to view your queries in chronological order. Up to 100 queries are stored by default.
-
To validate that previous knowledge is taking effect, try the following:
-
Tell the AI your name in one message, and then ask
What is my name?
in a subsequent message. -
Ask
What is the first subject I asked you about?
-
Now that your query has completed the journey from Chat Input to Chat Memory, you have completed the Memory Chatbot flow.
Next steps
To interact with this flow as an API endpoint, see the Langflow API.