mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +00:00
docs: Add SQLChatMessageHistory docstring (#23978)
- **Description:** Add SQLChatMessageHistory docstring. - **Issue:** the issue #21983 Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
This commit is contained in:
parent
092e9ee0e6
commit
9bcf8f867d
@ -113,7 +113,33 @@ _warned_once_already = False
|
||||
|
||||
|
||||
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")
|
||||
@ -131,6 +157,21 @@ class SQLChatMessageHistory(BaseChatMessageHistory):
|
||||
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"
|
||||
|
Loading…
Reference in New Issue
Block a user