mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-18 06:24:20 +01:00
update type annotation
This commit is contained in:
@@ -14,7 +14,7 @@ class AgentManager(metaclass=Singleton):
|
|||||||
# Create new GPT agent
|
# Create new GPT agent
|
||||||
# TODO: Centralise use of create_chat_completion() to globally enforce token limit
|
# TODO: Centralise use of create_chat_completion() to globally enforce token limit
|
||||||
|
|
||||||
def create_agent(self, task: str, prompt: str, model: str) -> tuple[int, str]:
|
def create_agent(self, task: str, prompt: str, model: str) -> Tuple[int, str]:
|
||||||
"""Create a new agent and return its key
|
"""Create a new agent and return its key
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ def get_response(
|
|||||||
timeout (int): The timeout for the HTTP request
|
timeout (int): The timeout for the HTTP request
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
tuple[None, str] | tuple[Response, None]: The response and error message
|
Tuple[None, str] | Tuple[Response, None]: The response and error message
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ValueError: If the URL is invalid
|
ValueError: If the URL is invalid
|
||||||
|
|||||||
@@ -11,12 +11,13 @@ from selenium.webdriver.chrome.options import Options
|
|||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from autogpt.config import Config
|
from autogpt.config import Config
|
||||||
|
from typing import List, Tuple, Union
|
||||||
|
|
||||||
FILE_DIR = Path(__file__).parent.parent
|
FILE_DIR = Path(__file__).parent.parent
|
||||||
CFG = Config()
|
CFG = Config()
|
||||||
|
|
||||||
|
|
||||||
def browse_website(url: str, question: str) -> tuple[str, WebDriver]:
|
def browse_website(url: str, question: str) -> Tuple[str, WebDriver]:
|
||||||
"""Browse a website and return the answer and links to the user
|
"""Browse a website and return the answer and links to the user
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -24,7 +25,7 @@ def browse_website(url: str, question: str) -> tuple[str, WebDriver]:
|
|||||||
question (str): The question asked by the user
|
question (str): The question asked by the user
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
tuple[str, WebDriver]: The answer and links to the user and the webdriver
|
Tuple[str, WebDriver]: The answer and links to the user and the webdriver
|
||||||
"""
|
"""
|
||||||
driver, text = scrape_text_with_selenium(url)
|
driver, text = scrape_text_with_selenium(url)
|
||||||
add_header(driver)
|
add_header(driver)
|
||||||
@@ -38,14 +39,14 @@ def browse_website(url: str, question: str) -> tuple[str, WebDriver]:
|
|||||||
return f"Answer gathered from website: {summary_text} \n \n Links: {links}", driver
|
return f"Answer gathered from website: {summary_text} \n \n Links: {links}", driver
|
||||||
|
|
||||||
|
|
||||||
def scrape_text_with_selenium(url: str) -> tuple[WebDriver, str]:
|
def scrape_text_with_selenium(url: str) -> Tuple[WebDriver, str]:
|
||||||
"""Scrape text from a website using selenium
|
"""Scrape text from a website using selenium
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
url (str): The url of the website to scrape
|
url (str): The url of the website to scrape
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
tuple[WebDriver, str]: The webdriver and the text scraped from the website
|
Tuple[WebDriver, str]: The webdriver and the text scraped from the website
|
||||||
"""
|
"""
|
||||||
logging.getLogger("selenium").setLevel(logging.CRITICAL)
|
logging.getLogger("selenium").setLevel(logging.CRITICAL)
|
||||||
|
|
||||||
@@ -77,14 +78,14 @@ def scrape_text_with_selenium(url: str) -> tuple[WebDriver, str]:
|
|||||||
return driver, text
|
return driver, text
|
||||||
|
|
||||||
|
|
||||||
def scrape_links_with_selenium(driver: WebDriver) -> list[str]:
|
def scrape_links_with_selenium(driver: WebDriver) -> List[str]:
|
||||||
"""Scrape links from a website using selenium
|
"""Scrape links from a website using selenium
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
driver (WebDriver): The webdriver to use to scrape the links
|
driver (WebDriver): The webdriver to use to scrape the links
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list[str]: The links scraped from the website
|
List[str]: The links scraped from the website
|
||||||
"""
|
"""
|
||||||
page_source = driver.page_source
|
page_source = driver.page_source
|
||||||
soup = BeautifulSoup(page_source, "html.parser")
|
soup = BeautifulSoup(page_source, "html.parser")
|
||||||
@@ -109,26 +110,26 @@ def close_browser(driver: WebDriver) -> None:
|
|||||||
driver.quit()
|
driver.quit()
|
||||||
|
|
||||||
|
|
||||||
def extract_hyperlinks(soup: BeautifulSoup) -> list[tuple[str, str]]:
|
def extract_hyperlinks(soup: BeautifulSoup) -> List[Tuple[str, str]]:
|
||||||
"""Extract hyperlinks from a BeautifulSoup object
|
"""Extract hyperlinks from a BeautifulSoup object
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
soup (BeautifulSoup): The BeautifulSoup object to extract the hyperlinks from
|
soup (BeautifulSoup): The BeautifulSoup object to extract the hyperlinks from
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list[tuple[str, str]]: The hyperlinks extracted from the BeautifulSoup object
|
List[Tuple[str, str]]: The hyperlinks extracted from the BeautifulSoup object
|
||||||
"""
|
"""
|
||||||
return [(link.text, link["href"]) for link in soup.find_all("a", href=True)]
|
return [(link.text, link["href"]) for link in soup.find_all("a", href=True)]
|
||||||
|
|
||||||
|
|
||||||
def format_hyperlinks(hyperlinks: list[tuple[str, str]]) -> list[str]:
|
def format_hyperlinks(hyperlinks: List[Tuple[str, str]]) -> List[str]:
|
||||||
"""Format hyperlinks to be displayed to the user
|
"""Format hyperlinks to be displayed to the user
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
hyperlinks (list[tuple[str, str]]): The hyperlinks to format
|
hyperlinks (List[Tuple[str, str]]): The hyperlinks to format
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list[str]: The formatted hyperlinks
|
List[str]: The formatted hyperlinks
|
||||||
"""
|
"""
|
||||||
return [f"{link_text} ({link_url})" for link_text, link_url in hyperlinks]
|
return [f"{link_text} ({link_url})" for link_text, link_url in hyperlinks]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user