Since this simple memory type doesn't actually take into account the chain input when loading memory, we can pass in an empty input for now:memory.load_memory_variables({})    {'history': 'Human: hi!\nAI: whats up?'}We can also keep a sliding window of the most recent k interactions using ConversationBufferWindowMemory.from langchain.memory import ConversationBufferWindowMemorymemory = ConversationBufferWindowMemory(k=1)memory.save_context({"input": "hi"}, {"output": "whats up"})memory.save_context({"input": "not much you"}, {"output": "not much"})memory.load_memory_variables({})    {'history': 'Human: not much you\nAI: not much'}ConversationSummaryMemory is an extension of this theme.It creates a summary of the conversation over time. This memory is most useful for longer conversations where the full message history would consume many tokens.from langchain.llms import OpenAIfrom langchain.memory import ConversationSummaryMemoryllm = OpenAI(temperature=0)memory = ConversationSummaryMemory(llm=llm)memory.save_context({"input": "hi"},{"output": "whats up"})memory.save_context({"input": "im working on better docs for chatbots"},{"output": "oh, that sounds like a lot of work"})memory.save_context({"input": "yes, but it's worth the effort"},{"output": "agreed, good docs are important!"})memory.load_memory_variables({})    {'history': '\nThe human greets the AI, to which the AI responds. The human then mentions they are working on better docs for chatbots, to which the AI responds that it sounds like a lot of work. The human agrees that it is worth the effort, and the AI agrees that good docs are important.'}ConversationSummaryBufferMemory extends this a bit further:It uses token length rather than number of interactions to determine when to flush interactions.from langchain.memory import ConversationSummaryBufferMemorymemory = ConversationSummaryBufferMemory(llm=llm, max_token_limit=10)memory.save_context({"input": "hi"}, {"output": "whats
Open In Colab
Open In Colab ->: Since this simple memory type doesn't actually take into account the chain input when loading memory, we can pass in an empty input for now:memory.load_memory_variables({})    {'history': 'Human: hi!\nAI: whats up?'}We can also keep a sliding window of the most recent k interactions using ConversationBufferWindowMemory.from langchain.memory import ConversationBufferWindowMemorymemory = ConversationBufferWindowMemory(k=1)memory.save_context({"input": "hi"}, {"output": "whats up"})memory.save_context({"input": "not much you"}, {"output": "not much"})memory.load_memory_variables({})    {'history': 'Human: not much you\nAI: not much'}ConversationSummaryMemory is an extension of this theme.It creates a summary of the conversation over time. This memory is most useful for longer conversations where the full message history would consume many tokens.from langchain.llms import OpenAIfrom langchain.memory import ConversationSummaryMemoryllm = OpenAI(temperature=0)memory = ConversationSummaryMemory(llm=llm)memory.save_context({"input": "hi"},{"output": "whats up"})memory.save_context({"input": "im working on better docs for chatbots"},{"output": "oh, that sounds like a lot of work"})memory.save_context({"input": "yes, but it's worth the effort"},{"output": "agreed, good docs are important!"})memory.load_memory_variables({})    {'history': '\nThe human greets the AI, to which the AI responds. The human then mentions they are working on better docs for chatbots, to which the AI responds that it sounds like a lot of work. The human agrees that it is worth the effort, and the AI agrees that good docs are important.'}ConversationSummaryBufferMemory extends this a bit further:It uses token length rather than number of interactions to determine when to flush interactions.from langchain.memory import ConversationSummaryBufferMemorymemory = ConversationSummaryBufferMemory(llm=llm, max_token_limit=10)memory.save_context({"input": "hi"}, {"output": "whats