Skip to content
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

docs: Add RedisChatMessageHistory docstrings #24548

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,43 @@


class RedisChatMessageHistory(BaseChatMessageHistory):
"""Chat message history stored in a Redis database."""
"""Chat message history stored in a Redis database.

Setup:
Install ``redis`` python package.

.. code-block:: bash

pip install redis

Instantiate:
.. code-block:: python

from langchain_community.chat_message_histories import RedisChatMessageHistory

history = RedisChatMessageHistory(
session_id = "your-session-id",
url="redis://your-host:your-port:your-database", # redis://localhost:6379/0
)

Add and retrieve messages:
.. code-block:: python

# Add single message
history.add_message(message)

# Add batch messages
history.add_messages([message1, message2, message3, ...])

# Add human message
history.add_user_message(human_message)

# Add ai message
history.add_ai_message(ai_message)

# Retrieve messages
messages = history.messages
""" # noqa: E501

def __init__(
self,
Expand All @@ -24,6 +60,18 @@ def __init__(
key_prefix: str = "message_store:",
ttl: Optional[int] = None,
):
"""Initialize with a RedisChatMessageHistory instance.

Args:
session_id: str
The ID for single chat session. Used to form keys with `key_prefix`.
url: Optional[str]
String parameter configuration for connecting to the redis.
key_prefix: Optional[str]
The prefix of the key, combined with `session id` to form the key.
ttl: Optional[int]
Set the expiration time of `key`, the unit is seconds.
"""
try:
import redis
except ImportError:
Expand Down
Loading