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 Bossuyt1b49c1d37aba
diff --cc scripts/browse.pyindex 6ef35ae896,9e93c55a33..a4a417447b--- a/scripts/browse.py+++ b/scripts/browse.py@@@ -6,11 -5,8 +6,12 @@@ from llm_utils import create_chat_complfrom urllib.parse import urlparse, urljoincfg = Config()+memory = get_memory(cfg)++session = requests.Session()+session.headers.update({'User-Agent': cfg.user_agent})+# Function to check if the URL is validdef is_valid_url(url):try:@@@ -37,31 -26,40 +31,40 @@@ def check_local_file_access(url)local_prefixes = ['file:///', 'file://localhost', 'http://localhost', 'https://localhost']return any(url.startswith(prefix) for prefix in local_prefixes)- def scrape_text(url):- """Scrape text from a webpage"""- # Basic check if the URL is valid- if not url.startswith('http'):- return "Error: Invalid URL"- # Restrict access to local files- if check_local_file_access(url):- return "Error: Access to local files is restricted"-def get_response(url, headers=cfg.user_agent_header, timeout=10):++def get_response(url, timeout=10):+ try:+ # Restrict access to local files+ if check_local_file_access(url):+ raise ValueError('Access to local files is restricted')++ # Most basic check if the URL is valid:+ if not url.startswith('http://') and not url.startswith('https://'):+ raise ValueError('Invalid URL format')- # Validate the input URL- if not is_valid_url(url):- # Sanitize the input URLsanitized_url = sanitize_url(url)- # Make the request with a timeout and handle exceptions- response = make_request(sanitized_url)- response = requests.get(sanitized_url, headers=headers, timeout=timeout)++ response = session.get(sanitized_url, timeout=timeout)- if isinstance(response, str):- return response- else:- # Sanitize the input URL- sanitized_url = sanitize_url(url)+ # Check if the response contains an HTTP error+ if response.status_code >= 400:+ return None, "Error: HTTP " + str(response.status_code) + " error"++ return response, None+ except ValueError as ve:+ # Handle invalid URL format+ return None, "Error: " + str(ve)- response = session.get(sanitized_url)+ except requests.exceptions.RequestException as re:+ # Handle exceptions related to the HTTP request (e.g., connection errors, timeouts, etc.)+ return None, "Error: " + str(re)+++ def scrape_text(url):+ """Scrape text from a webpage"""+ response, error_message = get_response(url)+ if error_message:+ return error_messagesoup = BeautifulSoup(response.text, "html.parser")diff --cc scripts/config.pyindex 61848b59d4,ebf1b08b22..e76a2915fd--- a/scripts/config.py+++ b/scripts/config.py@@@ -41,18 -42,15 +42,17 @@@ class Config(metaclass=Singleton)self.smart_llm_model = os.getenv("SMART_LLM_MODEL", "gpt-4")self.fast_token_limit = int(os.getenv("FAST_TOKEN_LIMIT", 4000))self.smart_token_limit = int(os.getenv("SMART_TOKEN_LIMIT", 8000))+ self.browse_chunk_max_length = int(os.getenv("BROWSE_CHUNK_MAX_LENGTH", 8000))+ self.browse_summary_max_token = int(os.getenv("BROWSE_SUMMARY_MAX_TOKEN", 300))self.openai_api_key = os.getenv("OPENAI_API_KEY")+ self.temperature = int(os.getenv("TEMPERATURE", "1"))self.use_azure = Falseself.use_azure = os.getenv("USE_AZURE") == 'True'+ self.execute_local_commands = os.getenv('EXECUTE_LOCAL_COMMANDS', 'False') == 'True'+if self.use_azure:- self.openai_api_base = os.getenv("OPENAI_AZURE_API_BASE")- self.openai_api_version = os.getenv("OPENAI_AZURE_API_VERSION")- self.openai_deployment_id = os.getenv("OPENAI_AZURE_DEPLOYMENT_ID")- self.azure_chat_deployment_id = os.getenv("OPENAI_AZURE_CHAT_DEPLOYMENT_ID")- self.azure_embeddigs_deployment_id = os.getenv("OPENAI_AZURE_EMBEDDINGS_DEPLOYMENT_ID")+ self.load_azure_config()openai.api_type = "azure"openai.api_base = self.openai_api_baseopenai.api_version = self.openai_api_version