Spaces:
Sleeping
Sleeping
Update tools/web_search.py
Browse files- tools/web_search.py +12 -12
tools/web_search.py
CHANGED
|
@@ -36,18 +36,18 @@ class DuckDuckGoSearchTool(Tool):
|
|
| 36 |
raise RuntimeError("No results found. Try a broader/simpler query.")
|
| 37 |
|
| 38 |
results: List[Dict[str, str]] = []
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
|
| 52 |
if not results:
|
| 53 |
raise RuntimeError("Results were returned but none contained valid URLs.")
|
|
|
|
| 36 |
raise RuntimeError("No results found. Try a broader/simpler query.")
|
| 37 |
|
| 38 |
results: List[Dict[str, str]] = []
|
| 39 |
+
for it in items:
|
| 40 |
+
href = (it.get("href") or "").strip()
|
| 41 |
+
if not href:
|
| 42 |
+
continue # skip malformed entries without a URL
|
| 43 |
+
results.append(
|
| 44 |
+
{
|
| 45 |
+
"title": str(it.get("title", "")),
|
| 46 |
+
"url": href, # normalized key name
|
| 47 |
+
"snippet": str(it.get("body", "")),
|
| 48 |
+
}
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
|
| 52 |
if not results:
|
| 53 |
raise RuntimeError("Results were returned but none contained valid URLs.")
|