File size: 863 Bytes
f5dc70c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from smolagents import Tool
import wikipediaapi

class WikipediaTool(Tool):
    name = "wikipedia_lookup"
    description = "Fetches English Wikipedia summary for a given topic."

    inputs = {
        "query": {"type": "string", "description": "The Wikipedia page title to retrieve."}
    }
    output_type = "string"

    def forward(self, query: str) -> str:
        wiki = wikipediaapi.Wikipedia('en')
        page = wiki.page(query)
        if not page.exists():
            return f"Wikipedia page '{query}' does not exist."
        return page.summary[:1000]


class TextTransformerTool(Tool):
    name = "text_transformer"
    description = "Reverses the input text."

    inputs = {
        "text": {"type": "string", "description": "Text to reverse."}
    }
    output_type = "string"

    def forward(self, text: str) -> str:
        return text[::-1]