Spaces:
Sleeping
Sleeping
File size: 479 Bytes
3b362b1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
from langchain.memory import ConversationBufferMemory
def get_memory():
return ConversationBufferMemory(memory_key="chat_history", return_messages=True)
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
def save_message(role: str, content: str):
memory.chat_memory.add_user_message(content) if role=="user" else memory.chat_memory.add_ai_message(content)
def get_history():
return memory.load_memory_variables({})["chat_history"]
|