-
Notifications
You must be signed in to change notification settings - Fork 16.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
community[patch]: Support passing graph object to Neo4j integrations (#…
…20876) For driver connection reusage, we introduce passing the graph object to neo4j integrations
- Loading branch information
Showing
4 changed files
with
157 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
libs/community/tests/integration_tests/chat_message_histories/test_neo4j.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import os | ||
|
||
from langchain_core.messages import AIMessage, HumanMessage | ||
|
||
from langchain_community.chat_message_histories import Neo4jChatMessageHistory | ||
from langchain_community.graphs import Neo4jGraph | ||
|
||
|
||
def test_add_messages() -> None: | ||
"""Basic testing: adding messages to the Neo4jChatMessageHistory.""" | ||
assert os.environ.get("NEO4J_URI") is not None | ||
assert os.environ.get("NEO4J_USERNAME") is not None | ||
assert os.environ.get("NEO4J_PASSWORD") is not None | ||
message_store = Neo4jChatMessageHistory("23334") | ||
message_store.clear() | ||
assert len(message_store.messages) == 0 | ||
message_store.add_user_message("Hello! Language Chain!") | ||
message_store.add_ai_message("Hi Guys!") | ||
|
||
# create another message store to check if the messages are stored correctly | ||
message_store_another = Neo4jChatMessageHistory("46666") | ||
message_store_another.clear() | ||
assert len(message_store_another.messages) == 0 | ||
message_store_another.add_user_message("Hello! Bot!") | ||
message_store_another.add_ai_message("Hi there!") | ||
message_store_another.add_user_message("How's this pr going?") | ||
|
||
# Now check if the messages are stored in the database correctly | ||
assert len(message_store.messages) == 2 | ||
assert isinstance(message_store.messages[0], HumanMessage) | ||
assert isinstance(message_store.messages[1], AIMessage) | ||
assert message_store.messages[0].content == "Hello! Language Chain!" | ||
assert message_store.messages[1].content == "Hi Guys!" | ||
|
||
assert len(message_store_another.messages) == 3 | ||
assert isinstance(message_store_another.messages[0], HumanMessage) | ||
assert isinstance(message_store_another.messages[1], AIMessage) | ||
assert isinstance(message_store_another.messages[2], HumanMessage) | ||
assert message_store_another.messages[0].content == "Hello! Bot!" | ||
assert message_store_another.messages[1].content == "Hi there!" | ||
assert message_store_another.messages[2].content == "How's this pr going?" | ||
|
||
# Now clear the first history | ||
message_store.clear() | ||
assert len(message_store.messages) == 0 | ||
assert len(message_store_another.messages) == 3 | ||
message_store_another.clear() | ||
assert len(message_store.messages) == 0 | ||
assert len(message_store_another.messages) == 0 | ||
|
||
|
||
def test_add_messages_graph_object() -> None: | ||
"""Basic testing: Passing driver through graph object.""" | ||
assert os.environ.get("NEO4J_URI") is not None | ||
assert os.environ.get("NEO4J_USERNAME") is not None | ||
assert os.environ.get("NEO4J_PASSWORD") is not None | ||
graph = Neo4jGraph() | ||
# rewrite env for testing | ||
os.environ["NEO4J_USERNAME"] = "foo" | ||
message_store = Neo4jChatMessageHistory("23334", graph=graph) | ||
message_store.clear() | ||
assert len(message_store.messages) == 0 | ||
message_store.add_user_message("Hello! Language Chain!") | ||
message_store.add_ai_message("Hi Guys!") | ||
# Now check if the messages are stored in the database correctly | ||
assert len(message_store.messages) == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters