From 5d6502ae1d2d7ef673918b87d35a906e1ceeae41 Mon Sep 17 00:00:00 2001 From: Killian Pitiot <52291816+Killian-pit@users.noreply.github.com> Date: Wed, 22 Jan 2025 14:02:38 +0200 Subject: [PATCH] Minor fix: adding a 60 seconds timeout to the visit webpage tool (#308) * adding a 60 seconds timeout * lowerting the timeout to 20s --- src/smolagents/default_tools.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/smolagents/default_tools.py b/src/smolagents/default_tools.py index 44f76df..3f3af93 100644 --- a/src/smolagents/default_tools.py +++ b/src/smolagents/default_tools.py @@ -225,8 +225,8 @@ class VisitWebpageTool(Tool): "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 @@ class VisitWebpageTool(Tool): 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: