From 13bc4cc0d96c5e6bf29efe1773d1f5e48ff8c8c7 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Tue, 30 May 2023 13:48:03 -0400 Subject: [PATCH] ensure auto-gpt writes all files where we want --- projects/agpt.co/auto-gpt | 29 +++++++++++++++++++---------- projects/agpt.co/package.yml | 8 ++++++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/projects/agpt.co/auto-gpt b/projects/agpt.co/auto-gpt index d667c7b2..8f363093 100755 --- a/projects/agpt.co/auto-gpt +++ b/projects/agpt.co/auto-gpt @@ -1,18 +1,27 @@ -#!/usr/bin/python -import os +#!/bin/sh -# Get the XDG base directory path -xdg_base_dir = os.environ.get('XDG_DATA_HOME') or os.path.expanduser(os.path.join('~', '.local', 'share')) -shared_data_dir = os.path.join(xdg_base_dir, 'agpt.co') +set -e + +WD="${XDG_DATA_HOME:-$HOME/.local/share}/auto-gpt" # if the data directory doesn’t exist auto-gpt bails -os.makedirs(os.path.join(shared_data_dir, "data"), exist_ok=True) +mkdir -p "$WD"/data + +PREFIX="$(cd "$(dirname "$0")/../.." && pwd)" # change to this directory because auto-gpt assumes it is running # in its own checkout and is not suitable to be run from anywhere -os.chdir(shared_data_dir) +cd "$WD" -print(f"tea: OUTPUT WILL BE HERE: {shared_data_dir}") +if ! test -f .env; then + cp "$PREFIX"/share/env.template .env +fi -import autogpt.cli -autogpt.cli.main() + +echo "tea: auto-gpt output goes here: $WD" +echo "tea: auto-gpt config is here: $WD/.env" +echo "tea: You need to set \`OPENAI_API_KEY\` before running auto-gpt or add it to the above config" +echo "tea: unless you have access to GPT4 you need to run \`--gpt3only\`" +echo + +exec "$VIRTUAL_ENV"/bin/python -m autogpt --workspace-directory="$WD" "$@" diff --git a/projects/agpt.co/package.yml b/projects/agpt.co/package.yml index 18cdb250..e34ea2e8 100644 --- a/projects/agpt.co/package.yml +++ b/projects/agpt.co/package.yml @@ -25,9 +25,17 @@ build: ${{prefix}}/venv/lib/python{{deps.python.org.version.marketing}}/site-packages - python-venv.py {{prefix}}/bin/auto-gpt --requirements-txt + # still pretty new and thus provides no executable, so we made one - cp props/auto-gpt {{prefix}}/venv/bin + # this is broken and means any environment variable that is set is ignored + - sed -i.bak s/^OPENAI_API_KEY=your-openai-api-key$//g .env.template + + - | + mkdir {{prefix}}/share + cp .env.template {{prefix}}/share/env.template + provides: - bin/auto-gpt