-
Couldn't load subscription status.
- 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
Open
matteocacciola
wants to merge
19
commits into
sinaptik-ai:main
Choose a base branch
from
matteocacciola:template_improvements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
853aee1
improving the template to avoid generation of code with unsupported t…
matteocacciola a5d6a46
minor change
matteocacciola 21e5e9d
adding plotly
matteocacciola 95149a9
improving the code generation template in case of plotly
matteocacciola 92a815e
improving the code generation template in case of plotly
matteocacciola a674c86
validation into the InteractiveChartResponse
matteocacciola ccb9e9a
tests
matteocacciola a8a5e77
removing misleading template
matteocacciola a342d17
including plotly.graph_objects in environments
matteocacciola 0f61de5
cleaning the eventual creation of dirs
matteocacciola 8464b87
linting
matteocacciola 7073946
Merge branch 'main' into template_improvements
matteocacciola 8ccec5c
Merge branch 'sinaptik-ai:main' into template_improvements
matteocacciola b8d05fa
Merge branch 'sinaptik-ai:main' into template_improvements
matteocacciola d2eaef4
fixes
matteocacciola 94b272a
Merge branch 'main' into template_improvements
matteocacciola a982919
poetry.lock
matteocacciola 3589509
Merge branch 'main' into template_improvements
matteocacciola a368e04
lock file
matteocacciola File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import json | ||
| import os | ||
| from typing import Any | ||
|
|
||
| from .base import BaseResponse | ||
|
|
||
|
|
||
| class InteractiveChartResponse(BaseResponse): | ||
| def __init__(self, value: Any, last_code_executed: str): | ||
| super().__init__(value, "ichart", last_code_executed) | ||
|
|
||
| self._validate() | ||
|
|
||
| def _get_chart(self) -> dict: | ||
| if isinstance(self.value, dict): | ||
| return self.value | ||
|
|
||
| if isinstance(self.value, str): | ||
| if os.path.exists(self.value): | ||
| with open(self.value, "rb") as f: | ||
| return json.load(f) | ||
|
|
||
| return json.loads(self.value) | ||
|
|
||
| raise ValueError( | ||
| "Invalid value type for InteractiveChartResponse. Expected dict or str." | ||
| ) | ||
|
|
||
| def save(self, path: str): | ||
| img = self._get_chart() | ||
| with open(path, "w") as f: | ||
| json.dump(img, f) | ||
|
|
||
| def __str__(self) -> str: | ||
| return self.value if isinstance(self.value, str) else json.dumps(self.value) | ||
|
|
||
| def get_dict_image(self) -> dict: | ||
| return self._get_chart() | ||
|
|
||
| def _validate(self): | ||
| if not isinstance(self.value, (dict, str)): | ||
| raise ValueError( | ||
| "InteractiveChartResponse value must be a dict or a str representing a file path." | ||
| ) | ||
|
|
||
| # if a string, it can be a path to a file or a JSON string | ||
| if isinstance(self.value, str): | ||
| try: | ||
| json.loads(self.value) # Check if it's a valid JSON string | ||
| except json.JSONDecodeError: | ||
| # If it fails, check if it's a valid file path | ||
| if not os.path.exists(self.value): | ||
| raise ValueError( | ||
| "InteractiveChartResponse value must be a valid file path or a JSON string." | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.