forked from Sinaptik-AI/pandas-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
from_sql.py
54 lines (49 loc) · 1.44 KB
/
from_sql.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Example of using PandasAI with a CSV file."""
from pandasai import Agent
from pandasai.connectors import MySQLConnector, PostgreSQLConnector, SqliteConnector
from pandasai.llm import OpenAI
# With a MySQL database
loan_connector = MySQLConnector(
config={
"host": "localhost",
"port": 3306,
"database": "mydb",
"username": "root",
"password": "root",
"table": "loans",
"where": [
# this is optional and filters the data to
# reduce the size of the dataframe
["loan_status", "=", "PAIDOFF"],
],
}
)
# With a PostgreSQL database
payment_connector = PostgreSQLConnector(
config={
"host": "localhost",
"port": 5432,
"database": "mydb",
"username": "root",
"password": "root",
"table": "payments",
"where": [
# this is optional and filters the data to
# reduce the size of the dataframe
["payment_status", "=", "PAIDOFF"],
],
}
)
# With a Sqlite database
invoice_connector = SqliteConnector(
config={
"database": "local_path_to_db",
"table": "invoices",
"where": [["status", "=", "pending"]],
}
)
llm = OpenAI()
df = Agent([loan_connector, payment_connector, invoice_connector], config={"llm": llm})
response = df.chat("How many people from the United states?")
print(response)
# Output: 247 loans have been paid off by men.