vanna-ai / vanna

šŸ¤– Chat with your SQL database šŸ“Š. Accurate Text-to-SQL Generation via LLMs using RAG šŸ”„.
https://vanna.ai/docs/
MIT License
9.97k stars 737 forks source link

Flask: chart still generated if chart=False #355

Open Molrn opened 3 months ago

Molrn commented 3 months ago

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('my-email@example.com'))
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:
image

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

Uzda20 commented 1 month ago

seems like issue is solved in latest release [0.5.5]