Skip to content

Commit

Permalink
Remove LLM Bash and related bash utilities (langchain-ai#11619)
Browse files Browse the repository at this point in the history
Deprecate LLMBash and related bash utilities
  • Loading branch information
eyurtsev authored Oct 10, 2023
1 parent 683f4a9 commit 58220cd
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 619 deletions.
12 changes: 8 additions & 4 deletions libs/langchain/langchain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,15 @@ def __getattr__(name: str) -> Any:

return ConversationChain
elif name == "LLMBashChain":
from langchain.chains import LLMBashChain
raise ImportError(
"This module has been moved to langchain-experimental. "
"For more details: "
"https://github.com/langchain-ai/langchain/discussions/11352."
"To access this code, install it with `pip install langchain-experimental`."
"`from langchain_experimental.llm_bash.base "
"import LLMBashChain`"
)

_warn_on_import(name)

return LLMBashChain
elif name == "LLMChain":
from langchain.chains import LLMChain

Expand Down
2 changes: 0 additions & 2 deletions libs/langchain/langchain/chains/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
from langchain.chains.graph_qa.sparql import GraphSparqlQAChain
from langchain.chains.hyde.base import HypotheticalDocumentEmbedder
from langchain.chains.llm import LLMChain
from langchain.chains.llm_bash.base import LLMBashChain
from langchain.chains.llm_checker.base import LLMCheckerChain
from langchain.chains.llm_math.base import LLMMathChain
from langchain.chains.llm_requests import LLMRequestsChain
Expand Down Expand Up @@ -94,7 +93,6 @@
"HugeGraphQAChain",
"HypotheticalDocumentEmbedder",
"KuzuQAChain",
"LLMBashChain",
"LLMChain",
"LLMCheckerChain",
"LLMMathChain",
Expand Down
13 changes: 12 additions & 1 deletion libs/langchain/langchain/chains/llm_bash/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
"""Chain that interprets a prompt and executes bash code to perform bash operations."""
def raise_on_import() -> None:
"""Raise an error on import since is deprecated."""
raise ImportError(
"This module has been moved to langchain-experimental. "
"For more details: https://github.com/langchain-ai/langchain/discussions/11352."
"To access this code, install it with `pip install langchain-experimental`."
"`from langchain_experimental.llm_bash.base "
"import LLMBashChain`"
)


raise_on_import()
138 changes: 0 additions & 138 deletions libs/langchain/langchain/chains/llm_bash/base.py

This file was deleted.

64 changes: 0 additions & 64 deletions libs/langchain/langchain/chains/llm_bash/prompt.py

This file was deleted.

5 changes: 3 additions & 2 deletions libs/langchain/langchain/chains/loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from langchain.chains.graph_qa.cypher import GraphCypherQAChain
from langchain.chains.hyde.base import HypotheticalDocumentEmbedder
from langchain.chains.llm import LLMChain
from langchain.chains.llm_bash.base import LLMBashChain
from langchain.chains.llm_checker.base import LLMCheckerChain
from langchain.chains.llm_math.base import LLMMathChain
from langchain.chains.llm_requests import LLMRequestsChain
Expand Down Expand Up @@ -183,7 +182,9 @@ def _load_reduce_documents_chain(config: dict, **kwargs: Any) -> ReduceDocuments
)


def _load_llm_bash_chain(config: dict, **kwargs: Any) -> LLMBashChain:
def _load_llm_bash_chain(config: dict, **kwargs: Any) -> Any:
from langchain_experimental.llm_bash.base import LLMBashChain

llm_chain = None
if "llm_chain" in config:
llm_chain_config = config.pop("llm_chain")
Expand Down
17 changes: 12 additions & 5 deletions libs/langchain/langchain/tools/shell/tool.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import asyncio
import platform
import warnings
from typing import List, Optional, Type, Union
from typing import Any, List, Optional, Type, Union

from langchain.callbacks.manager import (
AsyncCallbackManagerForToolRun,
CallbackManagerForToolRun,
)
from langchain.pydantic_v1 import BaseModel, Field, root_validator
from langchain.tools.base import BaseTool
from langchain.utilities.bash import BashProcess


class ShellInput(BaseModel):
Expand All @@ -35,8 +34,16 @@ def _validate_commands(cls, values: dict) -> dict:
return values


def _get_default_bash_processs() -> BashProcess:
"""Get file path from string."""
def _get_default_bash_process() -> Any:
"""Get default bash process."""
try:
from langchain_experimental.llm_bash.bash import BashProcess
except ImportError:
raise ImportError(
"BashProcess has been moved to langchain experimental."
"To use this tool, install langchain-experimental "
"with `pip install langchain-experimental`."
)
return BashProcess(return_err_output=True)


Expand All @@ -51,7 +58,7 @@ def _get_platform() -> str:
class ShellTool(BaseTool):
"""Tool to run shell commands."""

process: BashProcess = Field(default_factory=_get_default_bash_processs)
process: Any = Field(default_factory=_get_default_bash_process)
"""Bash process to run commands."""

name: str = "terminal"
Expand Down
2 changes: 0 additions & 2 deletions libs/langchain/langchain/utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from langchain.utilities.arcee import ArceeWrapper
from langchain.utilities.arxiv import ArxivAPIWrapper
from langchain.utilities.awslambda import LambdaWrapper
from langchain.utilities.bash import BashProcess
from langchain.utilities.bibtex import BibtexparserWrapper
from langchain.utilities.bing_search import BingSearchAPIWrapper
from langchain.utilities.brave_search import BraveSearchWrapper
Expand Down Expand Up @@ -44,7 +43,6 @@
"ApifyWrapper",
"ArceeWrapper",
"ArxivAPIWrapper",
"BashProcess",
"BibtexparserWrapper",
"BingSearchAPIWrapper",
"BraveSearchWrapper",
Expand Down
Loading

0 comments on commit 58220cd

Please sign in to comment.