DuckDuckGoSearchTool: add ddgs_kwargs parameter to constructor (#372)
* DuckDuckGoSearchTool: add ddgs_kwargs parameter to constructor for flexible configuration
This commit is contained in:
parent
8178eeca65
commit
2105811da6
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue