forked from sinaptik-ai/pandas-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrom_googlebigquery.py
57 lines (44 loc) · 1.46 KB
/
from_googlebigquery.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
55
56
57
import base64
import json
from pandasai import SmartDataframe
# A license might be required for using Snowflake with PandasAI
from pandasai.ee.connectors import GoogleBigQueryConnector
from pandasai.llm import OpenAI
# ENV's
# BIG_QUERY_DATABASE
# KEYFILE_PATH
# PROJECT_ID
# EXAMPLE 1
bigquery_connectors = GoogleBigQueryConnector(
config={
"credentials_path": "/Users/arslan/Downloads/loan-project.json",
"database": "loan_payments",
"table": "loan_payments",
"projectID": "loan-project",
"where": [["Gender", "=", "female"]],
}
)
llm = OpenAI("OPEN-API_KEY")
df = SmartDataframe(bigquery_connectors, config={"llm": llm})
response = df.chat("How many rows are there in data ?")
print(response)
# EXAMPLE 2
# initialize google big query using Base64 string
with open("/Users/arslan/Downloads/loan-project.json", "r") as file:
json_data = json.load(file)
# Convert JSON data to a string
json_string = json.dumps(json_data, indent=2)
encoded_bytes = base64.b64encode(json_string.encode("utf-8"))
bigquery_connectors = GoogleBigQueryConnector(
config={
"credentials_base64": encoded_bytes,
"database": "loan_payments",
"table": "loan_payments",
"projectID": "loan-project",
"where": [["Gender", "=", "female"]],
}
)
llm = OpenAI("OPEN-API_KEY")
df = SmartDataframe(bigquery_connectors, config={"llm": llm})
response = df.chat("How many rows are there in data ?")
print(response)