Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BFCL] Multi Turn Pipeline Robustness Patch #724

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -500,35 +500,6 @@ def grep(self, file_name: str, pattern: str) -> Dict[str, List[str]]:

return {"error": f"grep: {file_name}: No such file or directory"}

def xargs(self, command: str, file_name: str = None):
"""
Execute a command with arguments read from a file or standard input.

Args:
command (str): The command to execute with arguments.
file_name (str): [Optional] The file containing arguments. Defaults to None.

Returns:
output (str): The result of the command execution.
"""
if file_name:
if file_name in self._current_dir.contents:
file = self._current_dir._get_item(file_name)
if isinstance(file, File):
args = file._read().splitlines()
else:
return {"error": f"xargs: {file_name}: Not a file"}
else:
return {"error": f"xargs: {file_name}: No such file or directory"}
else:
return {"error": f"Argument not supported"}

try:
result = subprocess.run([command] + args, capture_output=True, text=True)
return {"output": result.stdout, "error": result.stderr}
except Exception as e:
return {"error": str(e)}

def du(self, human_readable: bool = False) -> Dict[str, str]:
"""
Estimate the disk usage of a directory and its contents.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ def execute_multi_turn_func_call(

# Evaluate the function call
try:
# Before calling `eval`, we need to make sure that the function call is safe
# We do so by checking if the function is `kill` or `exit`, etc.
# Extract the function name first
if "(" in func_call:
func_call = func_call.split("(")[0]
# Situation where the function call is a method call
if "." in func_call:
func_call = func_call.split(".")[1]
if func_call in ["kill", "exit", "quit", "remove", "unlink", "rmdir", "popen", "Popen", "run"]:
raise Exception(f"Function call {func_call} is not allowed.")

func_call_result = eval(func_call)

if type(func_call_result) == str:
Expand Down