Merge pull request #40 from Stillerman/main

Add max_results kwarg to DuckDuckGoSearchTool
This commit is contained in:
Aymeric Roucher 2025-01-06 19:34:13 +01:00 committed by GitHub
commit eae4b6fb3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 3 deletions

View File

@ -153,8 +153,9 @@ class DuckDuckGoSearchTool(Tool):
}
output_type = "any"
def __init__(self, **kwargs):
super().__init__(self, **kwargs)
def __init__(self, *args, max_results=10, **kwargs):
super().__init__(*args, **kwargs)
self.max_results = max_results
try:
from duckduckgo_search import DDGS
except ImportError:
@ -164,7 +165,7 @@ class DuckDuckGoSearchTool(Tool):
self.ddgs = DDGS()
def forward(self, query: str) -> str:
results = self.ddgs.text(query, max_results=10)
results = self.ddgs.text(query, max_results=self.max_results)
postprocessed_results = [
f"[{result['title']}]({result['href']})\n{result['body']}"
for result in results