Spaces:
Sleeping
Sleeping
Create tools/search.py
Browse files- tools/search.py +10 -0
tools/search.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from duckduckgo_search import DDGS
|
| 2 |
+
|
| 3 |
+
def web_search(query, max_results=3):
|
| 4 |
+
results = []
|
| 5 |
+
with DDGS() as ddgs:
|
| 6 |
+
for r in ddgs.text(query):
|
| 7 |
+
results.append(r["body"])
|
| 8 |
+
if len(results) >= max_results:
|
| 9 |
+
break
|
| 10 |
+
return "\n".join(results)
|