naman1102's picture
Update tools.py
2bf962d
raw
history blame
707 Bytes
from typing import List
from duckduckgo_search import DDGS
# --- Simple Search Tool ---
def simple_search(query: str, max_results: int = 3) -> List[str]:
"""
Perform a DuckDuckGo search and return a list of strings summarizing the top results.
"""
with DDGS() as ddgs:
raw_results = list(ddgs.text(query, max_results=max_results))
results = []
for r in raw_results:
try:
title = r.get("title", "")
link = r.get("href") or r.get("link", "")
summary = f"{title} - {link}"
results.append(summary)
except Exception as e:
print("Skipping malformed search result:", r, "Error:", e)
return results