Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

How to persist LangChain conversation memory (save and load)?

$
0
0

I'm creating a conversation like so:

llm = ChatOpenAI(temperature=0, openai_api_key=OPENAI_API_KEY, model_name=OPENAI_DEFAULT_MODEL)conversation = ConversationChain(llm=llm, memory=ConversationBufferMemory())

But what I really want is to be able to save and load that ConversationBufferMemory() so that it's persistent between sessions. There doesn't seem to be any obvious tutorials for this but I noticed "Pydantic" so I tried to do this:

saved_dict = conversation.memory.chat_memory.dict()cm = ChatMessageHistory(**saved_dict) # or cm = ChatMessageHistory.parse_obj(saved_dict)

But this fails:

ValidationError: 6 validation errors for ChatMessageHistorymessages -> 0  Can't instantiate abstract class BaseMessage with abstract method type (type=type_error)

Thoughts? I'd love links to any sort of guide, repo, reference, etc.


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>