Find answers from the community

Updated 3 months ago

Chat memory

Best way to serialize ChatMemoryBuffer? JSON no bueno.
L
b
30 comments
We really need to implement a method for this πŸ˜…

Why is JSON no Bueno?
json.dumps ( doesn't work
is what I mean by no bueno
because it's not implemented.
json_str = chat_memory_buffer.json()
does that work?
loaded_memory = ChatMemoryBuffer.parse_raw(json_str) should load it
oh you real
that's perfect
Plain Text
Traceback (most recent call last):
langchainapi-langchain-1  |   File "/srv/src/gpt.py", line 201, in chat
langchainapi-langchain-1  |     print(self.memory.json())
langchainapi-langchain-1  |   File "pydantic/main.py", line 504, in pydantic.main.BaseModel.json
langchainapi-langchain-1  |   File "/usr/local/lib/python3.9/json/__init__.py", line 234, in dumps
langchainapi-langchain-1  |     return cls(
langchainapi-langchain-1  |   File "/usr/local/lib/python3.9/json/encoder.py", line 199, in encode
langchainapi-langchain-1  |     chunks = self.iterencode(o, _one_shot=True)
langchainapi-langchain-1  |   File "/usr/local/lib/python3.9/json/encoder.py", line 257, in iterencode
langchainapi-langchain-1  |     return _iterencode(o, 0)
langchainapi-langchain-1  |   File "pydantic/json.py", line 90, in pydantic.json.pydantic_encoder
langchainapi-langchain-1  | TypeError: Object of type 'partial' is not JSON serializable
pydantic noooo
i can try implementing my own jsonencoder for chatmemory buffer
There's a more verbose workaround, with will encode each message as json. Would be nice to have the entire thing encoded though
I think it just needs to skip encoding the tokenizer
That attribute is probably causing issues
I wonder if I can get pydantic to ignore it and use the default when loading
ayyy got it working
PR coming soon, this is long overdue haha
oh wow nice
are you just skipping the tokenizer?
yea, you can set it to exclude and it won't attempt to serialize it

Just trying to deal with some mypy issues now haha
no need for 2 pr approvals?
also when do releases happen?
lol I merge on my own schedule (well, only sometimes πŸ˜† )
Release is probably daily, so likely tomorrow? Although feel free to install from source if you need it now
Add a reply
Sign up and join the conversation on Discord