Skip to content

Instantly share code, notes, and snippets.

@samirsaci
Created November 14, 2023 08:46
Show Gist options
  • Save samirsaci/cbfb256787d486fc8fdf0f892abd47a3 to your computer and use it in GitHub Desktop.
Save samirsaci/cbfb256787d486fc8fdf0f892abd47a3 to your computer and use it in GitHub Desktop.
LangChain SQL - Template
# Create the prompt template
template = PromptTemplate(
input_variables=["input_question", "context_explanation"],
template="""{context_explanation}
Question: {input_question}
"""
)
# Agent
agent_executor = create_sql_agent(
llm=llm,
toolkit=toolkit,
verbose=True,
handle_parsing_errors=True,
agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
return_intermediate_steps=True,
)
try:
print("Question: ", template.format(context_explanation = context_explanation, input_question = input_question))
result = agent_executor.run(template.format(context_explanation = context_explanation, input_question = input_question))
print("Result: ", result)
except Exception as e:
print(f"An error occurred: {e}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment