mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-25 16:13:25 +00:00
Order messages in PostgresChatMessageHistory (#6830)
Fixes issue: https://github.com/hwchase17/langchain/issues/6829 This guarantees message history is in the correct order. --------- Co-authored-by: Dev 2049 <dev.dev2049@gmail.com>
This commit is contained in:
parent
e9950392dd
commit
0f6737735d
@ -49,7 +49,9 @@ class PostgresChatMessageHistory(BaseChatMessageHistory):
|
||||
@property
|
||||
def messages(self) -> List[BaseMessage]: # type: ignore
|
||||
"""Retrieve the messages from PostgreSQL"""
|
||||
query = f"SELECT message FROM {self.table_name} WHERE session_id = %s;"
|
||||
query = (
|
||||
f"SELECT message FROM {self.table_name} WHERE session_id = %s ORDER BY id;"
|
||||
)
|
||||
self.cursor.execute(query, (self.session_id,))
|
||||
items = [record["message"] for record in self.cursor.fetchall()]
|
||||
messages = messages_from_dict(items)
|
||||
|
Loading…
Reference in New Issue
Block a user