AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
More graceful browsing error handling (#3494)
James Collins92009ceb32ec
diff --git a/autogpt/commands/web_selenium.py b/autogpt/commands/web_selenium.pyindex 739520ecdb..79a8ffd946 100644--- a/autogpt/commands/web_selenium.py+++ b/autogpt/commands/web_selenium.py@@ -7,6 +7,7 @@ from sys import platformfrom bs4 import BeautifulSoupfrom selenium import webdriver+from selenium.common.exceptions import WebDriverExceptionfrom selenium.webdriver.chrome.options import Options as ChromeOptionsfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.firefox.options import Options as FirefoxOptions@@ -43,7 +44,14 @@ def browse_website(url: str, question: str) -> tuple[str, WebDriver]:Returns:Tuple[str, WebDriver]: The answer and links to the user and the webdriver"""- driver, text = scrape_text_with_selenium(url)+ try:+ driver, text = scrape_text_with_selenium(url)+ except WebDriverException as e:+ # These errors are often quite long and include lots of context.+ # Just grab the first line.+ msg = e.msg.split("\n")[0]+ return f"Error: {msg}", None+add_header(driver)summary_text = summary.summarize_text(url, text, question, driver)links = scrape_links_with_selenium(driver, url)diff --git a/tests/unit/test_web_selenium.py b/tests/unit/test_web_selenium.pynew file mode 100644index 0000000000..bf13a8d9ed--- /dev/null+++ b/tests/unit/test_web_selenium.py@@ -0,0 +1,11 @@+from autogpt.commands.web_selenium import browse_website+++def test_browse_website():+ url = "https://barrel-roll.com"+ question = "How to execute a barrel roll"++ response, _ = browse_website(url, question)+ assert "Error" in response+ # Sanity check that the response is not too long+ assert len(response) < 200