01. ConversationBufferMemory

ConversationBufferMemory

This memory allows you to save the message and then extract the message to the variable.

First you can extract it as a string.

from langchain.memory import ConversationBufferMemory
memory = ConversationBufferMemory()
memory.save_context(
    inputs={
        "human": "Hello, I want to open a bank account remotely. How to start?"
    },
    outputs={
        "ai": "Hello! We are glad that you would like to open an account. First, Please prepare your ID for verification.?"
    },
)

memory load_memory_variables({}) The function returns the message history.

# 'history' heck the conversation history saved in the key.
memory.load_memory_variables({})
{'history':'Human: Hello, I would like to open a bank account in hypertrophy. How should I start?\nAI: Hello! I am glad you want to open an account. First, can you prepare your ID for your certification?'} 

save_context(inputs, outputs) You can use the method to save the conversation history.

  • This method inputs Wow outputs Receive two factors.

  • inputs Input of the user, outputs Saves the output of AI.

  • With this method, the conversation history history Stored in the key.

  • after load_memory_variables You can use the method to check the history of the saved conversation.

return_messages=True When set to HumanMessage Wow AIMessage Returns the object.

Apply to Chain

ConversationChain Use to conduct a conversation.

Last updated