Spaces:
Sleeping
Sleeping
Create tools.py
Browse files
tools.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import Tool
|
| 2 |
+
import wikipediaapi
|
| 3 |
+
|
| 4 |
+
class WikipediaTool(Tool):
|
| 5 |
+
name = "wikipedia_lookup"
|
| 6 |
+
description = "Fetches English Wikipedia summary for a given topic."
|
| 7 |
+
|
| 8 |
+
inputs = {
|
| 9 |
+
"query": {"type": "string", "description": "The Wikipedia page title to retrieve."}
|
| 10 |
+
}
|
| 11 |
+
output_type = "string"
|
| 12 |
+
|
| 13 |
+
def forward(self, query: str) -> str:
|
| 14 |
+
wiki = wikipediaapi.Wikipedia('en')
|
| 15 |
+
page = wiki.page(query)
|
| 16 |
+
if not page.exists():
|
| 17 |
+
return f"Wikipedia page '{query}' does not exist."
|
| 18 |
+
return page.summary[:1000]
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class TextTransformerTool(Tool):
|
| 22 |
+
name = "text_transformer"
|
| 23 |
+
description = "Reverses the input text."
|
| 24 |
+
|
| 25 |
+
inputs = {
|
| 26 |
+
"text": {"type": "string", "description": "Text to reverse."}
|
| 27 |
+
}
|
| 28 |
+
output_type = "string"
|
| 29 |
+
|
| 30 |
+
def forward(self, text: str) -> str:
|
| 31 |
+
return text[::-1]
|