More graceful browsing error handling (#3494)

pull/2757/head^2
James Collins 2023-04-28 14:12:47 -07:00 committed by GitHub
parent aa3e37ac14
commit 92009ceb32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -7,6 +7,7 @@ from sys import platform
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.common.by import By
from 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)

View File

@ -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