vanna
vanna copied to clipboard
Flask: chart still generated if chart=False
Describe the bug
When the option chart and redraw_chart are set to false, the function generate_plotly_code
of the model is still executed. If the dataset is big, the execution takes a lot of time, so it can be very problematic for users who do not need this step.
To Reproduce
import vanna
from vanna.remote import VannaDefault
from vanna.flask import VannaFlaskApp
class MyModel(VannaDefault):
def generate_plotly_code(
self, question: str = None, sql: str = None, df_metadata: str = None, **kwargs
) -> str:
plotly_code = super().generate_plotly_code(question, sql, df_metadata, **kwargs)
self.log(plotly_code)
return plotly_code
vn = MyModel(model='chinook', api_key=vanna.get_api_key('[email protected]'))
vn.connect_to_sqlite('https://vanna.ai/Chinook.sqlite')
app = VannaFlaskApp(vn, chart=False, redraw_chart=False)
app.run()
Execute this code to run the app, then ask a question in the app. No graph is generated:
But this appears in the logs:
Your app is running at:
http://localhost:8084
* Serving Flask app 'vanna.flask'
* Debug mode: off
import plotly.express as px
if len(df) == 1:
fig = px.indicators.generic.Indicator(
value=df['TotalSales'][0],
title=df['Name'][0]
)
else:
fig = px.bar(df, x='Name', y='TotalSales', title='Top 10 Artists by Sales')
Expected Behavior The function should not be executed. It comes as an important problem when the dataset is large or the LLM access is limited, because the function sends all the dataset to the LLM.
Desktop
- OS: [Ubuntu]
- Version: [22.04]
- Python: [3.10]
- Vanna: [0.3.3]
seems like issue is solved in latest release [0.5.5]