This commit is contained in:
Harrison Chase 2023-02-09 23:50:27 -08:00
parent 46354d4f64
commit 450be8d15f
3 changed files with 14 additions and 9 deletions

View File

@ -12,10 +12,10 @@ from langchain.python import PythonREPL
from langchain.requests import RequestsWrapper from langchain.requests import RequestsWrapper
from langchain.serpapi import SerpAPIWrapper from langchain.serpapi import SerpAPIWrapper
from langchain.utilities.bash import BashProcess 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.google_search import GoogleSearchAPIWrapper
from langchain.utilities.powershell import PowerShellProcess
from langchain.utilities.wolfram_alpha import WolframAlphaAPIWrapper from langchain.utilities.wolfram_alpha import WolframAlphaAPIWrapper
from langchain.utilities.wsl import WSLProcess
def _get_python_repl() -> Tool: def _get_python_repl() -> Tool:
@ -41,6 +41,7 @@ def _get_terminal() -> Tool:
"Executes commands in a terminal. Input should be valid commands, and the output will be any output from running that command.", "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: def _get_wsl() -> Tool:
return Tool( return Tool(
"WSL", "WSL",
@ -48,6 +49,7 @@ def _get_wsl() -> Tool:
"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.", "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: def _get_powershell() -> Tool:
return Tool( return Tool(
"PowerShell", "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.", "Executes commands in PowerShell. Input should be valid commands, and the output will be any output from running that command.",
) )
_BASE_TOOLS = { _BASE_TOOLS = {
"python_repl": _get_python_repl, "python_repl": _get_python_repl,
"requests": _get_requests, "requests": _get_requests,

View File

@ -17,7 +17,9 @@ class PowerShellProcess:
commands = ";".join(commands) commands = ";".join(commands)
try: try:
output = subprocess.check_output(["powershell.exe", "-Command", commands]).decode() output = subprocess.check_output(
["powershell.exe", "-Command", commands]
).decode()
except subprocess.CalledProcessError as error: except subprocess.CalledProcessError as error:
return str(error) return str(error)

View File

@ -15,7 +15,7 @@ class WSLProcess:
if isinstance(commands, str): if isinstance(commands, str):
commands = [commands] commands = [commands]
commands = ";".join(commands) commands = ";".join(commands)
commands = 'wsl.exe ' + commands commands = "wsl.exe " + commands
try: try:
output = subprocess.check_output(commands, shell=True).decode() output = subprocess.check_output(commands, shell=True).decode()