Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Feat/add max debug retry parameter #261

Merged
merged 11 commits into from
Jan 11, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!--
A new scriv changelog fragment.

Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Highlights ✨

- A bullet item for the Highlights ✨ category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Removed

- A bullet item for the Removed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Added

- A bullet item for the Added category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
Anna-Xiong marked this conversation as resolved.
Show resolved Hide resolved
<!--
### Changed

- A bullet item for the Changed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Deprecated

- A bullet item for the Deprecated category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Fixed

- A bullet item for the Fixed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Security

- A bullet item for the Security category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
16 changes: 16 additions & 0 deletions vizro-ai/docs/pages/user_guides/run_vizro_ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,19 @@ Vizro-AI's `_get_chart_code` method returns the Python code string that can be u

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=True)`, which returns a dictionary containing the code explanation and chart insights alongside the code.

### 4. Increase the maximum number of attempts to debug
maxschulz-COL marked this conversation as resolved.
Show resolved Hide resolved
Sometimes there is error in code generated first round since the code is generated by Large Language Models (LLMs),
Anna-Xiong marked this conversation as resolved.
Show resolved Hide resolved

The `max_debug_retry` parameter in the plot function specifies the maximum number of attempts the function will make to debug any errors that occur during its execution.
When an error is encountered, the function will automatically invoke a debugging process. This process involves running the code, capturing any errors that occur, and then using the LLM to analyze and attempt to resolve these errors.
Anna-Xiong marked this conversation as resolved.
Show resolved Hide resolved

By default, the max_debug_retry is set to 3, the function will attempt to debug errors up to three times.
If the errors are not resolved after the maximum number of retries, the function will cease further debugging attempts.
Anna-Xiong marked this conversation as resolved.
Show resolved Hide resolved

if users would like to increase or decrease the maximum number of retries, adding parameter `max_debug_retry` in plot call as below works:
Anna-Xiong marked this conversation as resolved.
Show resolved Hide resolved
!!! example "Change max_debug_retry"
Anna-Xiong marked this conversation as resolved.
Show resolved Hide resolved
=== "Code for the cell"
```py
vizro_ai.plot(df = df, user_input = "your user input", max_debug_retry= 5)
```
7 changes: 5 additions & 2 deletions vizro-ai/src/vizro_ai/_vizro_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,18 @@ def _get_chart_code(self, df: pd.DataFrame, user_input: str) -> str:
# TODO refine and update error handling
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]]:
def plot(
self, df: pd.DataFrame, user_input: str, explain: bool = False, max_debug_retry: int = 3
) -> Union[None, Dict[str, Any]]:
"""Plot visuals using vizro via english descriptions, english to chart translation.

Args:
df: The dataframe to be analyzed
user_input: User questions or descriptions of the desired visual
explain: Flag to include explanation in response
max_debug_retry: Number of times LLM can retry for debug
Anna-Xiong marked this conversation as resolved.
Show resolved Hide resolved
"""
output_dict = self._run_plot_tasks(df, user_input, explain=explain)
output_dict = self._run_plot_tasks(df, user_input, explain=explain, max_debug_retry=max_debug_retry)
code_string = output_dict.get("code_string")
business_insights = output_dict.get("business_insights")
code_explanation = output_dict.get("code_explanation")
Expand Down
Loading