Update app.py
Browse filesnew custom tool linux_shell_interface
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import datetime
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
|
|
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
|
@@ -18,6 +19,22 @@ def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -51,7 +68,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 51 |
|
| 52 |
agent = CodeAgent(
|
| 53 |
model=model,
|
| 54 |
-
tools=[final_answer, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
| 55 |
max_steps=6,
|
| 56 |
verbosity_level=1,
|
| 57 |
grammar=None,
|
|
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
+
import subprocess
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
|
|
|
| 19 |
"""
|
| 20 |
return "What magic will you build ?"
|
| 21 |
|
| 22 |
+
@tool
|
| 23 |
+
def linux_shell_interface(command: str) -> str:
|
| 24 |
+
"""A tool that executes a Debian Linux command and returns the output.
|
| 25 |
+
|
| 26 |
+
Args:
|
| 27 |
+
command: The Debian Linux command to execute as a string. Be very careful with this tool as it can run arbitrary commands.
|
| 28 |
+
|
| 29 |
+
Returns:
|
| 30 |
+
str: The output of the command, or an error message if execution fails.
|
| 31 |
+
"""
|
| 32 |
+
try:
|
| 33 |
+
result = subprocess.check_output(command, shell=True, executable='/bin/bash').decode('utf-8')
|
| 34 |
+
return result
|
| 35 |
+
except Exception as e:
|
| 36 |
+
return f"Error executing command: {e}"
|
| 37 |
+
|
| 38 |
@tool
|
| 39 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 40 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 68 |
|
| 69 |
agent = CodeAgent(
|
| 70 |
model=model,
|
| 71 |
+
tools=[final_answer, get_current_time_in_timezone, linux_shell_interface], ## add your tools here (don't remove final answer)
|
| 72 |
max_steps=6,
|
| 73 |
verbosity_level=1,
|
| 74 |
grammar=None,
|