Skip to content

Commit

Permalink
Change approach to fix docs instead of adding the keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
maxschulz-COL committed Jan 9, 2024
1 parent 326acb1 commit 2782adf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ Uncomment the section that is right (remove the HTML comment wrapper).
-->

### Changed

- Change return of `_get_chart_code` from returning code string only to return dictionary with keys `code_string`, `code_explanation` and `business_insights` ([#256](https://github.com/mckinsey/vizro/pull/256))

<!--
### Deprecated
Expand All @@ -36,7 +32,7 @@ Uncomment the section that is right (remove the HTML comment wrapper).

### Fixed

- Add keyword `explain` to `_get_chart_code` function ([#256](https://github.com/mckinsey/vizro/pull/256))
- Remove the keyword `explain` from docs example explaining the `_get_chart_code` function ([#256](https://github.com/mckinsey/vizro/pull/256))

<!--
### Security
Expand Down
9 changes: 3 additions & 6 deletions vizro-ai/docs/pages/user_guides/run_vizro_ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ You can utilize Vizro-AI in any standard development environment by creating a `

You have the possibility to integrate Vizro-AI into your application. For example, this can be achieved through a frontend that allows users to input prompts using a text field.

Vizro-AI's `_get_chart_code` method returns a dictionary containing the Python code string that can be used to prepare the data and create the visualization. It also contains the code explanation and business insights. The code is validated and debugged to ensure that it is executable and ready to be integrated.
Vizro-AI's `_get_chart_code` method returns the Python code string that can be used to prepare the data and create the visualization. This code is validated and debugged to ensure that it is executable and ready to be integrated.

!!! example "Application integration"
=== "app.py"
Expand All @@ -71,15 +71,12 @@ Vizro-AI's `_get_chart_code` method returns a dictionary containing the Python c
vizro_ai = VizroAI()

df = px.data.gapminder()
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 = vizro_ai._get_chart_code(df, "describe life expectancy per continent over time")
```
=== "code_string"
[![ResultCode]][ResultCode]

[ResultCode]: ../../assets/user_guides/code_string_app_integration.png

The returned `code_string` can be used to dynamically render charts within your application. You may have the option to encapsulate the chart within a `fig` object or convert the figure into a JSON string for further integration.
In case you would like to use the insights or code explanation, you can use `vizro_ai._run_plot_tasks(df, ..., explain=False)`, which returns a dictionary containing the code explanation and chart insights alongside the code.
4 changes: 2 additions & 2 deletions vizro-ai/src/vizro_ai/_vizro_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _run_plot_tasks(
"code_string": code_string,
}

def _get_chart_code(self, df: pd.DataFrame, user_input: str, explain: bool = False) -> str:
def _get_chart_code(self, df: pd.DataFrame, user_input: str) -> 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.
Expand All @@ -102,7 +102,7 @@ def _get_chart_code(self, df: pd.DataFrame, user_input: str, explain: bool = Fal
explain: Flag to include explanation in response
"""
# TODO refine and update error handling
return self._run_plot_tasks(df, user_input, explain=explain)
return self._run_plot_tasks(df, user_input, explain=False).get("code_string")

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 2782adf

Please sign in to comment.