File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
src/langchain_google_cloud_sql_pg Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -106,11 +106,17 @@ def create_sync(
106106 history = engine ._run_as_sync (coro )
107107 return cls (cls .__create_key , engine , history )
108108
109- @property # type: ignore[override]
109+ @property
110110 def messages (self ) -> list [BaseMessage ]:
111- """The abstraction required a property ."""
111+ """Fetches all messages stored in AlloyDB ."""
112112 return self ._engine ._run_as_sync (self ._history ._aget_messages ())
113113
114+ @messages .setter
115+ def messages (self , value : list [BaseMessage ]) -> None :
116+ """Clear the stored messages and appends a list of messages to the record in AlloyDB."""
117+ self .clear ()
118+ self .add_messages (value )
119+
114120 async def aadd_message (self , message : BaseMessage ) -> None :
115121 """Append the message to the record in PostgreSQL"""
116122 await self ._engine ._run_as_async (self ._history .aadd_message (message ))
Original file line number Diff line number Diff line change @@ -163,6 +163,20 @@ async def test_chat_message_history_sync_messages(
163163 assert len (history2 .messages ) == 0
164164
165165
166+ @pytest .mark .asyncio
167+ async def test_chat_message_history_set_messages (
168+ async_engine : PostgresEngine ,
169+ ) -> None :
170+ history = await PostgresChatMessageHistory .create (
171+ engine = async_engine , session_id = "test" , table_name = table_name_async
172+ )
173+ msg1 = HumanMessage (content = "hi!" )
174+ msg2 = AIMessage (content = "bye -_-" )
175+ # verify setting messages property adds to message history
176+ history .messages = [msg1 , msg2 ]
177+ assert len (history .messages ) == 2
178+
179+
166180@pytest .mark .asyncio
167181async def test_chat_table_async (async_engine ):
168182 with pytest .raises (ValueError ):
You can’t perform that action at this time.
0 commit comments