Skip to content

Commit

Permalink
Fixed the CI and CD errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kingtroga committed Nov 9, 2024
1 parent 1b497f9 commit a9831ae
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List, Optional, Union
import os
import redis.exceptions
from typing import List, Optional, Union

import redis.exceptions
from langchain_core.chat_history import BaseChatMessageHistory
from langchain_core.messages import (
AIMessage,
Expand All @@ -26,14 +26,20 @@ class FalkorDBChatMessageHistory(BaseChatMessageHistory):
password (Optional[str]): Password for authenticating with FalkorDB.
host (str): Host where the FalkorDB is running. Defaults to 'localhost'.
port (int): Port number where the FalkorDB is running. Defaults to 6379.
node_label (str): Label for the session node in the graph. Defaults to "Session".
window (int): The number of messages to retrieve when querying the history. Defaults to 3.
ssl (bool): Whether to use SSL for connecting to the database. Defaults to False.
graph (Optional[FalkorDBGraph]): Optionally provide an existing FalkorDBGraph object for connecting.
node_label (str): Label for the session node
in the graph. Defaults to "Session".
window (int): The number of messages to retrieve when querying
the history. Defaults to 3.
ssl (bool): Whether to use SSL for connecting
to the database. Defaults to False.
graph (Optional[FalkorDBGraph]): Optionally provide an existing
FalkorDBGraph object for connecting.
Example:
.. code-block:: python
from langchain_community.chat_message_histories import FalkorDBChatMessageHistory
from langchain_community.chat_message_histories import (
FalkorDBChatMessageHistory
)
history = FalkorDBChatMessageHistory(
session_id="1234",
Expand All @@ -56,7 +62,10 @@ def __init__(
*,
graph: Optional[FalkorDBGraph] = None,
) -> None:
"""Initialize the FalkorDBChatMessageHistory class with the session and connection details."""
"""
Initialize the FalkorDBChatMessageHistory
class with the session and connection details.
"""
try:
import falkordb
except ImportError:
Expand Down Expand Up @@ -115,21 +124,23 @@ def __init__(
if "already indexed" in e:
raise ValueError(f"{self._node_label} has already been indexed")

def _process_records(self, records: list) -> list:
def _process_records(self, records: list) -> List[BaseMessage]:
"""Process the records from FalkorDB and convert them into BaseMessage objects.
Args:
records (list): The raw records fetched from the FalkorDB query.
Returns:
list: A list of `BaseMessage` objects.
List[BaseMessage]: A list of `BaseMessage` objects.
"""
messages = []
# Explicitly set messages as a list of BaseMessage
messages: List[BaseMessage] = []

for record in records:
content = record[0].get("data", {}).get("content", "")
message_type = record[0].get("type", "").lower()

# Append the correct message type to the list
if message_type == "human":
messages.append(
HumanMessage(
Expand All @@ -143,7 +154,7 @@ def _process_records(self, records: list) -> list:
)
)
else:
print(f"Unknown message type: {message_type}")
raise ValueError(f"Unknown message type: {message_type}")

return messages

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Integration tests for FalkorDB Chat History/Memory functionality.
Note:
These tests are conducted using a local FalkorDB instance but can also
These tests are conducted using a local FalkorDB instance but can also
be run against a Cloud FalkorDB instance. Ensure that appropriate host,port
cusername, and password configurations are set up
cusername, and password configurations are set up
before running the tests.
Test Cases:
Expand All @@ -14,11 +14,15 @@
when passing the FalkorDB driver through a graph object.
"""

from langchain_core.messages import AIMessage, HumanMessage

from langchain_community.chat_message_histories.falkordb import FalkorDBChatMessageHistory
from langchain_community.chat_message_histories.falkordb import (
FalkorDBChatMessageHistory,
)
from langchain_community.graphs import FalkorDBGraph


def test_add_messages() -> None:
"""Basic testing: add messages to the FalkorDBChatMessageHistory."""
message_store = FalkorDBChatMessageHistory("500daysofSadiya")
Expand Down

0 comments on commit a9831ae

Please sign in to comment.