forked from yoheinakajima/babyagi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
320 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
.env | ||
.idea | ||
.env.* | ||
env/ | ||
.venv | ||
venv/ | ||
|
||
.vscode/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
babyagi.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import os | ||
import sys | ||
import argparse | ||
|
||
# Extract the env filenames in the -e flag only | ||
# Ignore any other arguments | ||
def parse_dotenv_extensions(argv): | ||
env_argv = [] | ||
if '-e' in argv: | ||
tmp_argv = argv[argv.index('-e') + 1:] | ||
parsed_args = [] | ||
for arg in tmp_argv: | ||
if arg.startswith('-'): | ||
break | ||
parsed_args.append(arg) | ||
env_argv = ['-e'] + parsed_args | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-e', '--env', nargs='+', help=''' | ||
filenames for additional env variables to load | ||
''', default=os.getenv("DOTENV_EXTENSIONS", "").split(' ')) | ||
|
||
return parser.parse_args(env_argv).env | ||
|
||
def parse_arguments(): | ||
dotenv_extensions = parse_dotenv_extensions(sys.argv) | ||
# Check if we need to load any additional env files | ||
# This allows us to override the default .env file | ||
# and update the default values for any command line arguments | ||
if dotenv_extensions: | ||
from extensions.dotenvext import load_dotenv_extensions | ||
load_dotenv_extensions(parse_dotenv_extensions(sys.argv)) | ||
|
||
# Now parse the full command line arguments | ||
parser = argparse.ArgumentParser( | ||
add_help=False, | ||
) | ||
parser.add_argument('objective', nargs='*', metavar='<objective>', help=''' | ||
main objective description. Doesn\'t need to be quoted. | ||
if not specified, get objective from environment. | ||
''', default=[os.getenv("OBJECTIVE", "")]) | ||
parser.add_argument('-t', '--task', metavar='<initial task>', help=''' | ||
initial task description. must be quoted. | ||
if not specified, get initial_task from environment. | ||
''', default=os.getenv("INITIAL_TASK", os.getenv("FIRST_TASK", ""))) | ||
parser.add_argument('-4', '--gpt-4', dest='openai_api_model', action='store_const', const="gpt-4", help=''' | ||
use GPT-4 instead of the default GPT-3 model. | ||
''', default=os.getenv("OPENAI_API_MODEL", "gpt-3.5-turbo")) | ||
# This will parse -e again, which we want, because we need | ||
# to load those in the main file later as well | ||
parser.add_argument('-e', '--env', nargs='+', help=''' | ||
filenames for additional env variables to load | ||
''', default=os.getenv("DOTENV_EXTENSIONS", "").split(' ')) | ||
parser.add_argument('-h', '-?', '--help', action='help', help=''' | ||
show this help message and exit | ||
''') | ||
|
||
args = parser.parse_args() | ||
|
||
openai_api_model = args.openai_api_model | ||
|
||
dotenv_extensions = args.env | ||
|
||
objective = ' '.join(args.objective).strip() | ||
if not objective: | ||
print("\033[91m\033[1m"+"No objective specified or found in environment.\n"+"\033[0m\033[0m") | ||
parser.print_help() | ||
parser.exit() | ||
|
||
initial_task = args.task | ||
if not initial_task: | ||
print("\033[91m\033[1m"+"No initial task specified or found in environment.\n"+"\033[0m\033[0m") | ||
parser.print_help() | ||
parser.exit() | ||
|
||
return objective, initial_task, openai_api_model, dotenv_extensions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from dotenv import load_dotenv | ||
|
||
def load_dotenv_extensions(dotenv_files): | ||
for dotenv_file in dotenv_files: | ||
load_dotenv(dotenv_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
openai==0.27.2 | ||
argparse==1.4.0 | ||
openai==0.27.4 | ||
pinecone-client==2.2.1 | ||
pre-commit>=3.2.0 | ||
python-dotenv==1.0.0 |
Oops, something went wrong.