File size: 1,683 Bytes
fcc14cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from smolagents import PythonInterpreterTool, tool
import requests

@tool
def ReverseTextTool(text: str) -> str:
    """

    Reverses a text string character by character.

    Args:

        text (str): The text to reverse

    Returns:

        str: The reversed text

    """
    return text[::-1]


@tool
def RunPythonFileTool(file_path: str) -> str:
    """

    Executes a Python script loaded from the specified path using the PythonInterpreterTool.

    Args:

        file_path (str): The full path to the python (.py) file containing the Python code.

    Returns:

        str: The output produced by the code execution, or an error message if it fails.

    """
    try:
        with open(file_path, "r") as f:
            code = f.read()
        interpreter = PythonInterpreterTool()
        result = interpreter.run({"code": code})
        return result.get("output", "No output returned.")
    except Exception as e:
        return f"Execution failed: {e}"

@tool
def download_server(url: str, save_path: str) -> str:
    """

    Downloads a file from a URL and saves it to the given path.

    Args:

        url (str): The URL from which to download the file.

        save_path (str): The local file path where the downloaded file will be saved.

    Returns:

        str: A message indicating the result of the download operation.

    """
    try:
        response = requests.get(url, timeout=30)
        response.raise_for_status()
        with open(save_path, "wb") as f:
            f.write(response.content)
        return f"File downloaded to {save_path}"
    except Exception as e:
        return f"Failed to download: {e}"