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 branch 'master' into add_website_memory

Maiko Bossuyt3a2ccbd02f57
diff --cc .env.template
index 0953fac938,4694aca085..0aec7b10c5
--- a/.env.template
+++ b/.env.template
@@@ -15,5 -17,4 +17,6 @@@ OPENAI_AZURE_EMBEDDINGS_DEPLOYMENT_ID=d
IMAGE_PROVIDER=dalle
HUGGINGFACE_API_TOKEN=
USE_MAC_OS_TTS=False
-MEMORY_BACKEND=local
+BROWSE_CHUNK_MAX_LENGTH=4000
- BROWSE_SUMMARY_MAX_TOKEN=300
++BROWSE_SUMMARY_MAX_TOKEN=300
++MEMORY_BACKEND=local
diff --cc scripts/browse.py
index 5f4aafe678,b936c5b197..6ef35ae896
--- a/scripts/browse.py
+++ b/scripts/browse.py
@@@ -1,15 -1,32 +1,37 @@@
import requests
from bs4 import BeautifulSoup
+from memory import get_memory
from config import Config
from llm_utils import create_chat_completion
+ from urllib.parse import urlparse, urljoin
cfg = Config()
+memory = get_memory(cfg)
+
+session = requests.Session()
+session.headers.update({'User-Agent': cfg.user_agent})
+ # Function to check if the URL is valid
+ def is_valid_url(url):
+ try:
+ result = urlparse(url)
+ return all([result.scheme, result.netloc])
+ except ValueError:
+ return False
+
+ # Function to sanitize the URL
+ def sanitize_url(url):
+ return urljoin(url, urlparse(url).path)
+
+ # Function to make a request with a specified timeout and handle exceptions
+ def make_request(url, timeout=10):
+ try:
- response = requests.get(url, headers=cfg.user_agent_header, timeout=timeout)
++ response = session.get(url, timeout=timeout)
+ response.raise_for_status()
+ return response
+ except requests.exceptions.RequestException as e:
+ return "Error: " + str(e)
+
# Define and check for local file address prefixes
def check_local_file_access(url):
local_prefixes = ['file:///', 'file://localhost', 'http://localhost', 'https://localhost']
@@@ -24,15 -41,22 +46,22 @@@ def scrape_text(url)
# Restrict access to local files
if check_local_file_access(url):
return "Error: Access to local files is restricted"
-
- try:
- response = session.get(url)
- except requests.exceptions.RequestException as e:
- return "Error: " + str(e)
- # Check if the response contains an HTTP error
- if response.status_code >= 400:
- return "Error: HTTP " + str(response.status_code) + " error"
+ # Validate the input URL
+ if not is_valid_url(url):
+ # Sanitize the input URL
+ sanitized_url = sanitize_url(url)
+
+ # Make the request with a timeout and handle exceptions
+ response = make_request(sanitized_url)
+
+ if isinstance(response, str):
+ return response
+ else:
+ # Sanitize the input URL
+ sanitized_url = sanitize_url(url)
+
- response = requests.get(sanitized_url, headers=cfg.user_agent_header)
++ response = session.get(sanitized_url)
soup = BeautifulSoup(response.text, "html.parser")