mirror of
https://github.com/hwchase17/langchain
synced 2024-11-08 07:10:35 +00:00
Fix bug in SPARQL intent selection (#8521)
- Description: Fix bug in SPARQL intent selection - Issue: After the change in #7758 the intent is always set to "UPDATE". Indeed, if the answer to the prompt contains only "SELECT" the `find("SELECT")` operation returns a higher value w.r.t. `-1` returned by `find("UPDATE")`. - Dependencies: None, - Tag maintainer: @baskaryan @aditya-29 - Twitter handle: @mario_scrock
This commit is contained in:
parent
7fe8bf03a0
commit
334bd8ebbe
@ -84,17 +84,17 @@ class GraphSparqlQAChain(Chain):
|
|||||||
_intent = self.sparql_intent_chain.run({"prompt": prompt}, callbacks=callbacks)
|
_intent = self.sparql_intent_chain.run({"prompt": prompt}, callbacks=callbacks)
|
||||||
intent = _intent.strip()
|
intent = _intent.strip()
|
||||||
|
|
||||||
if "SELECT" not in intent and "UPDATE" not in intent:
|
if "SELECT" in intent and "UPDATE" not in intent:
|
||||||
|
sparql_generation_chain = self.sparql_generation_select_chain
|
||||||
|
intent = "SELECT"
|
||||||
|
elif "UPDATE" in intent and "SELECT" not in intent:
|
||||||
|
sparql_generation_chain = self.sparql_generation_update_chain
|
||||||
|
intent = "UPDATE"
|
||||||
|
else:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"I am sorry, but this prompt seems to fit none of the currently "
|
"I am sorry, but this prompt seems to fit none of the currently "
|
||||||
"supported SPARQL query types, i.e., SELECT and UPDATE."
|
"supported SPARQL query types, i.e., SELECT and UPDATE."
|
||||||
)
|
)
|
||||||
elif intent.find("SELECT") < intent.find("UPDATE"):
|
|
||||||
sparql_generation_chain = self.sparql_generation_select_chain
|
|
||||||
intent = "SELECT"
|
|
||||||
else:
|
|
||||||
sparql_generation_chain = self.sparql_generation_update_chain
|
|
||||||
intent = "UPDATE"
|
|
||||||
|
|
||||||
_run_manager.on_text("Identified intent:", end="\n", verbose=self.verbose)
|
_run_manager.on_text("Identified intent:", end="\n", verbose=self.verbose)
|
||||||
_run_manager.on_text(intent, color="green", end="\n", verbose=self.verbose)
|
_run_manager.on_text(intent, color="green", end="\n", verbose=self.verbose)
|
||||||
|
Loading…
Reference in New Issue
Block a user