Skip to content

Commit

Permalink
Add keyword to _get_chart_code
Browse files Browse the repository at this point in the history
  • Loading branch information
maxschulz-COL committed Jan 9, 2024
1 parent 26b610b commit 44ad36e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 7 additions & 3 deletions vizro-ai/docs/pages/user_guides/run_vizro_ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ Vizro-AI's `_get_chart_code` method returns the Python code string that can be u
```py
import vizro.plotly.express as px
from vizro_ai import VizroAI

vizro_ai = VizroAI()

df = px.data.gapminder()
code_string = vizro_ai._get_chart_code(df, "describe life expectancy per continent over time", explain=True)
output = vizro_ai._get_chart_code(df, "describe life expectancy per continent over time", explain=True)

code_string = output.get("code_string")
code_explanation = output.get("code_explanation")
business_insights = output.get("business_insights")
```
=== "code_string"
[![ResultCode]][ResultCode]
Expand Down
5 changes: 3 additions & 2 deletions vizro-ai/src/vizro_ai/_vizro_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,18 @@ def _run_plot_tasks(
"code_string": code_string,
}

def _get_chart_code(self, df: pd.DataFrame, user_input: str) -> str:
def _get_chart_code(self, df: pd.DataFrame, user_input: str, explain: bool = False) -> str:
"""Get Chart code of vizro via english descriptions, English to chart translation.
Can be used in integration with other application if only code snippet return is required.
Args:
df: The dataframe to be analyzed
user_input: User questions or descriptions of the desired visual
explain: Flag to include explanation in response
"""
# TODO refine and update error handling
return self._run_plot_tasks(df, user_input, explain=False).get("code_string")
return self._run_plot_tasks(df, user_input, explain=explain)

def plot(self, df: pd.DataFrame, user_input: str, explain: bool = False) -> Union[None, Dict[str, Any]]:
"""Plot visuals using vizro via english descriptions, english to chart translation.
Expand Down

0 comments on commit 44ad36e

Please sign in to comment.