Spaces:
Sleeping
Sleeping
Update tools.py
Browse files
tools.py
CHANGED
|
@@ -31,57 +31,31 @@ def search_wikipedia(query: str) -> str:
|
|
| 31 |
return "\n".join([r['title'] for r in results])
|
| 32 |
return "No search results found."
|
| 33 |
|
| 34 |
-
# ✅ Actual tools expecting dict inputs
|
| 35 |
class WikipediaTool(Tool):
|
| 36 |
name = "WikipediaTool"
|
| 37 |
-
description = "Fetches plain text from a Wikipedia article. Input should be the article title."
|
| 38 |
inputs = {"query": "string"}
|
| 39 |
output_type = "string"
|
| 40 |
|
| 41 |
-
def __call__(self, inputs
|
| 42 |
-
return fetch_wikipedia_article(inputs["query"])
|
| 43 |
-
|
| 44 |
-
class WikipediaSearchTool(Tool):
|
| 45 |
-
name = "WikipediaSearchTool"
|
| 46 |
-
description = "Searches Wikipedia for article titles related to a query. Input should be a question or topic."
|
| 47 |
-
inputs = {"query": "string"}
|
| 48 |
-
output_type = "string"
|
| 49 |
-
|
| 50 |
-
def __call__(self, inputs: dict) -> str:
|
| 51 |
-
return search_wikipedia(inputs["query"])
|
| 52 |
-
|
| 53 |
-
# ✅ Wrapper Tools (these are called by CodeAgent)
|
| 54 |
-
class WikipediaToolWrapper(Tool):
|
| 55 |
-
name = "WikipediaToolWrapper"
|
| 56 |
-
description = WikipediaTool.description
|
| 57 |
-
inputs = {"query": "string"}
|
| 58 |
-
output_type = "string"
|
| 59 |
-
|
| 60 |
-
def __init__(self):
|
| 61 |
-
self.tool = WikipediaTool()
|
| 62 |
-
|
| 63 |
-
def __call__(self, inputs: dict) -> str:
|
| 64 |
if isinstance(inputs, str):
|
| 65 |
inputs = {"query": inputs}
|
| 66 |
elif isinstance(inputs, dict) and "query" not in inputs:
|
| 67 |
inputs = {"query": next(iter(inputs.values()))}
|
| 68 |
-
return
|
| 69 |
|
| 70 |
-
class
|
| 71 |
-
name = "
|
| 72 |
-
description =
|
| 73 |
inputs = {"query": "string"}
|
| 74 |
output_type = "string"
|
| 75 |
|
| 76 |
-
def
|
| 77 |
-
self.tool = WikipediaSearchTool()
|
| 78 |
-
|
| 79 |
-
def __call__(self, inputs: dict) -> str:
|
| 80 |
if isinstance(inputs, str):
|
| 81 |
inputs = {"query": inputs}
|
| 82 |
elif isinstance(inputs, dict) and "query" not in inputs:
|
| 83 |
inputs = {"query": next(iter(inputs.values()))}
|
| 84 |
-
return
|
| 85 |
|
| 86 |
|
| 87 |
|
|
|
|
| 31 |
return "\n".join([r['title'] for r in results])
|
| 32 |
return "No search results found."
|
| 33 |
|
|
|
|
| 34 |
class WikipediaTool(Tool):
|
| 35 |
name = "WikipediaTool"
|
| 36 |
+
description = "Fetches plain text from a Wikipedia article. Input should be the article title as a string."
|
| 37 |
inputs = {"query": "string"}
|
| 38 |
output_type = "string"
|
| 39 |
|
| 40 |
+
def __call__(self, inputs) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
if isinstance(inputs, str):
|
| 42 |
inputs = {"query": inputs}
|
| 43 |
elif isinstance(inputs, dict) and "query" not in inputs:
|
| 44 |
inputs = {"query": next(iter(inputs.values()))}
|
| 45 |
+
return fetch_wikipedia_article(inputs["query"])
|
| 46 |
|
| 47 |
+
class WikipediaSearchTool(Tool):
|
| 48 |
+
name = "WikipediaSearchTool"
|
| 49 |
+
description = "Searches Wikipedia for article titles. Input should be a question or topic as a string."
|
| 50 |
inputs = {"query": "string"}
|
| 51 |
output_type = "string"
|
| 52 |
|
| 53 |
+
def __call__(self, inputs) -> str:
|
|
|
|
|
|
|
|
|
|
| 54 |
if isinstance(inputs, str):
|
| 55 |
inputs = {"query": inputs}
|
| 56 |
elif isinstance(inputs, dict) and "query" not in inputs:
|
| 57 |
inputs = {"query": next(iter(inputs.values()))}
|
| 58 |
+
return search_wikipedia(inputs["query"])
|
| 59 |
|
| 60 |
|
| 61 |
|