-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjupysqlagent.py
36 lines (33 loc) · 2.67 KB
/
jupysqlagent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from haystack.nodes import AnswerParser, PromptNode, PromptTemplate
from haystack.agents import Agent, Tool
from dotenv import load_dotenv
import os
# Load the .env file
load_dotenv(".env")
# Define the tools that the agent has access to
# The agent has access to the following tools:
sql_agent_prompt = PromptTemplate(
prompt="You are a helpful and knowledgeable agent who has access to an SQL database which has a table called 'bank'"
" that has the following Columns: 'age';'job';'marital';'education';'default';'balance';'housing';'loan';'contact';'day';'month';'duration';'campaign';'pdays';'previous';'poutcome';'y'"
"Your task is to assess whether a query can be resolved with the tools you have at hand, and if yes, generate an SQL query to resolve it."
"The generated SQL query should be stripped down to just the query with no syntax highlighting and no capitalization. If you are creating new column names, they should all be lower case, with no special characters."
"You have access to the following tools:\n\n"
"{tool_names_with_descriptions}\n\n"
"To answer questions, you'll need to go through multiple steps involving step-by-step thinking and "
"selecting appropriate tools and their inputs; tools will respond with observations."
"When you are ready wity an answer, respond with the `Final Answer:`\n\n"
"If the query is unrelated and cannot be answered by any of the tools, your final answer should say 'Cannot be answered with available databases'\n\n"
"Use the following format:\n\n"
"Question: the question to be answered\n"
"Thought: Reason if you have the final answer. If yes, answer the query. If not, continue using the tools to resolve the query.\n"
"Tool: pick one of {tool_names} \n"
"Tool Input: the input for the tool.\n"
"Observation: The full result the tool responds with\n"
"...\n"
"Final Answer: the final answer to the query. This should be the full result of the SQL query that you came up with.\n\n"
"Thought, Tool, Tool Input, and Observation steps can be repeated multiple times, but sometimes we can find an answer in the first pass\n"
"---\n\n"
"Question: {query}\n"
"Thought: Let's think step-by-step, I first need to\n"
"{transcript}",
)