Skip to content

Commit

Permalink
docs: Add SQLChatMessageHistory docstring (#23978)
Browse files Browse the repository at this point in the history
- **Description:** Add SQLChatMessageHistory docstring.
- **Issue:** the issue #21983

Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
  • Loading branch information
maang-h and eyurtsev authored Jul 11, 2024
1 parent 092e9ee commit 9bcf8f8
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion libs/community/langchain_community/chat_message_histories/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,33 @@ def get_sql_model_class(self) -> Any:


class SQLChatMessageHistory(BaseChatMessageHistory):
"""Chat message history stored in an SQL database."""
"""Chat message history stored in an SQL database.
Example:
.. code-block:: python
from langchain_core.messages import HumanMessage
from langchain_community.chat_message_histories import SQLChatMessageHistory
# create sync sql message history by connection_string
message_history = SQLChatMessageHistory(
session_id='foo', connection_string='sqlite///:memory.db'
)
message_history.add_message(HumanMessage("hello"))
message_history.message
# create async sql message history using aiosqlite
# from sqlalchemy.ext.asyncio import create_async_engine
#
# async_engine = create_async_engine("sqlite+aiosqlite:///memory.db")
# async_message_history = SQLChatMessageHistory(
# session_id='foo', connection=async_engine,
# )
# await async_message_history.aadd_message(HumanMessage("hello"))
# await async_message_history.aget_messages()
"""

@property
@deprecated("0.2.2", removal="0.3.0", alternative="session_maker")
Expand All @@ -131,6 +157,21 @@ def __init__(
engine_args: Optional[Dict[str, Any]] = None,
async_mode: Optional[bool] = None, # Use only if connection is a string
):
"""Initialize with a SQLChatMessageHistory instance.
Args:
session_id: Indicates the id of the same session.
connection_string: String parameter configuration for connecting
to the database.
table_name: Table name used to save data.
session_id_field_name: The name of field of `session_id`.
custom_message_converter: Custom message converter for converting
database data and `BaseMessage`
connection: Database connection object, which can be a string containing
connection configuration, Engine object or AsyncEngine object.
engine_args: Additional configuration for creating database engines.
async_mode: Whether it is an asynchronous connection.
"""
assert not (
connection_string and connection
), "connection_string and connection are mutually exclusive"
Expand Down

0 comments on commit 9bcf8f8

Please sign in to comment.