Adding timestamp in additional args
Browse files
memory.py
CHANGED
@@ -34,10 +34,10 @@ class CustomMongoDBChatMessageHistory(MongoDBChatMessageHistory):
|
|
34 |
return messages
|
35 |
|
36 |
def add_user_message(self, message: str) -> None:
|
37 |
-
self.append(HumanMessage(content=message))
|
38 |
|
39 |
def add_ai_message(self, message: str) -> None:
|
40 |
-
self.append(AIMessage(content=message))
|
41 |
|
42 |
def append(self, message: BaseMessage) -> None:
|
43 |
"""Append the message to the record in MongoDB with the desired format"""
|
@@ -56,7 +56,7 @@ class CustomMongoDBChatMessageHistory(MongoDBChatMessageHistory):
|
|
56 |
# Update the messages array with the new message object
|
57 |
self.collection.update_one(
|
58 |
{"SessionId": self.session_id},
|
59 |
-
{"$push": {"messages": json.dumps(_message_to_dict(message))}},
|
60 |
upsert=True
|
61 |
)
|
62 |
except errors.WriteError as err:
|
|
|
34 |
return messages
|
35 |
|
36 |
def add_user_message(self, message: str) -> None:
|
37 |
+
self.append(HumanMessage(content=message, additional_kwargs={"timestamp": datetime.utcnow()}))
|
38 |
|
39 |
def add_ai_message(self, message: str) -> None:
|
40 |
+
self.append(AIMessage(content=message, additional_kwargs={"timestamp": datetime.utcnow()}))
|
41 |
|
42 |
def append(self, message: BaseMessage) -> None:
|
43 |
"""Append the message to the record in MongoDB with the desired format"""
|
|
|
56 |
# Update the messages array with the new message object
|
57 |
self.collection.update_one(
|
58 |
{"SessionId": self.session_id},
|
59 |
+
{"$push": {"messages": json.dumps(_message_to_dict(message), default=str)}},
|
60 |
upsert=True
|
61 |
)
|
62 |
except errors.WriteError as err:
|