forked from Sinaptik-AI/pandas-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
table_relations.py
43 lines (36 loc) · 1.1 KB
/
table_relations.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
from pandasai.agent.base import Agent
from pandasai.connectors.sql import PostgreSQLConnector
from pandasai.ee.connectors.relations import ForeignKey, PrimaryKey
from pandasai.llm.openai import OpenAI
llm = OpenAI("sk-*************")
config_ = {"llm": llm, "direct_sql": True}
payment_connector = PostgreSQLConnector(
config={
"host": "localhost",
"port": 5432,
"database": "testdb",
"username": "postgres",
"password": "*****",
"table": "orders",
},
connector_relations=[
PrimaryKey("id"),
ForeignKey(
field="customer_id", foreign_table="customers", foreign_table_field="id"
),
],
)
customer_connector = PostgreSQLConnector(
config={
"host": "localhost",
"port": 5432,
"database": "mydb",
"username": "root",
"password": "root",
"table": "customers",
},
connector_relations=[PrimaryKey("id")],
)
agent = Agent([payment_connector, customer_connector], config=config_, memory_size=10)
response = agent.chat("return orders count groupby country")
print(response)