Skip to content

Commit

Permalink
Minor fix: adding a 60 seconds timeout to the visit webpage tool (#308)
Browse files Browse the repository at this point in the history
* adding a 60 seconds timeout

* lowerting the timeout to 20s
  • Loading branch information
Killian-pit authored Jan 22, 2025
1 parent 43904f3 commit 5d6502a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/smolagents/default_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 5d6502a

Please sign in to comment.