forked from langchain-ai/langchain
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate PythonRepl tools and Pandas/Xorbits/Spark DataFrame/Python/…
…CSV agents (langchain-ai#12427) See discussion here: langchain-ai#11680 The code is available for usage from langchain_experimental. The reason for the deprecation is that the agents are relying on a Python REPL. The code can only be run safely with appropriate sandboxing. --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
- Loading branch information
1 parent
8352e52
commit b90ab6a
Showing
31 changed files
with
267 additions
and
1,400 deletions.
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.