Skip to content

Commit

Permalink
Fix/improve ai error message (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxschulz-COL authored Nov 13, 2023
1 parent e796427 commit ae1017b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
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))
-->
<!--
### 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))
-->
12 changes: 7 additions & 5 deletions vizro-ai/src/vizro_ai/_vizro_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
logger = logging.getLogger(__name__)


class DebugFailure(Exception):
pass


class VizroAI:
"""Vizro-AI main class."""

Expand Down Expand Up @@ -113,12 +117,10 @@ def plot(self, df: pd.DataFrame, user_input: str, explain: bool = False) -> Unio
code_explanation = output_dict.get("code_explanation")

if code_string.startswith("Failed to debug code"):
logger.warning(
"Chart creation failed. Retry debugging has reached maximum limit, fallout response is \
provided. "
+ code_string
raise DebugFailure(
"Chart creation failed. Retry debugging has reached maximum limit. Try to rephrase the prompt, "
"or try to select a different model. Fallout response is provided: \n\n" + code_string
)
return
if not explain:
_exec_code(code=code_string, local_args={"df": df}, show_fig=True, is_notebook_env=_is_jupyter())
if explain:
Expand Down

0 comments on commit ae1017b

Please sign in to comment.