Spaces:
Sleeping
Sleeping
File size: 1,663 Bytes
6025aa5 74d146e 6025aa5 720b4df 4d31f6b 6025aa5 4d31f6b 6025aa5 4d31f6b 6025aa5 4d31f6b 6025aa5 | 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 | from smolagents import Tool
from transformers import AutoProcessor
# adjust import to your setup
# from langchain_community.retrievers import WikipediaRetriever # or your existing retriever
class WikiSearchTool(Tool):
name = "wiki_search"
description = (
"Search Wikipedia for a query and return at most 3 results. "
"Args: query (str). Returns: search result as text."
)
inputs = {
"query": {
"type": "string",
"description": "Query string to search on Wikipedia."
}
}
output_type = "string"
def forward(self, query: str) -> str:
try:
# Use your existing WikipediaRetriever, make sure it's imported.
retriever = WikipediaRetriever(top_k_results=3)
wiki_result = retriever.invoke(query)
return wiki_result
except Exception as e:
return f"wiki_search failed {e}"
class ReverseStringTool(Tool):
name = "reverse_string"
description = (
"Reverse the characters of the given string and wrap it in an explanatory sentence."
)
inputs = {
"input_string": {
"type": "string",
"description": "String whose characters will be reversed."
}
}
output_type = "string"
def forward(self, input_string: str) -> str:
try:
reversed_string = input_string[::-1]
reversed_string = (
f"The reversed string returned from reverse_string function is: {reversed_string}"
)
return reversed_string
except Exception as e:
return f"reverse_string failed {e}" |