mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-02 03:26:17 +00:00
community[patch]: Basic Logging and Human input to ShellTool (#15932)
- **Description:** As Shell tool is very versatile, while integrating it into applications as openai functions, developers have no clue about what command is being executed using the ShellTool. All one can see is:  Summarising my feature request: 1. There's no visibility about what command was executed. 2. There's no mechanism to prevent a command to be executed using ShellTool, like a y/n human input which can be accepted from user to proceed with executing the command., - **Issue:** the issue #15931 it fixes if applicable, - **Dependencies:** There isn't any dependancy, - **Twitter handle:** @krishnashed
This commit is contained in:
committed by
GitHub
parent
2af813c7eb
commit
f238217cea
@@ -1,5 +1,6 @@
|
||||
import warnings
|
||||
from typing import List
|
||||
from unittest.mock import patch
|
||||
|
||||
from langchain_community.tools.shell.tool import ShellInput, ShellTool
|
||||
|
||||
@@ -65,3 +66,29 @@ def test_shell_tool_run_str() -> None:
|
||||
shell_tool = ShellTool(process=placeholder)
|
||||
result = shell_tool._run(commands="echo 'Hello, World!'")
|
||||
assert result.strip() == "hello"
|
||||
|
||||
|
||||
async def test_shell_tool_arun_with_user_confirmation() -> None:
|
||||
placeholder = PlaceholderProcess(output="hello")
|
||||
shell_tool = ShellTool(process=placeholder, ask_human_input=True)
|
||||
|
||||
with patch("builtins.input", return_value="y"):
|
||||
result = await shell_tool._arun(commands=test_commands)
|
||||
assert result.strip() == "hello"
|
||||
|
||||
with patch("builtins.input", return_value="n"):
|
||||
result = await shell_tool._arun(commands=test_commands)
|
||||
assert result is None
|
||||
|
||||
|
||||
def test_shell_tool_run_with_user_confirmation() -> None:
|
||||
placeholder = PlaceholderProcess(output="hello")
|
||||
shell_tool = ShellTool(process=placeholder, ask_human_input=True)
|
||||
|
||||
with patch("builtins.input", return_value="y"):
|
||||
result = shell_tool._run(commands="echo 'Hello, World!'")
|
||||
assert result.strip() == "hello"
|
||||
|
||||
with patch("builtins.input", return_value="n"):
|
||||
result = shell_tool._run(commands="echo 'Hello, World!'")
|
||||
assert result is None
|
||||
|
Reference in New Issue
Block a user