Spaces:
Running
Running
Update tools/web_search.py
Browse files- tools/web_search.py +6 -23
tools/web_search.py
CHANGED
|
@@ -18,27 +18,10 @@ class DuckDuckGoSearchTool(Tool):
|
|
| 18 |
"You must install package `duckduckgo_search` to run this tool: for instance run `pip install duckduckgo-search`."
|
| 19 |
) from e
|
| 20 |
self.ddgs = DDGS(**kwargs)
|
| 21 |
-
|
| 22 |
-
|
| 23 |
def forward(self, query: str) -> str:
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
results = ddgs.text(query, max_results=self.max_results)
|
| 30 |
-
|
| 31 |
-
if not results:
|
| 32 |
-
raise Exception("No results found! Try a less restrictive/shorter query.")
|
| 33 |
-
|
| 34 |
-
postprocessed_results = [
|
| 35 |
-
f"[{r['title']}]({r['href']})\n{r['body']}" for r in results
|
| 36 |
-
]
|
| 37 |
-
return "## Search Results\n\n" + "\n\n".join(postprocessed_results)
|
| 38 |
-
|
| 39 |
-
# def forward(self, query: str) -> str:
|
| 40 |
-
# results = self.ddgs.text(query, max_results=self.max_results)
|
| 41 |
-
# if len(results) == 0:
|
| 42 |
-
# raise Exception("No results found! Try a less restrictive/shorter query.")
|
| 43 |
-
# postprocessed_results = [f"[{result['title']}]({result['href']})\n{result['body']}" for result in results]
|
| 44 |
-
# return "## Search Results\n\n" + "\n\n".join(postprocessed_results)
|
|
|
|
| 18 |
"You must install package `duckduckgo_search` to run this tool: for instance run `pip install duckduckgo-search`."
|
| 19 |
) from e
|
| 20 |
self.ddgs = DDGS(**kwargs)
|
| 21 |
+
|
|
|
|
| 22 |
def forward(self, query: str) -> str:
|
| 23 |
+
results = self.ddgs.text(query, max_results=self.max_results)
|
| 24 |
+
if len(results) == 0:
|
| 25 |
+
raise Exception("No results found! Try a less restrictive/shorter query.")
|
| 26 |
+
postprocessed_results = [f"[{result['title']}]({result['href']})\n{result['body']}" for result in results]
|
| 27 |
+
return "## Search Results\n\n" + "\n\n".join(postprocessed_results)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|