Skip to content

Commit

Permalink
fix: charts are now displayed again (sinaptik-ai#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
gventuri committed May 8, 2023
1 parent 5f8851a commit 01f84d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pandasai/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@

START_CODE_TAG = "<startCode>"
END_CODE_TAG = "<endCode>"
WHITELISTED_LIBRARIES = [
"numpy",
"matplotlib",
]
7 changes: 5 additions & 2 deletions pandasai/llm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import astor

from ..constants import END_CODE_TAG, START_CODE_TAG
from ..constants import END_CODE_TAG, START_CODE_TAG, WHITELISTED_LIBRARIES
from ..exceptions import (
APIKeyNotFoundError,
MethodNotImplementedError,
Expand Down Expand Up @@ -37,7 +37,10 @@ def _remove_imports(self, code: str) -> str:
new_body = [
node
for node in tree.body
if not isinstance(node, (ast.Import, ast.ImportFrom))
if not (
isinstance(node, (ast.Import, ast.ImportFrom))
and any(alias.name in WHITELISTED_LIBRARIES for alias in node.names)
)
]
new_tree = ast.Module(body=new_body)
return astor.to_source(new_tree).strip()
Expand Down

0 comments on commit 01f84d2

Please sign in to comment.