HemanM commited on
Commit
52a306d
·
verified ·
1 Parent(s): 1c98e83

Create web_search.py

Browse files
Files changed (1) hide show
  1. web_search.py +18 -0
web_search.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # web_search.py — basic RAG search module using DuckDuckGo
2
+ import requests
3
+
4
+ def web_search(query, max_results=3):
5
+ headers = {"User-Agent": "Mozilla/5.0"}
6
+ url = f"https://duckduckgo.com/html/?q={query}"
7
+ resp = requests.get(url, headers=headers)
8
+
9
+ # Very basic scraping for summaries (not robust)
10
+ snippets = []
11
+ for line in resp.text.splitlines():
12
+ if "result__snippet" in line:
13
+ text = line.split(">")[-1].split("<")[0]
14
+ snippets.append(text)
15
+ if len(snippets) >= max_results:
16
+ break
17
+
18
+ return "\n".join(snippets) if snippets else "No relevant information found."