diff --git a/src/smolagents/default_tools.py b/src/smolagents/default_tools.py index 44f76df42..3f3af93e7 100644 --- a/src/smolagents/default_tools.py +++ b/src/smolagents/default_tools.py @@ -225,8 +225,8 @@ def forward(self, url: str) -> str: "You must install packages `markdownify` and `requests` to run this tool: for instance run `pip install markdownify requests`." ) from e try: - # Send a GET request to the URL - response = requests.get(url) + # Send a GET request to the URL with a 20-second timeout + response = requests.get(url, timeout=20) response.raise_for_status() # Raise an exception for bad status codes # Convert the HTML content to Markdown @@ -237,6 +237,8 @@ def forward(self, url: str) -> str: return truncate_content(markdown_content, 10000) + except requests.exceptions.Timeout: + return "The request timed out. Please try again later or check the URL." except RequestException as e: return f"Error fetching the webpage: {str(e)}" except Exception as e: