Skip to content

added a method to update session id in PostgresChatMessageHistory #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions langchain_postgres/chat_message_histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

This client provides support for both sync and async via psycopg 3.
"""

from __future__ import annotations

import json
Expand Down Expand Up @@ -370,3 +371,12 @@ async def aclear(self) -> None:
async with self._aconnection.cursor() as cursor:
await cursor.execute(query, {"session_id": self._session_id})
await self._aconnection.commit()

def update_session_id(self, new_session_id: str) -> None:
"""Update the session ID for the current instance and in the database"""
update_query = (
f"UPDATE {self._table_name} SET session_id = %s WHERE session_id = %s;"
)
with self._connection.cursor() as cursor:
cursor.execute(update_query, (new_session_id, self._session_id))
self._connection.commit()