Spaces:
Sleeping
Sleeping
| 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}" |