From 2c6da1636c8c7877c51699370fb9e122088abf75 Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Thu, 7 Dec 2023 21:54:44 -0800 Subject: [PATCH 1/2] fix imports from core --- libs/langchain/langchain/agents/__init__.py | 6 +++++- .../langchain/agents/agent_toolkits/csv/__init__.py | 6 ++++-- .../langchain/agents/agent_toolkits/pandas/__init__.py | 6 ++++-- .../langchain/agents/agent_toolkits/python/__init__.py | 6 ++++-- .../langchain/agents/agent_toolkits/spark/__init__.py | 6 ++++-- .../langchain/agents/agent_toolkits/xorbits/__init__.py | 6 ++++-- 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/libs/langchain/langchain/agents/__init__.py b/libs/langchain/langchain/agents/__init__.py index 5af4b9ed7c78e..4925a913ba533 100644 --- a/libs/langchain/langchain/agents/__init__.py +++ b/libs/langchain/langchain/agents/__init__.py @@ -82,7 +82,11 @@ def __getattr__(name: str) -> Any: """Get attr name.""" if name in DEPRECATED_CODE: - relative_path = as_import_path(Path(__file__).parent, suffix=name) + # Get directory of langchain package + HERE = Path(__file__).parents[1] + relative_path = as_import_path( + Path(__file__).parent, suffix=name, relative_to=HERE + ) old_path = "langchain." + relative_path new_path = "langchain_experimental." + relative_path raise ImportError( diff --git a/libs/langchain/langchain/agents/agent_toolkits/csv/__init__.py b/libs/langchain/langchain/agents/agent_toolkits/csv/__init__.py index 1b4899a2d572a..e5b187c1a6ea0 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/csv/__init__.py +++ b/libs/langchain/langchain/agents/agent_toolkits/csv/__init__.py @@ -7,11 +7,13 @@ def __getattr__(name: str) -> Any: """Get attr name.""" - here = as_import_path(Path(__file__).parent) + # Get directory of langchain package + HERE = Path(__file__).parents[3] + here = as_import_path(Path(__file__).parent, relative_to=HERE) old_path = "langchain." + here + "." + name new_path = "langchain_experimental." + here + "." + name - raise AttributeError( + 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. " diff --git a/libs/langchain/langchain/agents/agent_toolkits/pandas/__init__.py b/libs/langchain/langchain/agents/agent_toolkits/pandas/__init__.py index 1b4899a2d572a..e5b187c1a6ea0 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/pandas/__init__.py +++ b/libs/langchain/langchain/agents/agent_toolkits/pandas/__init__.py @@ -7,11 +7,13 @@ def __getattr__(name: str) -> Any: """Get attr name.""" - here = as_import_path(Path(__file__).parent) + # Get directory of langchain package + HERE = Path(__file__).parents[3] + here = as_import_path(Path(__file__).parent, relative_to=HERE) old_path = "langchain." + here + "." + name new_path = "langchain_experimental." + here + "." + name - raise AttributeError( + 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. " diff --git a/libs/langchain/langchain/agents/agent_toolkits/python/__init__.py b/libs/langchain/langchain/agents/agent_toolkits/python/__init__.py index 1b4899a2d572a..e5b187c1a6ea0 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/python/__init__.py +++ b/libs/langchain/langchain/agents/agent_toolkits/python/__init__.py @@ -7,11 +7,13 @@ def __getattr__(name: str) -> Any: """Get attr name.""" - here = as_import_path(Path(__file__).parent) + # Get directory of langchain package + HERE = Path(__file__).parents[3] + here = as_import_path(Path(__file__).parent, relative_to=HERE) old_path = "langchain." + here + "." + name new_path = "langchain_experimental." + here + "." + name - raise AttributeError( + 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. " diff --git a/libs/langchain/langchain/agents/agent_toolkits/spark/__init__.py b/libs/langchain/langchain/agents/agent_toolkits/spark/__init__.py index 1b4899a2d572a..e5b187c1a6ea0 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/spark/__init__.py +++ b/libs/langchain/langchain/agents/agent_toolkits/spark/__init__.py @@ -7,11 +7,13 @@ def __getattr__(name: str) -> Any: """Get attr name.""" - here = as_import_path(Path(__file__).parent) + # Get directory of langchain package + HERE = Path(__file__).parents[3] + here = as_import_path(Path(__file__).parent, relative_to=HERE) old_path = "langchain." + here + "." + name new_path = "langchain_experimental." + here + "." + name - raise AttributeError( + 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. " diff --git a/libs/langchain/langchain/agents/agent_toolkits/xorbits/__init__.py b/libs/langchain/langchain/agents/agent_toolkits/xorbits/__init__.py index 1b4899a2d572a..e5b187c1a6ea0 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/xorbits/__init__.py +++ b/libs/langchain/langchain/agents/agent_toolkits/xorbits/__init__.py @@ -7,11 +7,13 @@ def __getattr__(name: str) -> Any: """Get attr name.""" - here = as_import_path(Path(__file__).parent) + # Get directory of langchain package + HERE = Path(__file__).parents[3] + here = as_import_path(Path(__file__).parent, relative_to=HERE) old_path = "langchain." + here + "." + name new_path = "langchain_experimental." + here + "." + name - raise AttributeError( + 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. " From 69182e2affeada82d89154b3d1a084524b9df401 Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Thu, 7 Dec 2023 22:20:12 -0800 Subject: [PATCH 2/2] cr --- .../agents/agent_toolkits/csv/__init__.py | 30 ++++++++++--------- .../agents/agent_toolkits/pandas/__init__.py | 30 ++++++++++--------- .../agents/agent_toolkits/python/__init__.py | 30 ++++++++++--------- .../agents/agent_toolkits/spark/__init__.py | 30 ++++++++++--------- .../agents/agent_toolkits/xorbits/__init__.py | 30 ++++++++++--------- 5 files changed, 80 insertions(+), 70 deletions(-) diff --git a/libs/langchain/langchain/agents/agent_toolkits/csv/__init__.py b/libs/langchain/langchain/agents/agent_toolkits/csv/__init__.py index e5b187c1a6ea0..4b049802888ea 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/csv/__init__.py +++ b/libs/langchain/langchain/agents/agent_toolkits/csv/__init__.py @@ -7,18 +7,20 @@ def __getattr__(name: str) -> Any: """Get attr name.""" - # Get directory of langchain package - HERE = Path(__file__).parents[3] - here = as_import_path(Path(__file__).parent, relative_to=HERE) + if name == "create_csv_agent": + # Get directory of langchain package + HERE = Path(__file__).parents[3] + here = as_import_path(Path(__file__).parent, relative_to=HERE) - 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}`." - ) + 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}`." + ) + raise AttributeError(f"{name} does not exist") diff --git a/libs/langchain/langchain/agents/agent_toolkits/pandas/__init__.py b/libs/langchain/langchain/agents/agent_toolkits/pandas/__init__.py index e5b187c1a6ea0..a5cc6fc6664fb 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/pandas/__init__.py +++ b/libs/langchain/langchain/agents/agent_toolkits/pandas/__init__.py @@ -7,18 +7,20 @@ def __getattr__(name: str) -> Any: """Get attr name.""" - # Get directory of langchain package - HERE = Path(__file__).parents[3] - here = as_import_path(Path(__file__).parent, relative_to=HERE) + if name == "create_pandas_dataframe_agent": + # Get directory of langchain package + HERE = Path(__file__).parents[3] + here = as_import_path(Path(__file__).parent, relative_to=HERE) - 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}`." - ) + 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}`." + ) + raise AttributeError(f"{name} does not exist") diff --git a/libs/langchain/langchain/agents/agent_toolkits/python/__init__.py b/libs/langchain/langchain/agents/agent_toolkits/python/__init__.py index e5b187c1a6ea0..85d36eeb49221 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/python/__init__.py +++ b/libs/langchain/langchain/agents/agent_toolkits/python/__init__.py @@ -7,18 +7,20 @@ def __getattr__(name: str) -> Any: """Get attr name.""" - # Get directory of langchain package - HERE = Path(__file__).parents[3] - here = as_import_path(Path(__file__).parent, relative_to=HERE) + if name == "create_python_agent": + # Get directory of langchain package + HERE = Path(__file__).parents[3] + here = as_import_path(Path(__file__).parent, relative_to=HERE) - 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}`." - ) + 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}`." + ) + raise AttributeError(f"{name} does not exist") diff --git a/libs/langchain/langchain/agents/agent_toolkits/spark/__init__.py b/libs/langchain/langchain/agents/agent_toolkits/spark/__init__.py index e5b187c1a6ea0..73ec5b97dee85 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/spark/__init__.py +++ b/libs/langchain/langchain/agents/agent_toolkits/spark/__init__.py @@ -7,18 +7,20 @@ def __getattr__(name: str) -> Any: """Get attr name.""" - # Get directory of langchain package - HERE = Path(__file__).parents[3] - here = as_import_path(Path(__file__).parent, relative_to=HERE) + if name == "create_spark_dataframe_agent": + # Get directory of langchain package + HERE = Path(__file__).parents[3] + here = as_import_path(Path(__file__).parent, relative_to=HERE) - 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}`." - ) + 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}`." + ) + raise AttributeError(f"{name} does not exist") diff --git a/libs/langchain/langchain/agents/agent_toolkits/xorbits/__init__.py b/libs/langchain/langchain/agents/agent_toolkits/xorbits/__init__.py index e5b187c1a6ea0..fd8fc13ba0da8 100644 --- a/libs/langchain/langchain/agents/agent_toolkits/xorbits/__init__.py +++ b/libs/langchain/langchain/agents/agent_toolkits/xorbits/__init__.py @@ -7,18 +7,20 @@ def __getattr__(name: str) -> Any: """Get attr name.""" - # Get directory of langchain package - HERE = Path(__file__).parents[3] - here = as_import_path(Path(__file__).parent, relative_to=HERE) + if name == "create_xorbits_agent": + # Get directory of langchain package + HERE = Path(__file__).parents[3] + here = as_import_path(Path(__file__).parent, relative_to=HERE) - 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}`." - ) + 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}`." + ) + raise AttributeError(f"{name} does not exist")