-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
Deprecate PythonRepl tools and Pandas/Xorbits/Spark DataFrame/Python/CSV agents (CVE-2023-39659) #12427
Merged
Merged
Deprecate PythonRepl tools and Pandas/Xorbits/Spark DataFrame/Python/CSV agents (CVE-2023-39659) #12427
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
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 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 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,36 @@ | ||
import os | ||
from pathlib import Path | ||
from typing import Optional, Union | ||
|
||
HERE = Path(__file__).parent | ||
|
||
# Get directory of langchain package | ||
PACKAGE_DIR = HERE.parent | ||
SEPARATOR = os.sep | ||
|
||
|
||
def get_relative_path( | ||
file: Union[Path, str], *, relative_to: Path = PACKAGE_DIR | ||
) -> str: | ||
"""Get the path of the file as a relative path to the package directory.""" | ||
if isinstance(file, str): | ||
file = Path(file) | ||
return str(file.relative_to(relative_to)) | ||
|
||
|
||
def as_import_path( | ||
file: Union[Path, str], | ||
*, | ||
suffix: Optional[str] = None, | ||
relative_to: Path = PACKAGE_DIR | ||
) -> str: | ||
"""Path of the file as a LangChain import exclude langchain top namespace.""" | ||
if isinstance(file, str): | ||
file = Path(file) | ||
path = get_relative_path(file, relative_to=relative_to) | ||
if file.is_file(): | ||
path = path[: -len(file.suffix)] | ||
import_path = path.replace(SEPARATOR, ".") | ||
if suffix: | ||
import_path += "." + suffix | ||
return import_path |
This file contains 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 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
23 changes: 22 additions & 1 deletion
23
libs/langchain/langchain/agents/agent_toolkits/csv/__init__.py
This file contains 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 |
---|---|---|
@@ -1 +1,22 @@ | ||
"""CSV toolkit.""" | ||
from pathlib import Path | ||
from typing import Any | ||
|
||
from langchain._api.path import as_import_path | ||
|
||
|
||
def __getattr__(name: str) -> Any: | ||
"""Get attr name.""" | ||
|
||
here = as_import_path(Path(__file__).parent) | ||
|
||
old_path = "langchain." + here + "." + name | ||
new_path = "langchain_experimental." + here + "." + name | ||
raise ImportError( | ||
"This agent has been moved to langchain experiment. " | ||
"This agent relies on python REPL tool under the hood, so to use it " | ||
"safely please sandbox the python REPL. " | ||
"Read https://github.com/langchain-ai/langchain/blob/master/SECURITY.md " | ||
"and https://github.com/langchain-ai/langchain/discussions/11680" | ||
"To keep using this code as is, install langchain experimental and " | ||
f"update your import statement from:\n `{old_path}` to `{new_path}`." | ||
) |
34 changes: 0 additions & 34 deletions
34
libs/langchain/langchain/agents/agent_toolkits/csv/base.py
This file was deleted.
Oops, something went wrong.
23 changes: 22 additions & 1 deletion
23
libs/langchain/langchain/agents/agent_toolkits/pandas/__init__.py
This file contains 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 |
---|---|---|
@@ -1 +1,22 @@ | ||
"""Pandas toolkit.""" | ||
from pathlib import Path | ||
from typing import Any | ||
|
||
from langchain._api.path import as_import_path | ||
|
||
|
||
def __getattr__(name: str) -> Any: | ||
"""Get attr name.""" | ||
|
||
here = as_import_path(Path(__file__).parent) | ||
|
||
old_path = "langchain." + here + "." + name | ||
new_path = "langchain_experimental." + here + "." + name | ||
raise ImportError( | ||
"This agent has been moved to langchain experiment. " | ||
"This agent relies on python REPL tool under the hood, so to use it " | ||
"safely please sandbox the python REPL. " | ||
"Read https://github.com/langchain-ai/langchain/blob/master/SECURITY.md " | ||
"and https://github.com/langchain-ai/langchain/discussions/11680" | ||
"To keep using this code as is, install langchain experimental and " | ||
f"update your import statement from:\n `{old_path}` to `{new_path}`." | ||
) |
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.
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.
Forgot to do it last time -- this fixes auto-completion in the ipython repl
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.
should we remove LLMMathChain below too
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.
It's still in langchain, what we did was make the underlying dependency optional (and up to the user) and bumped it to a minimum version that contains sanitization