-
Notifications
You must be signed in to change notification settings - Fork 80
/
vanna_calls.py
58 lines (44 loc) · 1.84 KB
/
vanna_calls.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
58
import streamlit as st
from vanna.remote import VannaDefault
@st.cache_resource(ttl=3600)
def setup_vanna():
vn = VannaDefault(api_key=st.secrets.get("VANNA_API_KEY"), model='chinook')
vn.connect_to_sqlite("https://vanna.ai/Chinook.sqlite")
return vn
@st.cache_data(show_spinner="Generating sample questions ...")
def generate_questions_cached():
vn = setup_vanna()
return vn.generate_questions()
@st.cache_data(show_spinner="Generating SQL query ...")
def generate_sql_cached(question: str):
vn = setup_vanna()
return vn.generate_sql(question=question, allow_llm_to_see_data=True)
@st.cache_data(show_spinner="Checking for valid SQL ...")
def is_sql_valid_cached(sql: str):
vn = setup_vanna()
return vn.is_sql_valid(sql=sql)
@st.cache_data(show_spinner="Running SQL query ...")
def run_sql_cached(sql: str):
vn = setup_vanna()
return vn.run_sql(sql=sql)
@st.cache_data(show_spinner="Checking if we should generate a chart ...")
def should_generate_chart_cached(question, sql, df):
vn = setup_vanna()
return vn.should_generate_chart(df=df)
@st.cache_data(show_spinner="Generating Plotly code ...")
def generate_plotly_code_cached(question, sql, df):
vn = setup_vanna()
code = vn.generate_plotly_code(question=question, sql=sql, df=df)
return code
@st.cache_data(show_spinner="Running Plotly code ...")
def generate_plot_cached(code, df):
vn = setup_vanna()
return vn.get_plotly_figure(plotly_code=code, df=df)
@st.cache_data(show_spinner="Generating followup questions ...")
def generate_followup_cached(question, sql, df):
vn = setup_vanna()
return vn.generate_followup_questions(question=question, sql=sql, df=df)
@st.cache_data(show_spinner="Generating summary ...")
def generate_summary_cached(question, df):
vn = setup_vanna()
return vn.generate_summary(question=question, df=df)