From 773324dcd6f784c45151d11f515a28080c74694e Mon Sep 17 00:00:00 2001 From: chao ma Date: Sat, 15 Apr 2023 12:18:19 +0800 Subject: [PATCH 01/11] feat: Add support for running Chrome in Headless mode. Add headless mode support for Chrome and refactor web page text extraction --- .env.template | 3 +++ autogpt/config.py | 1 + autogpt/web.py | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/.env.template b/.env.template index 22bf8d74..89ae0a9b 100644 --- a/.env.template +++ b/.env.template @@ -121,3 +121,6 @@ USE_BRIAN_TTS=False ELEVENLABS_API_KEY=your-elevenlabs-api-key ELEVENLABS_VOICE_1_ID=your-voice-id-1 ELEVENLABS_VOICE_2_ID=your-voice-id-2 + +# Chrome Headless Mode +HEADLESS_BROWSER=True diff --git a/autogpt/config.py b/autogpt/config.py index 26132a5a..a2da05aa 100644 --- a/autogpt/config.py +++ b/autogpt/config.py @@ -86,6 +86,7 @@ class Config(metaclass=Singleton): "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", ) + 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", "") diff --git a/autogpt/web.py b/autogpt/web.py index 355f7fd3..fb25b9f2 100644 --- a/autogpt/web.py +++ b/autogpt/web.py @@ -31,7 +31,12 @@ def scrape_text_with_selenium(url): logging.getLogger("selenium").setLevel(logging.CRITICAL) options = Options() + if cfg.headless_browser: + options.add_argument('--headless') + options.add_argument('--disable-gpu') + options.add_argument('--no-sandbox') 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" ) driver = webdriver.Chrome( From d6b1aa677d08aa450cad3af9df20fb21b408e1d4 Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Tue, 18 Apr 2023 16:15:37 +0200 Subject: [PATCH 02/11] consolidate browser settings --- .env.template | 10 +++++----- autogpt/commands/web_selenium.py | 2 +- autogpt/config/config.py | 9 ++++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.env.template b/.env.template index 68392d76..855cb91f 100644 --- a/.env.template +++ b/.env.template @@ -9,9 +9,6 @@ BROWSE_CHUNK_MAX_LENGTH=8192 # 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" # AI_SETTINGS_FILE - Specifies which AI Settings file to use (defaults to ai_settings.yaml) AI_SETTINGS_FILE=ai_settings.yaml -# USE_WEB_BROWSER - Sets the web-browser drivers to use with selenium (defaults to chrome). -# Note: set this to either 'chrome', 'firefox', or 'safari' depending on your current browser -# USE_WEB_BROWSER=chrome ################################################################################ ### LLM PROVIDER @@ -138,8 +135,11 @@ GITHUB_USERNAME=your-github-username ################################################################################ ### BROWSER -# HEADLESS_BROWSER - Whether to run the browser in headless mode -HEADLESS_BROWSER=True +# USE_WEB_BROWSER - Sets the web-browser drivers to use with selenium (defaults to chrome). +# HEADLESS_BROWSER - Whether to run the browser in headless mode (defaults to True) +# Note: set this to either 'chrome', 'firefox', or 'safari' depending on your current browser +# USE_WEB_BROWSER=chrome +# HEADLESS_BROWSER=True ### GOOGLE # GOOGLE_API_KEY - Google API key (Example: my-google-api-key) diff --git a/autogpt/commands/web_selenium.py b/autogpt/commands/web_selenium.py index 27706403..11bdfeb1 100644 --- a/autogpt/commands/web_selenium.py +++ b/autogpt/commands/web_selenium.py @@ -83,7 +83,7 @@ def scrape_text_with_selenium(url: str) -> tuple[WebDriver, str]: options.add_argument("--remote-debugging-port=9222") options.add_argument("--no-sandbox") - if CFG.headless_browser: + if CFG.selenium_headless: options.add_argument("--headless") options.add_argument("--disable-gpu") diff --git a/autogpt/config/config.py b/autogpt/config/config.py index 7e82627d..acf41c44 100644 --- a/autogpt/config/config.py +++ b/autogpt/config/config.py @@ -25,7 +25,6 @@ class Config(metaclass=Singleton): self.skip_reprompt = False self.allow_downloads = False - self.selenium_web_browser = os.getenv("USE_WEB_BROWSER", "chrome") self.ai_settings_file = os.getenv("AI_SETTINGS_FILE", "ai_settings.yaml") self.fast_llm_model = os.getenv("FAST_LLM_MODEL", "gpt-3.5-turbo") self.smart_llm_model = os.getenv("SMART_LLM_MODEL", "gpt-4") @@ -87,7 +86,11 @@ class Config(metaclass=Singleton): "HUGGINGFACE_AUDIO_TO_TEXT_MODEL" ) - # User agent headers to use when browsing web + # Selenium browser settings + self.selenium_web_browser = os.getenv("USE_WEB_BROWSER", "chrome") + self.selenium_headless = os.getenv("HEADLESS_BROWSER", "True") == "True" + + # User agent header to use when making HTTP requests # Some websites might just completely deny request with an error code if # no user agent was found. self.user_agent = os.getenv( @@ -95,7 +98,7 @@ class Config(metaclass=Singleton): "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", "") From 4a077909108c7089e8eb688ea12ddeb087483ed9 Mon Sep 17 00:00:00 2001 From: Richard Beales Date: Tue, 18 Apr 2023 20:09:07 +0100 Subject: [PATCH 03/11] Added ability to output news/announcements on startup --- BULLETIN.md | 2 ++ autogpt/cli.py | 12 ++++++++++++ autogpt/config/config.py | 1 + autogpt/configurator.py | 6 +++++- autogpt/utils.py | 9 +++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 BULLETIN.md diff --git a/BULLETIN.md b/BULLETIN.md new file mode 100644 index 00000000..735048dd --- /dev/null +++ b/BULLETIN.md @@ -0,0 +1,2 @@ +Welcome to Auto-GPT! We'll keep you informed of the latest news and features by printing messages here. +If you don't wish to see this message, you can run Auto-GPT with the --skip-news flag \ No newline at end of file diff --git a/autogpt/cli.py b/autogpt/cli.py index 8ed9abb0..323c126b 100644 --- a/autogpt/cli.py +++ b/autogpt/cli.py @@ -42,6 +42,11 @@ import click is_flag=True, help="Dangerous: Allows Auto-GPT to download files natively.", ) +@click.option( + "--skip-news", + is_flag=True, + help="Specifies whether to suppress the output of latest news on startup.", +) @click.pass_context def main( ctx: click.Context, @@ -56,6 +61,7 @@ def main( memory_type: str, browser_name: str, allow_downloads: bool, + skip_news: bool ) -> None: """ Welcome to AutoGPT an experimental open-source application showcasing the capabilities of the GPT-4 pushing the boundaries of AI. @@ -73,6 +79,7 @@ def main( from autogpt.logs import logger from autogpt.memory import get_memory from autogpt.prompt import construct_prompt + from autogpt.utils import get_latest_bulletin if ctx.invoked_subcommand is None: cfg = Config() @@ -90,9 +97,14 @@ def main( memory_type, browser_name, allow_downloads, + skip_news ) logger.set_level(logging.DEBUG if cfg.debug_mode else logging.INFO) ai_name = "" + if not cfg.skip_news: + motd = get_latest_bulletin() + if motd: + logger.typewriter_log("NEWS: ", Fore.GREEN, motd) system_prompt = construct_prompt() # print(prompt) # Initialize variables diff --git a/autogpt/config/config.py b/autogpt/config/config.py index bc75b031..763882ec 100644 --- a/autogpt/config/config.py +++ b/autogpt/config/config.py @@ -24,6 +24,7 @@ class Config(metaclass=Singleton): self.speak_mode = False self.skip_reprompt = False self.allow_downloads = False + self.skip_news = False self.selenium_web_browser = os.getenv("USE_WEB_BROWSER", "chrome") self.ai_settings_file = os.getenv("AI_SETTINGS_FILE", "ai_settings.yaml") diff --git a/autogpt/configurator.py b/autogpt/configurator.py index 247cdac9..79b0bd0b 100644 --- a/autogpt/configurator.py +++ b/autogpt/configurator.py @@ -22,6 +22,7 @@ def create_config( memory_type: str, browser_name: str, allow_downloads: bool, + skip_news: bool ) -> None: """Updates the config object with the given arguments. @@ -37,7 +38,7 @@ def create_config( memory_type (str): The type of memory backend to use browser_name (str): The name of the browser to use when using selenium to scrape the web allow_downloads (bool): Whether to allow Auto-GPT to download files natively - + skips_news (bool): Whether to suppress the output of latest news on startup """ CFG.set_debug_mode(False) CFG.set_continuous_mode(False) @@ -126,5 +127,8 @@ def create_config( ) CFG.allow_downloads = True + if skip_news: + CFG.skip_news = True + if browser_name: CFG.selenium_web_browser = browser_name diff --git a/autogpt/utils.py b/autogpt/utils.py index db7d3321..c7b35b11 100644 --- a/autogpt/utils.py +++ b/autogpt/utils.py @@ -1,5 +1,6 @@ import yaml from colorama import Fore +import requests def clean_input(prompt: str = ""): @@ -37,3 +38,11 @@ def readable_file_size(size, decimal_places=2): break size /= 1024.0 return f"{size:.{decimal_places}f} {unit}" + +def get_latest_bulletin() -> str: + try: + response = requests.get('https://raw.githubusercontent.com/Significant-Gravitas/Auto-GPT/master/BULLETIN.md') + if response.status_code == 200: + return response.text + except: + return "" From 90e6a55e378bc80352f01eb08122300b4d1a64ec Mon Sep 17 00:00:00 2001 From: Richard Beales Date: Tue, 18 Apr 2023 20:11:26 +0100 Subject: [PATCH 04/11] Black formatting --- autogpt/cli.py | 4 ++-- autogpt/configurator.py | 2 +- autogpt/utils.py | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/autogpt/cli.py b/autogpt/cli.py index 323c126b..a69a53ac 100644 --- a/autogpt/cli.py +++ b/autogpt/cli.py @@ -61,7 +61,7 @@ def main( memory_type: str, browser_name: str, allow_downloads: bool, - skip_news: bool + skip_news: bool, ) -> None: """ Welcome to AutoGPT an experimental open-source application showcasing the capabilities of the GPT-4 pushing the boundaries of AI. @@ -97,7 +97,7 @@ def main( memory_type, browser_name, allow_downloads, - skip_news + skip_news, ) logger.set_level(logging.DEBUG if cfg.debug_mode else logging.INFO) ai_name = "" diff --git a/autogpt/configurator.py b/autogpt/configurator.py index 79b0bd0b..1dc3be12 100644 --- a/autogpt/configurator.py +++ b/autogpt/configurator.py @@ -22,7 +22,7 @@ def create_config( memory_type: str, browser_name: str, allow_downloads: bool, - skip_news: bool + skip_news: bool, ) -> None: """Updates the config object with the given arguments. diff --git a/autogpt/utils.py b/autogpt/utils.py index c7b35b11..3dc42871 100644 --- a/autogpt/utils.py +++ b/autogpt/utils.py @@ -39,9 +39,12 @@ def readable_file_size(size, decimal_places=2): size /= 1024.0 return f"{size:.{decimal_places}f} {unit}" + def get_latest_bulletin() -> str: try: - response = requests.get('https://raw.githubusercontent.com/Significant-Gravitas/Auto-GPT/master/BULLETIN.md') + response = requests.get( + "https://raw.githubusercontent.com/Significant-Gravitas/Auto-GPT/master/BULLETIN.md" + ) if response.status_code == 200: return response.text except: From 913c933e8cf43873d49c2a08d9ff9ed77e617d61 Mon Sep 17 00:00:00 2001 From: Richard Beales Date: Tue, 18 Apr 2023 20:13:31 +0100 Subject: [PATCH 05/11] isort --- autogpt/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autogpt/utils.py b/autogpt/utils.py index 3dc42871..ab7fe82a 100644 --- a/autogpt/utils.py +++ b/autogpt/utils.py @@ -1,6 +1,6 @@ +import requests import yaml from colorama import Fore -import requests def clean_input(prompt: str = ""): From 88ebebf74fecf43703a476fdce27ca66d4295ea3 Mon Sep 17 00:00:00 2001 From: Richard Beales Date: Tue, 18 Apr 2023 21:45:09 +0100 Subject: [PATCH 06/11] Implement suggestions from pi - save current news to file --- .gitignore | 3 +++ autogpt/utils.py | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 26d7e5a3..85111ce9 100644 --- a/.gitignore +++ b/.gitignore @@ -157,3 +157,6 @@ vicuna-* # mac .DS_Store + +# news +CURRENT_BULLETIN.md \ No newline at end of file diff --git a/autogpt/utils.py b/autogpt/utils.py index ab7fe82a..0e4ce5e9 100644 --- a/autogpt/utils.py +++ b/autogpt/utils.py @@ -1,3 +1,5 @@ +import os + import requests import yaml from colorama import Fore @@ -40,12 +42,26 @@ def readable_file_size(size, decimal_places=2): return f"{size:.{decimal_places}f} {unit}" -def get_latest_bulletin() -> str: +def get_bulletin_from_web() -> str: try: response = requests.get( - "https://raw.githubusercontent.com/Significant-Gravitas/Auto-GPT/master/BULLETIN.md" + "https://raw.githubusercontent.com/Significant-Gravitas/Auto-GPT/master/CONTRIBUTING.md" ) if response.status_code == 200: return response.text except: return "" + + +def get_latest_bulletin() -> str: + exists = os.path.exists("CURRENT_BULLETIN.md") + current_bulletin = "" + if exists: + current_bulletin = open("CURRENT_BULLETIN.md", "r", encoding="utf-8").read() + new_bulletin = get_bulletin_from_web() + is_new_news = new_bulletin != current_bulletin + + if new_bulletin and is_new_news: + open("CURRENT_BULLETIN.md", "w", encoding="utf-8").write(new_bulletin) + return f" {Fore.RED}::UPDATED:: {Fore.CYAN}{new_bulletin}{Fore.RESET}" + return current_bulletin From 3ebe125d3f81f4f933b088276d28e21c60210eca Mon Sep 17 00:00:00 2001 From: Richard Beales Date: Tue, 18 Apr 2023 22:16:11 +0100 Subject: [PATCH 07/11] Bugfix - filename for announcement was wrong --- autogpt/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autogpt/utils.py b/autogpt/utils.py index 0e4ce5e9..0f52c060 100644 --- a/autogpt/utils.py +++ b/autogpt/utils.py @@ -45,7 +45,7 @@ def readable_file_size(size, decimal_places=2): def get_bulletin_from_web() -> str: try: response = requests.get( - "https://raw.githubusercontent.com/Significant-Gravitas/Auto-GPT/master/CONTRIBUTING.md" + "https://raw.githubusercontent.com/Significant-Gravitas/Auto-GPT/master/BULLETIN.md" ) if response.status_code == 200: return response.text From e2accab87e3b5d339cb5695eb55908ff52b235c3 Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Wed, 19 Apr 2023 01:27:29 +0200 Subject: [PATCH 08/11] Move to Python 3.10 & improve CI workflow (#2369) * Use Python 3.10 in CI, benchmark, devcontainer, docker config, .sourcery.yaml * Improve Python CI workflow --- .devcontainer/Dockerfile | 8 +++--- .github/workflows/benchmark.yml | 4 +-- .github/workflows/ci.yml | 46 +++++++++++++++++++++++---------- .sourcery.yaml | 4 +-- Dockerfile | 2 +- 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 379f6310..02f580a0 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,10 +1,10 @@ -# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster +# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3-bullseye, 3.10-bullseye, 3-buster, 3.10-buster ARG VARIANT=3-bullseye -FROM --platform=linux/amd64 python:3.8 +FROM --platform=linux/amd64 python:3.10 RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ # Remove imagemagick due to https://security-tracker.debian.org/tracker/CVE-2019-10131 - && apt-get purge -y imagemagick imagemagick-6-common + && apt-get purge -y imagemagick imagemagick-6-common # Temporary: Upgrade python packages due to https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-40897 # They are installed by the base image (python) which does not have the patch. @@ -25,4 +25,4 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ # && apt-get -y install --no-install-recommends # [Optional] Uncomment this line to install global node packages. -# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 \ No newline at end of file +# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index c5a42b2c..750366d8 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -9,11 +9,11 @@ jobs: environment: benchmark strategy: matrix: - python-version: [3.8] + python-version: ['3.10'] steps: - name: Check out repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2eb34b9d..f437a71c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,26 +2,24 @@ name: Python CI on: push: - branches: - - master + branches: [master] pull_request: - branches: - - '**' - pull_request_target: - branches: - - '**' + branches: [master] + +concurrency: + group: ${{ format('ci-{0}', format('pr-{0}', github.event.pull_request.number) || github.sha) }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: - build: + lint: runs-on: ubuntu-latest - strategy: matrix: - python-version: [3.8] + python-version: ['3.10'] steps: - name: Check out repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 @@ -34,16 +32,35 @@ jobs: pip install -r requirements.txt - name: Lint with flake8 - continue-on-error: false run: flake8 - name: Check black formatting - continue-on-error: false run: black . --check + if: success() || failure() - name: Check isort formatting - continue-on-error: false run: isort . --check + if: success() || failure() + + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.10'] + + steps: + - name: Check out repository + uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt - name: Run unittest tests with coverage run: | @@ -53,3 +70,4 @@ jobs: run: | coverage report coverage xml + if: success() || failure() diff --git a/.sourcery.yaml b/.sourcery.yaml index a7f5b9d7..da171e75 100644 --- a/.sourcery.yaml +++ b/.sourcery.yaml @@ -30,7 +30,7 @@ rule_settings: - refactoring - suggestion - comment - python_version: '3.9' # A string specifying the lowest Python version your project supports. Sourcery will not suggest refactorings requiring a higher Python version. + python_version: '3.10' # A string specifying the lowest Python version your project supports. Sourcery will not suggest refactorings requiring a higher Python version. # rules: # A list of custom rules Sourcery will include in its analysis. # - id: no-print-statements @@ -68,4 +68,4 @@ rule_settings: # proxy: # url: # ssl_certs_file: -# no_ssl_verify: false \ No newline at end of file +# no_ssl_verify: false diff --git a/Dockerfile b/Dockerfile index 09b5303d..83961549 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Use an official Python base image from the Docker Hub -FROM python:3.11-slim +FROM python:3.10-slim # Install git RUN apt-get -y update From 74aa4add1b066bcab5d1749a6f50898a576c9499 Mon Sep 17 00:00:00 2001 From: Will Callender <29266431+willcallender@users.noreply.github.com> Date: Tue, 18 Apr 2023 19:37:31 -0400 Subject: [PATCH 09/11] fix(python-run): prompt users to install Docker when execute_python_file encounters a Docker error (#2231) fix(python-run): make error message more explicit --------- Co-authored-by: Reinier van der Leer --- autogpt/commands/execute_code.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/autogpt/commands/execute_code.py b/autogpt/commands/execute_code.py index 95ba6122..11266f85 100644 --- a/autogpt/commands/execute_code.py +++ b/autogpt/commands/execute_code.py @@ -84,6 +84,12 @@ def execute_python_file(file: str) -> str: return logs + except docker.errors.DockerException as e: + print( + "Could not run the script in a container. If you haven't already, please install Docker https://docs.docker.com/get-docker/" + ) + return f"Error: {str(e)}" + except Exception as e: return f"Error: {str(e)}" From 24d5e1fc8aa5787c504294cc2280be45a6590a0a Mon Sep 17 00:00:00 2001 From: Drikus Roor Date: Wed, 19 Apr 2023 01:38:42 +0200 Subject: [PATCH 10/11] Ensure Python 3.10 & 3.11 compatability (#1815) CI: Ensure compatability with Python 3.10 & 3.11 --------- Co-authored-by: Reinier van der Leer --- .github/workflows/benchmark.yml | 2 +- .github/workflows/ci.yml | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 750366d8..53b6e7a0 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -9,7 +9,7 @@ jobs: environment: benchmark strategy: matrix: - python-version: ['3.10'] + python-version: ['3.10', '3.11'] steps: - name: Check out repository diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f437a71c..b37e7f00 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,18 +13,17 @@ concurrency: jobs: lint: runs-on: ubuntu-latest - strategy: - matrix: - python-version: ['3.10'] + env: + min-python-version: '3.10' steps: - name: Check out repository uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} + - name: Set up Python ${{ env.min-python-version }} uses: actions/setup-python@v2 with: - python-version: ${{ matrix.python-version }} + python-version: ${{ env.min-python-version }} - name: Install dependencies run: | @@ -46,7 +45,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.10'] + python-version: ['3.10', '3.11'] steps: - name: Check out repository From 9514919d376c9aca9ff678cac3a774bf807b2d30 Mon Sep 17 00:00:00 2001 From: Josh XT <102809327+Josh-XT@users.noreply.github.com> Date: Tue, 18 Apr 2023 19:54:38 -0400 Subject: [PATCH 11/11] Option to disable working directory restrictions (#1875) Remove restriction on working directory if RESTRICT_TO_WORKSPACE != True --------- Co-authored-by: Reinier van der Leer --- .env.template | 2 ++ autogpt/commands/file_operations.py | 3 +-- autogpt/config/config.py | 3 +++ autogpt/workspace.py | 8 ++++++-- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.env.template b/.env.template index 855cb91f..4fb09cf2 100644 --- a/.env.template +++ b/.env.template @@ -3,6 +3,8 @@ ################################################################################ # EXECUTE_LOCAL_COMMANDS - Allow local command execution (Example: False) EXECUTE_LOCAL_COMMANDS=False +# RESTRICT_TO_WORKSPACE - Restrict file operations to workspace ./auto_gpt_workspace (Default: True) +RESTRICT_TO_WORKSPACE=True # BROWSE_CHUNK_MAX_LENGTH - When browsing website, define the length of chunk stored in memory BROWSE_CHUNK_MAX_LENGTH=8192 # USER_AGENT - Define the user-agent used by the requests library to browse website (string) diff --git a/autogpt/commands/file_operations.py b/autogpt/commands/file_operations.py index 72b02b5d..ad145ec9 100644 --- a/autogpt/commands/file_operations.py +++ b/autogpt/commands/file_operations.py @@ -3,8 +3,7 @@ from __future__ import annotations import os import os.path -from pathlib import Path -from typing import Generator, List +from typing import Generator import requests from colorama import Back, Fore diff --git a/autogpt/config/config.py b/autogpt/config/config.py index 2fd300dd..1fe44edf 100644 --- a/autogpt/config/config.py +++ b/autogpt/config/config.py @@ -39,6 +39,9 @@ class Config(metaclass=Singleton): self.execute_local_commands = ( os.getenv("EXECUTE_LOCAL_COMMANDS", "False") == "True" ) + self.restrict_to_workspace = ( + os.getenv("RESTRICT_TO_WORKSPACE", "True") == "True" + ) if self.use_azure: self.load_azure_config() diff --git a/autogpt/workspace.py b/autogpt/workspace.py index 964a94d1..6fb0e311 100644 --- a/autogpt/workspace.py +++ b/autogpt/workspace.py @@ -3,6 +3,10 @@ from __future__ import annotations import os from pathlib import Path +from autogpt.config import Config + +CFG = Config() + # Set a dedicated folder for file I/O WORKSPACE_PATH = Path(os.getcwd()) / "auto_gpt_workspace" @@ -35,9 +39,9 @@ def safe_path_join(base: Path, *paths: str | Path) -> Path: """ joined_path = base.joinpath(*paths).resolve() - if not joined_path.is_relative_to(base): + if CFG.restrict_to_workspace and not joined_path.is_relative_to(base): raise ValueError( - f"Attempted to access path '{joined_path}' outside of working directory '{base}'." + f"Attempted to access path '{joined_path}' outside of workspace '{base}'." ) return joined_path