-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Template improvements and interactive charts #1807
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
base: main
Are you sure you want to change the base?
Template improvements and interactive charts #1807
Conversation
instructing the template with the opportunity to use plotly
# Conflicts: # poetry.lock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for interactive charts using Plotly alongside existing matplotlib chart functionality. The changes introduce a new "iplot" output type for Plotly charts, add necessary dependencies, and update templates and prompts to handle the new chart type.
- Adds InteractiveChartResponse class for handling Plotly chart data
- Integrates Plotly dependencies (plotly.express as "px" and plotly.graph_objects as "go")
- Updates response parsing to support "iplot" type for interactive charts
Reviewed Changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
tests/unit_tests/response/test_interactive_chart_response.py | Comprehensive test suite for the new InteractiveChartResponse class |
tests/unit_tests/prompts/test_sql_prompt.py | Updates prompt tests to include "iplot" type and fixes typo |
tests/unit_tests/helpers/test_responses.py | Adds tests for interactive plot parsing and validation |
tests/unit_tests/helpers/test_optional_dependency.py | Adds assertion for "px" dependency in environment |
tests/unit_tests/core/code_generation/test_code_cleaning.py | Tests for JSON chart file handling and directory creation removal |
tests/unit_tests/core/code_execution/test_environment.py | Adds assertion for "px" dependency in environment tests |
pyproject.toml | Adds plotly dependency to project requirements |
pandasai/core/response/parser.py | Updates response parser to handle "iplot" type |
pandasai/core/response/interactive_chart.py | New InteractiveChartResponse class implementation |
pandasai/core/response/init.py | Exports the new InteractiveChartResponse class |
pandasai/core/prompts/templates/shared/output_type_template.tmpl | Updates template to include "iplot" type with typo fix |
pandasai/core/prompts/templates/generate_python_code_with_sql.tmpl | Fixes typo in SQL template |
pandasai/core/code_generation/code_cleaning.py | Adds JSON chart handling and directory creation removal |
pandasai/core/code_execution/environment.py | Adds Plotly dependencies to execution environment |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
pandasai/core/prompts/templates/shared/output_type_template.tmpl
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caution
Changes requested ❌
Reviewed everything up to b8d05fa in 2 minutes and 33 seconds. Click for details.
- Reviewed
522
lines of code in14
files - Skipped
1
files when reviewing. - Skipped posting
5
draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. pandasai/core/response/interactive_chart.py:19
- Draft comment:
Opening the file in binary mode ('rb') for JSON parsing might cause issues since json.load expects a text stream. Consider using 'r' or wrapping the binary stream with a text decoder. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50% While technically both "r" and "rb" modes can work with json.load(), using text mode "r" is more conventional and clearer for JSON files since they are text-based. However, json.load() can handle both text and binary file objects, as it will decode binary streams automatically. The change isn't strictly necessary for functionality. The comment might be too pedantic since the code would work fine either way. Also, in some cases, binary mode can be preferable for handling different line endings consistently across platforms. While the code works with either mode, using text mode "r" better reflects the nature of JSON files and follows more conventional Python practices. The comment should be deleted as it suggests a change that isn't strictly necessary for functionality and doesn't address any real issues or risks.
2. tests/unit_tests/core/code_generation/test_code_cleaning.py:232
- Draft comment:
Possible formatting issue in the f-string for the default chart directory: the quotes seem mismatched. Consider using consistent quoting, e.g., f"os.makedirs('{DEFAULT_CHART_DIRECTORY}')\nplt.show()\nfig.show()". - Reason this comment was not posted:
Marked as duplicate.
3. pandasai/core/prompts/templates/shared/output_type_template.tmpl:2
- Draft comment:
Typographical error: Consider changing "plotly" si used to "plotly" is used. - Reason this comment was not posted:
Marked as duplicate.
4. tests/unit_tests/core/code_generation/test_code_cleaning.py:236
- Draft comment:
Typo: The f-string in this line also has mismatched quotes: f"os.mkdir({DEFAULT_CHART_DIRECTORY}')\nplt.show()\nfig.show()" It would likely be correct to have it as: f"os.mkdir('{DEFAULT_CHART_DIRECTORY}')\nplt.show()\nfig.show()" - Reason this comment was not posted:
Marked as duplicate.
5. tests/unit_tests/prompts/test_sql_prompt.py:24
- Draft comment:
Typographical error: In the string, "plotly" si used should be "plotly" is used. - Reason this comment was not posted:
Marked as duplicate.
Workflow ID: wflow_eZWWPMVJQlGQWSdd
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
pandasai/core/prompts/templates/shared/output_type_template.tmpl
Outdated
Show resolved
Hide resolved
11749dd
to
d2eaef4
Compare
@matteocacciola Thank you for the PR! We’re not planning to add interactive charts to PandasAI. Feel free to submit a PR to improve the prompt. |
# Conflicts: # poetry.lock
Important
Adds Plotly support for interactive charts, updates templates, and includes tests for new functionality.
get_environment()
inenvironment.py
.plt.show()
andfig.show()
lines inclean_code()
incode_cleaning.py
._replace_output_filenames_with_temp_json_chart()
incode_cleaning.py
._remove_make_dirs()
incode_cleaning.py
.generate_python_code_with_sql.tmpl
andoutput_type_template.tmpl
to include "iplot" type.InteractiveChartResponse
class ininteractive_chart.py
.ResponseParser
inparser.py
to handle "iplot" type.plotly
topyproject.toml
.test_environment.py
.test_code_cleaning.py
.InteractiveChartResponse
intest_interactive_chart_response.py
.test_responses.py
andtest_sql_prompt.py
for new "iplot" type.This description was created by
for b8d05fa. You can customize this summary. It will automatically update as commits are pushed.