diff --git a/langchain/agents/load_tools.py b/langchain/agents/load_tools.py index 28e037636b5..6a265f8811b 100644 --- a/langchain/agents/load_tools.py +++ b/langchain/agents/load_tools.py @@ -12,10 +12,10 @@ from langchain.python import PythonREPL from langchain.requests import RequestsWrapper from langchain.serpapi import SerpAPIWrapper from langchain.utilities.bash import BashProcess -from langchain.utilities.wsl import WSLProcess -from langchain.utilities.powershell import PowerShellProcess from langchain.utilities.google_search import GoogleSearchAPIWrapper +from langchain.utilities.powershell import PowerShellProcess from langchain.utilities.wolfram_alpha import WolframAlphaAPIWrapper +from langchain.utilities.wsl import WSLProcess def _get_python_repl() -> Tool: @@ -40,14 +40,16 @@ def _get_terminal() -> Tool: BashProcess().run, "Executes commands in a terminal. Input should be valid commands, and the output will be any output from running that command.", ) - + + def _get_wsl() -> Tool: return Tool( "WSL", WSLProcess().run, "Executes bash commands in a linux system running on Windows Subsystem for Linux (WSL). Input should be valid bash commands, and the output will be any output from running that command.", ) - + + def _get_powershell() -> Tool: return Tool( "PowerShell", @@ -55,6 +57,7 @@ def _get_powershell() -> Tool: "Executes commands in PowerShell. Input should be valid commands, and the output will be any output from running that command.", ) + _BASE_TOOLS = { "python_repl": _get_python_repl, "requests": _get_requests, diff --git a/langchain/utilities/powershell.py b/langchain/utilities/powershell.py index e54b8fc2821..fffab910044 100644 --- a/langchain/utilities/powershell.py +++ b/langchain/utilities/powershell.py @@ -15,10 +15,12 @@ class PowerShellProcess: if isinstance(commands, str): commands = [commands] commands = ";".join(commands) - + try: - output = subprocess.check_output(["powershell.exe", "-Command", commands]).decode() - + output = subprocess.check_output( + ["powershell.exe", "-Command", commands] + ).decode() + except subprocess.CalledProcessError as error: return str(error) if self.strip_newlines: diff --git a/langchain/utilities/wsl.py b/langchain/utilities/wsl.py index 660a29116d8..62456a28c84 100644 --- a/langchain/utilities/wsl.py +++ b/langchain/utilities/wsl.py @@ -15,10 +15,10 @@ class WSLProcess: if isinstance(commands, str): commands = [commands] commands = ";".join(commands) - commands = 'wsl.exe ' + commands + commands = "wsl.exe " + commands try: output = subprocess.check_output(commands, shell=True).decode() - + except subprocess.CalledProcessError as error: return str(error) if self.strip_newlines: