Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -136,35 +136,36 @@ browser = SimpleTextBrowser(**BROWSER_CONFIG)
|
|
136 |
class DuckDuckGoSearchTool(Tool):
|
137 |
"""Search tool using DuckDuckGo"""
|
138 |
name = "web_search"
|
139 |
-
description = "Search the web using DuckDuckGo"
|
140 |
-
output_type = "string" # Explicit output type [github.com]
|
141 |
inputs = {
|
142 |
"query": {
|
143 |
-
"type": "string",
|
144 |
-
"description": "Search query",
|
145 |
"required": True
|
146 |
}
|
147 |
}
|
|
|
148 |
|
149 |
-
def __init__(self, max_results=5):
|
150 |
super().__init__()
|
151 |
self.max_results = max_results
|
152 |
|
153 |
-
def
|
|
|
154 |
try:
|
155 |
-
with DDGS(timeout=30) as ddgs:
|
156 |
results = list(ddgs.text(
|
157 |
-
query,
|
158 |
max_results=self.max_results,
|
159 |
-
region='wt-wt'
|
160 |
-
safesearch='moderate'
|
161 |
))
|
162 |
-
|
163 |
-
|
|
|
164 |
for res in results
|
165 |
])
|
166 |
except Exception as e:
|
167 |
-
return f"Search
|
168 |
|
169 |
|
170 |
|
|
|
136 |
class DuckDuckGoSearchTool(Tool):
|
137 |
"""Search tool using DuckDuckGo"""
|
138 |
name = "web_search"
|
139 |
+
description = "Search the web using DuckDuckGo (current information)"
|
|
|
140 |
inputs = {
|
141 |
"query": {
|
142 |
+
"type": "string",
|
143 |
+
"description": "Search query terms",
|
144 |
"required": True
|
145 |
}
|
146 |
}
|
147 |
+
output_type = "string"
|
148 |
|
149 |
+
def __init__(self, max_results: int = 5):
|
150 |
super().__init__()
|
151 |
self.max_results = max_results
|
152 |
|
153 |
+
def forward(self, query: str) -> str: # <-- Correct method name and signature
|
154 |
+
"""Execute DuckDuckGo search"""
|
155 |
try:
|
156 |
+
with DDGS(timeout=30) as ddgs:
|
157 |
results = list(ddgs.text(
|
158 |
+
keywords=query,
|
159 |
max_results=self.max_results,
|
160 |
+
region='wt-wt'
|
|
|
161 |
))
|
162 |
+
|
163 |
+
return "\n\n".join([
|
164 |
+
f"β’ {res['title']}\n URL: {res['href']}\n {res['body'][:200]}..."
|
165 |
for res in results
|
166 |
])
|
167 |
except Exception as e:
|
168 |
+
return f"Search error: {str(e)}"
|
169 |
|
170 |
|
171 |
|