From 6a45bf9554f481af0aac9af954e7cdf91c40b914 Mon Sep 17 00:00:00 2001 From: Rafael Pereira <82586689+RafaelXokito@users.noreply.github.com> Date: Fri, 19 Jul 2024 19:03:14 +0100 Subject: [PATCH] community[minor]: GraphCypherQAChain to accept additional inputs as provided by the user for cypher generation (#24300) **Description:** This PR introduces a change to the `cypher_generation_chain` to dynamically concatenate inputs. This improvement aims to streamline the input handling process and make the method more flexible. The change involves updating the arguments dictionary with all elements from the `inputs` dictionary, ensuring that all necessary inputs are dynamically appended. This will ensure that any cypher generation template will not require a new `_call` method patch. **Issue:** This PR fixes issue #24260. --- .../langchain_community/chains/graph_qa/cypher.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/community/langchain_community/chains/graph_qa/cypher.py b/libs/community/langchain_community/chains/graph_qa/cypher.py index e4168cccef972..2d6263cf8b058 100644 --- a/libs/community/langchain_community/chains/graph_qa/cypher.py +++ b/libs/community/langchain_community/chains/graph_qa/cypher.py @@ -311,12 +311,15 @@ def _call( _run_manager = run_manager or CallbackManagerForChainRun.get_noop_manager() callbacks = _run_manager.get_child() question = inputs[self.input_key] + args = { + "question": question, + "schema": self.graph_schema, + } + args.update(inputs) intermediate_steps: List = [] - generated_cypher = self.cypher_generation_chain.run( - {"question": question, "schema": self.graph_schema}, callbacks=callbacks - ) + generated_cypher = self.cypher_generation_chain.run(args, callbacks=callbacks) # Extract Cypher code if it is wrapped in backticks generated_cypher = extract_cypher(generated_cypher)