File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change 1
- from json import dumps , loads
2
1
from typing import AsyncIterator , Iterator , NamedTuple , TypedDict
3
2
3
+ from msgspec .json import decode , encode
4
4
from numpy import float32
5
5
from numpy .typing import NDArray
6
6
@@ -168,7 +168,7 @@ async def save_messages(
168
168
finally :
169
169
answer_to_save : Message = {'role' : 'assistant' , 'content' : '' .join (answer_accumulator )}
170
170
message_history .append (answer_to_save )
171
- await self .redis .set (f'chat:{ chat_id } ' , dumps (message_history ))
171
+ await self .redis .set (f'chat:{ chat_id } ' , encode (message_history ))
172
172
173
173
async def get_messages (self , chat_id : str ) -> list [Message ]:
174
174
"""
@@ -185,7 +185,7 @@ async def get_messages(self, chat_id: str) -> list[Message]:
185
185
messages (list[Message]) : the messages
186
186
"""
187
187
messages_json : str | None = await self .redis .get (f'chat:{ chat_id } ' )
188
- return [] if not messages_json else loads (messages_json )
188
+ return [] if not messages_json else decode (messages_json , type = list [ Message ] )
189
189
190
190
async def get_chat_id (self , key : str ) -> str | None :
191
191
"""
You can’t perform that action at this time.
0 commit comments