Dodero1305 commited on
Commit
329dc02
·
verified ·
1 Parent(s): 610bb7e

Upload gaia_tools.py

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