Skip to content

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.

Merge remote-tracking branch 'origin/master' into support-headless-chrome-mode

Reinier van der Leer9d14b113a3e5
diff --cc .env.template
index 89ae0a9b08,09deeb9314..68392d769b
--- a/.env.template
+++ b/.env.template
@@@ -93,9 -117,26 +117,30 @@@ IMAGE_PROVIDER=dall
HUGGINGFACE_API_TOKEN=your-huggingface-api-token
################################################################################
- ### SEARCH PROVIDER
+ ### AUDIO TO TEXT PROVIDER
+ ################################################################################
+
+ ### HUGGINGFACE
+ HUGGINGFACE_AUDIO_TO_TEXT_MODEL=facebook/wav2vec2-base-960h
+
+ ################################################################################
+ ### GIT Provider for repository actions
+ ################################################################################
+
+ ### GITHUB
+ # GITHUB_API_KEY - Github API key / PAT (Example: github_pat_123)
+ # GITHUB_USERNAME - Github username
+ GITHUB_API_KEY=github_pat_123
+ GITHUB_USERNAME=your-github-username
+
+ ################################################################################
-### SEARCH PROVIDER
++### WEB BROWSING
################################################################################
++### BROWSER
++# HEADLESS_BROWSER - Whether to run the browser in headless mode
++HEADLESS_BROWSER=True
++
### GOOGLE
# GOOGLE_API_KEY - Google API key (Example: my-google-api-key)
# CUSTOM_SEARCH_ENGINE_ID - Custom search engine ID (Example: my-custom-search-engine-id)
diff --cc autogpt/commands/web_selenium.py
index 0000000000,9db5d03502..277064034b
mode 000000,100644..100644
--- a/autogpt/commands/web_selenium.py
+++ b/autogpt/commands/web_selenium.py
@@@ -1,0 -1,149 +1,154 @@@
+ """Selenium web scraping module."""
+ from __future__ import annotations
+
+ import logging
+ from pathlib import Path
+ from sys import platform
+
+ from bs4 import BeautifulSoup
+ from selenium import webdriver
+ 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
+ from selenium.webdriver.remote.webdriver import WebDriver
+ from selenium.webdriver.safari.options import Options as SafariOptions
+ from selenium.webdriver.support import expected_conditions as EC
+ from selenium.webdriver.support.wait import WebDriverWait
+ from webdriver_manager.chrome import ChromeDriverManager
+ from webdriver_manager.firefox import GeckoDriverManager
+
+ import autogpt.processing.text as summary
+ from autogpt.config import Config
+ from autogpt.processing.html import extract_hyperlinks, format_hyperlinks
+
+ FILE_DIR = Path(__file__).parent.parent
+ CFG = Config()
+
+
+ def browse_website(url: str, question: str) -> tuple[str, WebDriver]:
+ """Browse a website and return the answer and links to the user
+
+ Args:
+ url (str): The url of the website to browse
+ question (str): The question asked by the user
+
+ Returns:
+ Tuple[str, WebDriver]: The answer and links to the user and the webdriver
+ """
+ driver, text = scrape_text_with_selenium(url)
+ add_header(driver)
+ summary_text = summary.summarize_text(url, text, question, driver)
+ links = scrape_links_with_selenium(driver, url)
+
+ # Limit links to 5
+ if len(links) > 5:
+ links = links[:5]
+ close_browser(driver)
+ return f"Answer gathered from website: {summary_text} \n \n Links: {links}", driver
+
+
+ def scrape_text_with_selenium(url: str) -> tuple[WebDriver, str]:
+ """Scrape text from a website using selenium
+
+ Args:
+ url (str): The url of the website to scrape
+
+ Returns:
+ Tuple[WebDriver, str]: The webdriver and the text scraped from the website
+ """
+ logging.getLogger("selenium").setLevel(logging.CRITICAL)
+
+ options_available = {
+ "chrome": ChromeOptions,
+ "safari": SafariOptions,
+ "firefox": FirefoxOptions,
+ }
+
+ options = options_available[CFG.selenium_web_browser]()
+ options.add_argument(
+ "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.5615.49 Safari/537.36"
+ )
+
+ if CFG.selenium_web_browser == "firefox":
+ driver = webdriver.Firefox(
+ executable_path=GeckoDriverManager().install(), options=options
+ )
+ elif CFG.selenium_web_browser == "safari":
+ # Requires a bit more setup on the users end
+ # See https://developer.apple.com/documentation/webkit/testing_with_webdriver_in_safari
+ driver = webdriver.Safari(options=options)
+ else:
+ if platform == "linux" or platform == "linux2":
+ options.add_argument("--disable-dev-shm-usage")
+ options.add_argument("--remote-debugging-port=9222")
++
+ options.add_argument("--no-sandbox")
++ if CFG.headless_browser:
++ options.add_argument("--headless")
++ options.add_argument("--disable-gpu")
++
+ driver = webdriver.Chrome(
+ executable_path=ChromeDriverManager().install(), options=options
+ )
+ driver.get(url)
+
+ WebDriverWait(driver, 10).until(
+ EC.presence_of_element_located((By.TAG_NAME, "body"))
+ )
+
+ # Get the HTML content directly from the browser's DOM
+ page_source = driver.execute_script("return document.body.outerHTML;")
+ soup = BeautifulSoup(page_source, "html.parser")
+
+ for script in soup(["script", "style"]):
+ script.extract()
+
+ text = soup.get_text()
+ lines = (line.strip() for line in text.splitlines())
+ chunks = (phrase.strip() for line in lines for phrase in line.split(" "))
+ text = "\n".join(chunk for chunk in chunks if chunk)
+ return driver, text
+
+
+ def scrape_links_with_selenium(driver: WebDriver, url: str) -> list[str]:
+ """Scrape links from a website using selenium
+
+ Args:
+ driver (WebDriver): The webdriver to use to scrape the links
+
+ Returns:
+ List[str]: The links scraped from the website
+ """
+ page_source = driver.page_source
+ soup = BeautifulSoup(page_source, "html.parser")
+
+ for script in soup(["script", "style"]):
+ script.extract()
+
+ hyperlinks = extract_hyperlinks(soup, url)
+
+ return format_hyperlinks(hyperlinks)
+
+
+ def close_browser(driver: WebDriver) -> None:
+ """Close the browser
+
+ Args:
+ driver (WebDriver): The webdriver to close
+
+ Returns:
+ None
+ """
+ driver.quit()
+
+
+ def add_header(driver: WebDriver) -> None:
+ """Add a header to the website
+
+ Args:
+ driver (WebDriver): The webdriver to use to add the header
+
+ Returns:
+ None
+ """
+ driver.execute_script(open(f"{FILE_DIR}/js/overlay.js", "r").read())
diff --cc autogpt/config/config.py
index a2da05aa9d,bc75b03192..7e82627df8
--- a/autogpt/config/config.py
+++ b/autogpt/config/config.py
@@@ -77,16 -65,36 +65,37 @@@ class Config(metaclass=Singleton)
self.pinecone_api_key = os.getenv("PINECONE_API_KEY")
self.pinecone_region = os.getenv("PINECONE_ENV")
+ self.weaviate_host = os.getenv("WEAVIATE_HOST")
+ self.weaviate_port = os.getenv("WEAVIATE_PORT")
+ self.weaviate_protocol = os.getenv("WEAVIATE_PROTOCOL", "http")
+ self.weaviate_username = os.getenv("WEAVIATE_USERNAME", None)
+ self.weaviate_password = os.getenv("WEAVIATE_PASSWORD", None)
+ self.weaviate_scopes = os.getenv("WEAVIATE_SCOPES", None)
+ self.weaviate_embedded_path = os.getenv("WEAVIATE_EMBEDDED_PATH")
+ self.weaviate_api_key = os.getenv("WEAVIATE_API_KEY", None)
+ self.use_weaviate_embedded = (
+ os.getenv("USE_WEAVIATE_EMBEDDED", "False") == "True"
+ )
+
+ # milvus configuration, e.g., localhost:19530.
+ self.milvus_addr = os.getenv("MILVUS_ADDR", "localhost:19530")
+ self.milvus_collection = os.getenv("MILVUS_COLLECTION", "autogpt")
+
self.image_provider = os.getenv("IMAGE_PROVIDER")
self.huggingface_api_token = os.getenv("HUGGINGFACE_API_TOKEN")
+ self.huggingface_audio_to_text_model = os.getenv(
+ "HUGGINGFACE_AUDIO_TO_TEXT_MODEL"
+ )
# User agent headers to use when browsing web
- # Some websites might just completely deny request with an error code if no user agent was found.
+ # Some websites might just completely deny request with an error code if
+ # no user agent was found.
self.user_agent = os.getenv(
"USER_AGENT",
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36",
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36"
+ " (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36",
)
+ self.headless_browser = os.getenv('HEADLESS_BROWSER',"True") == "True"
self.redis_host = os.getenv("REDIS_HOST", "localhost")
self.redis_port = os.getenv("REDIS_PORT", "6379")
self.redis_password = os.getenv("REDIS_PASSWORD", "")