dlaima commited on
Commit
d2607ac
·
verified ·
1 Parent(s): da7bb4a

Create gaia_tools.py

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