Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(flask): missing fig_json error #470

Merged
merged 1 commit into from
Jun 7, 2024
Merged

Conversation

Molrn
Copy link
Contributor

@Molrn Molrn commented May 30, 2024

related to #428

Problem

When no graph is generated, retrieving a converstation through the history fails as the cache is expecting a fig_json field.
The following error is displayed:
image

Solution

set fig_json as an optional field instead of a required one for the function VannaFlaskApp.load_question. The conversation is then displayed, followed by an empty graph:
image

Improvements

It would be good to take into account the possibility of fig being null in the JS displaying the graph so that it shows nothing instead of an epty graph, but as it is in the assets I can't modify it.

@AI-Mart
Copy link

AI-Mart commented May 31, 2024

Yes, it makes sense for the front-end not to display anything when fig is empty. How should I adjust this code to solve it? It’s a bit troublesome.”

@Molrn
Copy link
Contributor Author

Molrn commented May 31, 2024

@AI-Mart in the mean time, you can disable all graph generation by overiding the methods responsible for generation:

import pandas as pd
from plotly import Figure

from vanna.remote import VannaDefault


class VannaModel(VannaDefault):

    def generate_plotly_code(
        self, question: str = None, sql: str = None, df_metadata: str = None, **kwargs
    ) -> str:
        return ""

    def get_plotly_figure(
        self, plotly_code: str, df: pd.DataFrame, dark_mode: bool = True
    ) -> Figure:
        return Figure()

    def should_generate_chart(self, df) -> bool:
        return True

@AI-Mart
Copy link

AI-Mart commented May 31, 2024

“If there is no chat history information, then instead of showing a blank image, nothing should be displayed at all. Currently, I have set the parameter ‘chart=False’; however, it seems that when ‘fig’ is empty,chat history information it still shows a blank image instead of nothing.”This seems to be a front-end issue, as the backend interface is no longer generating the image.

@Uzda20
Copy link

Uzda20 commented Jun 5, 2024

Hello, similar error is displayed for df.

obraz

I assume similar approach can be applied for fixing it as for fig_json.

@zainhoda zainhoda merged commit fdcb93d into vanna-ai:main Jun 7, 2024
@Molrn
Copy link
Contributor Author

Molrn commented Jun 7, 2024

@Uzda20 it is the same kind of error (cache issue) but definitely not the same source, and not the same way to fix it, because it is not supposed to not be set. If you want to adress it, please create a new issue with details about how to reproduce this error

@Uzda20
Copy link

Uzda20 commented Jun 7, 2024

@Molrn Thanks, I will try to reproduce it and add issue description as advised.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants