From 6761ffe11a608b19884adfa36c6c88ed60957398 Mon Sep 17 00:00:00 2001 From: Alex Thomas Date: Mon, 16 Dec 2024 19:55:31 +0000 Subject: [PATCH] 100% coverage for GraphCypherQAChain --- .../integration_tests/chains/test_graph_database.py | 1 + libs/neo4j/tests/unit_tests/chains/test_graph_qa.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/libs/neo4j/tests/integration_tests/chains/test_graph_database.py b/libs/neo4j/tests/integration_tests/chains/test_graph_database.py index 3293fcc..1f4046a 100644 --- a/libs/neo4j/tests/integration_tests/chains/test_graph_database.py +++ b/libs/neo4j/tests/integration_tests/chains/test_graph_database.py @@ -77,6 +77,7 @@ def test_cypher_generating_run() -> None: chain = GraphCypherQAChain.from_llm( llm=llm, graph=graph, + validate_cypher=True, allow_dangerous_requests=True, ) output = chain.run("Who starred in Pulp Fiction?") diff --git a/libs/neo4j/tests/unit_tests/chains/test_graph_qa.py b/libs/neo4j/tests/unit_tests/chains/test_graph_qa.py index d966366..030d5cf 100644 --- a/libs/neo4j/tests/unit_tests/chains/test_graph_qa.py +++ b/libs/neo4j/tests/unit_tests/chains/test_graph_qa.py @@ -304,6 +304,19 @@ def test_graph_cypher_qa_chain() -> None: assert True +def test_cypher_generation_failure() -> None: + """Test the chain doesn't fail if the Cypher query fails to be generated.""" + llm = FakeLLM(queries={"query": ""}, sequential_responses=True) + chain = GraphCypherQAChain.from_llm( + llm=llm, + graph=FakeGraphStore(), + allow_dangerous_requests=True, + return_direct=True, + ) + response = chain.run("Test question") + assert response == [] + + def test_no_backticks() -> None: """Test if there are no backticks, so the original text should be returned.""" query = "MATCH (n) RETURN n"