Refactor SQLGeneratorComponent class to handle prompts without {question} variable
This commit is contained in:
parent
3d645ee41d
commit
0111c62c4e
1 changed files with 4 additions and 13 deletions
|
|
@ -43,19 +43,10 @@ class SQLGeneratorComponent(CustomComponent):
|
|||
else:
|
||||
template = prompt.template if hasattr(prompt, "template") else prompt
|
||||
# Check if {question} is in the prompt
|
||||
if (
|
||||
"{question}" not in template
|
||||
or "question" not in template.input_variables
|
||||
):
|
||||
raise ValueError(
|
||||
"Prompt must contain `{question}` to be used with Natural Language to SQL."
|
||||
)
|
||||
sql_query_chain = create_sql_query_chain(
|
||||
llm=llm, db=db, prompt=prompt, **kwargs
|
||||
)
|
||||
query_writer = sql_query_chain | {
|
||||
"query": lambda x: x.replace("SQLQuery:", "").strip()
|
||||
}
|
||||
if "{question}" not in template or "question" not in template.input_variables:
|
||||
raise ValueError("Prompt must contain `{question}` to be used with Natural Language to SQL.")
|
||||
sql_query_chain = create_sql_query_chain(llm=llm, db=db, prompt=prompt, **kwargs)
|
||||
query_writer = sql_query_chain | {"query": lambda x: x.replace("SQLQuery:", "").strip()}
|
||||
response = query_writer.invoke({"question": inputs})
|
||||
query = response.get("query")
|
||||
self.status = query
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue