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.

Copy

from langchain.memory import ConversationBufferMemory

Copy

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.

Copy

# 'history' heck the conversation history saved in the key.
memory.load_memory_variables({})

Copy

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.

Copy

Copy

Copy

Copy

Copy

Copy

Copy

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

Copy

Copy

Copy

Apply to Chain

Copy

Copy

ConversationChain Use to conduct a conversation.

Copy

Copy

Copy

Last updated