Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -126,35 +126,52 @@ class DuckDuckGoSearchTool(Tool):
|
|
126 |
"""Search tool using DuckDuckGo"""
|
127 |
name = "web_search"
|
128 |
description = "Search the web using DuckDuckGo (current information)"
|
129 |
-
inputs = [{
|
130 |
-
"name": "query",
|
131 |
-
"type": "string",
|
132 |
-
"description": "Search query string",
|
133 |
-
"required": True
|
134 |
-
}]
|
135 |
-
outputs = [{
|
136 |
-
"name": "results",
|
137 |
-
"type": "string",
|
138 |
-
"description": "Formatted search results"
|
139 |
-
}]
|
140 |
|
141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
super().__init__()
|
143 |
self.max_results = max_results
|
144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
def run(self, query: str) -> str:
|
146 |
-
"""
|
147 |
try:
|
148 |
with DDGS() as ddgs:
|
149 |
-
results = list(ddgs.text(
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
-
|
152 |
-
f"
|
153 |
-
for
|
154 |
-
]
|
155 |
-
return "\n\n".join(formatted)
|
156 |
except Exception as e:
|
157 |
-
return f"Search
|
|
|
158 |
|
159 |
WEB_TOOLS = [
|
160 |
DuckDuckGoSearchTool(max_results=5),
|
|
|
126 |
"""Search tool using DuckDuckGo"""
|
127 |
name = "web_search"
|
128 |
description = "Search the web using DuckDuckGo (current information)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
+
# Smolagents requires these formatted as dicts (not lists) [github.com]
|
131 |
+
inputs = {
|
132 |
+
"query": {
|
133 |
+
"type": "string",
|
134 |
+
"description": "Search query string",
|
135 |
+
"required": True
|
136 |
+
}
|
137 |
+
}
|
138 |
+
|
139 |
+
outputs = {
|
140 |
+
"results": {
|
141 |
+
"type": "string",
|
142 |
+
"description": "Formatted search results with URLs and snippets"
|
143 |
+
}
|
144 |
+
}
|
145 |
+
|
146 |
+
def __init__(self, max_results: int = 5):
|
147 |
super().__init__()
|
148 |
self.max_results = max_results
|
149 |
+
self.args_schema = {
|
150 |
+
"max_results": {
|
151 |
+
"type": "integer",
|
152 |
+
"description": "Max results to return",
|
153 |
+
"default": 5
|
154 |
+
}
|
155 |
+
}
|
156 |
+
|
157 |
def run(self, query: str) -> str:
|
158 |
+
"""Perform a search and return formatted results"""
|
159 |
try:
|
160 |
with DDGS() as ddgs:
|
161 |
+
results = list(ddgs.text(
|
162 |
+
keywords=query,
|
163 |
+
region='wt-wt',
|
164 |
+
safesearch='moderate',
|
165 |
+
max_results=self.max_results
|
166 |
+
))
|
167 |
|
168 |
+
return "\n\n".join([
|
169 |
+
f"β’ {res['title']}\n {res['href']}\n {res['body'][:300]}..."
|
170 |
+
for res in results
|
171 |
+
])
|
|
|
172 |
except Exception as e:
|
173 |
+
return f"Search failed: {str(e)}"
|
174 |
+
|
175 |
|
176 |
WEB_TOOLS = [
|
177 |
DuckDuckGoSearchTool(max_results=5),
|