File size: 2,272 Bytes
edab6f8
 
76befd3
edab6f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76befd3
edab6f8
76befd3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48d443e
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from smolagents import PythonInterpreterTool, tool
import requests
import wikipedia

@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 code 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 WikipediaSearchTool(query: str) -> str:
    """
    Searches Wikipedia and returns page content for a given query.
    
    Args:
        query (str): The search term or page title to look up on Wikipedia
        
    Returns:
        str: The Wikipedia page content, or an error message if not found
    """
    try:
        page = wikipedia.page(query)
        return f"Title: {page.title}\nURL: {page.url}\nContent: {page.content[:2000]}..."
    except wikipedia.exceptions.DisambiguationError as e:
        try:
            page = wikipedia.page(e.options[0])
            return f"Title: {page.title}\nURL: {page.url}\nContent: {page.content[:2000]}..."
        except:
            return f"Multiple pages found: {e.options[:5]}"
    except wikipedia.exceptions.PageError:
        try:
            search_results = wikipedia.search(query, results=3)
            if search_results:
                page = wikipedia.page(search_results[0])
                return f"Title: {page.title}\nURL: {page.url}\nContent: {page.content[:2000]}..."
            else:
                return f"No Wikipedia pages found for: {query}"
        except:
            return f"No Wikipedia pages found for: {query}"
    except Exception as e:
        return f"Wikipedia search failed: {e}"

@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]