Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/smolagents/default_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,11 @@ class WebSearchTool(Tool):
inputs = {"query": {"type": "string", "description": "The search query to perform."}}
output_type = "string"

def __init__(self, max_results: int = 10, engine: str = "duckduckgo"):
def __init__(self, max_results: int = 10, engine: str = "duckduckgo", timeout: int = 30):
super().__init__()
self.max_results = max_results
self.engine = engine
self.timeout = timeout

def forward(self, query: str) -> str:
results = self.search(query)
Expand Down Expand Up @@ -376,6 +377,7 @@ def search_duckduckgo(self, query: str) -> list:
"https://lite.duckduckgo.com/lite/",
params={"q": query},
headers={"User-Agent": "Mozilla/5.0"},
timeout=self.timeout,
)
response.raise_for_status()
parser = self._create_duckduckgo_parser()
Expand Down Expand Up @@ -436,6 +438,7 @@ def search_bing(self, query: str) -> list:
response = requests.get(
"https://www.bing.com/search",
params={"q": query, "format": "rss"},
timeout=self.timeout,
)
response.raise_for_status()
root = ET.fromstring(response.text)
Expand Down