-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql_agent.py
More file actions
57 lines (43 loc) · 1.34 KB
/
sql_agent.py
File metadata and controls
57 lines (43 loc) · 1.34 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_community.utilities import SQLDatabase
from langchain_community.agent_toolkits import create_sql_agent
# Load database
db = SQLDatabase.from_uri("sqlite:///chinook.db")
# Gemini model
llm = ChatGoogleGenerativeAI(
model="gemini-2.5-flash",
temperature=0
)
# Create SQL Agent
agent_executor = create_sql_agent(
llm=llm,
db=db,
verbose=True
)
# Chat loop
while True:
question = input("\nAsk a database question (type 'exit'): ")
if question.lower() == "exit":
break
response = agent_executor.invoke({"input": question})
print("\nAnswer:", response["output"])
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_community.utilities import SQLDatabase
from langchain_community.agent_toolkits import create_sql_agent
"""
Sample Questions to Test the Agent
Basic:
- List all tables in the database
- How many albums are there?
- How many artists exist?
Intermediate:
- Which artist has the most albums?
- Which genre has the most tracks?
- Show the first 10 tracks
- Which country has the most customers?
Analytics:
- Top 5 customers by spending
- Which artist generated the most revenue?
- Which album has the most songs?
- What is the longest track in the database?
"""