mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-06 07:04:01 +00:00
community[minor]: Relax constraints on CassandraChatMessageHistory constructor (#21241)
This commit is contained in:
parent
3a8d1d8838
commit
2fbe82f5e6
@ -2,11 +2,10 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import typing
|
|
||||||
import uuid
|
import uuid
|
||||||
from typing import List
|
from typing import TYPE_CHECKING, List, Optional
|
||||||
|
|
||||||
if typing.TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from cassandra.cluster import Session
|
from cassandra.cluster import Session
|
||||||
|
|
||||||
from langchain_core.chat_history import BaseChatMessageHistory
|
from langchain_core.chat_history import BaseChatMessageHistory
|
||||||
@ -26,8 +25,8 @@ class CassandraChatMessageHistory(BaseChatMessageHistory):
|
|||||||
Args:
|
Args:
|
||||||
session_id: arbitrary key that is used to store the messages
|
session_id: arbitrary key that is used to store the messages
|
||||||
of a single chat session.
|
of a single chat session.
|
||||||
session: a Cassandra `Session` object (an open DB connection)
|
session: Cassandra driver session. If not provided, it is resolved from cassio.
|
||||||
keyspace: name of the keyspace to use.
|
keyspace: Cassandra key space. If not provided, it is resolved from cassio.
|
||||||
table_name: name of the table to use.
|
table_name: name of the table to use.
|
||||||
ttl_seconds: time-to-live (seconds) for automatic expiration
|
ttl_seconds: time-to-live (seconds) for automatic expiration
|
||||||
of stored entries. None (default) for no expiration.
|
of stored entries. None (default) for no expiration.
|
||||||
@ -36,10 +35,10 @@ class CassandraChatMessageHistory(BaseChatMessageHistory):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
session_id: str,
|
session_id: str,
|
||||||
session: Session,
|
session: Optional[Session] = None,
|
||||||
keyspace: str,
|
keyspace: Optional[str] = None,
|
||||||
table_name: str = DEFAULT_TABLE_NAME,
|
table_name: str = DEFAULT_TABLE_NAME,
|
||||||
ttl_seconds: typing.Optional[int] = DEFAULT_TTL_SECONDS,
|
ttl_seconds: Optional[int] = DEFAULT_TTL_SECONDS,
|
||||||
) -> None:
|
) -> None:
|
||||||
try:
|
try:
|
||||||
from cassio.table import ClusteredCassandraTable
|
from cassio.table import ClusteredCassandraTable
|
||||||
@ -74,7 +73,11 @@ class CassandraChatMessageHistory(BaseChatMessageHistory):
|
|||||||
return messages
|
return messages
|
||||||
|
|
||||||
def add_message(self, message: BaseMessage) -> None:
|
def add_message(self, message: BaseMessage) -> None:
|
||||||
"""Write a message to the table"""
|
"""Write a message to the table
|
||||||
|
|
||||||
|
Args:
|
||||||
|
message: A message to write.
|
||||||
|
"""
|
||||||
this_row_id = uuid.uuid1()
|
this_row_id = uuid.uuid1()
|
||||||
self.table.put(
|
self.table.put(
|
||||||
partition_id=self.session_id,
|
partition_id=self.session_id,
|
||||||
|
Loading…
Reference in New Issue
Block a user