Upload gaia_tools.py
Browse files- gaia_tools.py +51 -0
gaia_tools.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from smolagents import PythonInterpreterTool, tool
|
2 |
+
import requests
|
3 |
+
|
4 |
+
@tool
|
5 |
+
def ReverseTextTool(text: str) -> str:
|
6 |
+
"""
|
7 |
+
Reverses a text string character by character.
|
8 |
+
Args:
|
9 |
+
text (str): The text to reverse
|
10 |
+
Returns:
|
11 |
+
str: The reversed text
|
12 |
+
"""
|
13 |
+
return text[::-1]
|
14 |
+
|
15 |
+
|
16 |
+
@tool
|
17 |
+
def RunPythonFileTool(file_path: str) -> str:
|
18 |
+
"""
|
19 |
+
Executes a Python script loaded from the specified path using the PythonInterpreterTool.
|
20 |
+
Args:
|
21 |
+
file_path (str): The full path to the python (.py) file containing the Python code.
|
22 |
+
Returns:
|
23 |
+
str: The output produced by the code execution, or an error message if it fails.
|
24 |
+
"""
|
25 |
+
try:
|
26 |
+
with open(file_path, "r") as f:
|
27 |
+
code = f.read()
|
28 |
+
interpreter = PythonInterpreterTool()
|
29 |
+
result = interpreter.run({"code": code})
|
30 |
+
return result.get("output", "No output returned.")
|
31 |
+
except Exception as e:
|
32 |
+
return f"Execution failed: {e}"
|
33 |
+
|
34 |
+
@tool
|
35 |
+
def download_server(url: str, save_path: str) -> str:
|
36 |
+
"""
|
37 |
+
Downloads a file from a URL and saves it to the given path.
|
38 |
+
Args:
|
39 |
+
url (str): The URL from which to download the file.
|
40 |
+
save_path (str): The local file path where the downloaded file will be saved.
|
41 |
+
Returns:
|
42 |
+
str: A message indicating the result of the download operation.
|
43 |
+
"""
|
44 |
+
try:
|
45 |
+
response = requests.get(url, timeout=30)
|
46 |
+
response.raise_for_status()
|
47 |
+
with open(save_path, "wb") as f:
|
48 |
+
f.write(response.content)
|
49 |
+
return f"File downloaded to {save_path}"
|
50 |
+
except Exception as e:
|
51 |
+
return f"Failed to download: {e}"
|