DuckDuckGoSearchTool: add ddgs_kwargs parameter to constructor (#372)

* DuckDuckGoSearchTool: add ddgs_kwargs parameter to constructor for flexible configuration
This commit is contained in:
onukura 2025-01-28 10:11:33 +01:00 committed by GitHub
parent 8178eeca65
commit 2105811da6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 3 deletions

View File

@ -106,8 +106,8 @@ class DuckDuckGoSearchTool(Tool):
inputs = {"query": {"type": "string", "description": "The search query to perform."}} inputs = {"query": {"type": "string", "description": "The search query to perform."}}
output_type = "string" output_type = "string"
def __init__(self, *args, max_results=10, **kwargs): def __init__(self, max_results=10, **kwargs):
super().__init__(*args, **kwargs) super().__init__()
self.max_results = max_results self.max_results = max_results
try: try:
from duckduckgo_search import DDGS from duckduckgo_search import DDGS
@ -115,7 +115,7 @@ class DuckDuckGoSearchTool(Tool):
raise ImportError( raise ImportError(
"You must install package `duckduckgo_search` to run this tool: for instance run `pip install duckduckgo-search`." "You must install package `duckduckgo_search` to run this tool: for instance run `pip install duckduckgo-search`."
) from e ) from e
self.ddgs = DDGS() self.ddgs = DDGS(**kwargs)
def forward(self, query: str) -> str: def forward(self, query: str) -> str:
results = self.ddgs.text(query, max_results=self.max_results) results = self.ddgs.text(query, max_results=self.max_results)