EvoConvo / web_search.py
HemanM's picture
Update web_search.py
5829fd2 verified
raw
history blame
567 Bytes
# web_search.py — DuckDuckGo basic web RAG
import requests
def web_search(query, max_results=3):
headers = {"User-Agent": "Mozilla/5.0"}
url = f"https://duckduckgo.com/html/?q={query}"
resp = requests.get(url, headers=headers)
snippets = []
for line in resp.text.splitlines():
if "result__snippet" in line:
text = line.split(">")[-1].split("<")[0]
snippets.append(text)
if len(snippets) >= max_results:
break
return "\n".join(snippets) if snippets else "No relevant information found."