diff --git a/babyagi.py b/babyagi.py index b5682367..28c44773 100755 --- a/babyagi.py +++ b/babyagi.py @@ -1,13 +1,13 @@ #!/usr/bin/env python3 import os -import openai -import pinecone import time import argparse +import importlib +import openai +import pinecone from collections import deque from typing import Dict, List from dotenv import load_dotenv -import os #Set Variables load_dotenv() @@ -30,26 +30,39 @@ # Run configuration -parser = argparse.ArgumentParser(add_help=False) +parser = argparse.ArgumentParser( + add_help=False, + formatter_class=argparse.RawDescriptionHelpFormatter, + epilog=""" +examples: + * start solving world hunger by creating initial list of tasks using GPT-4: + %(prog)s -t "Create initial list of tasks" -4 Solve world hunger + * join the work on solving world hunger using GPT-3: + %(prog)s -j Solve world hunger +""" +) parser.add_argument('objective', nargs='*', metavar='', help=''' -Main objective description. Doesn\'t need to be quoted. -If not specified, get OBJECTIVE in environment. +main objective description. Doesn\'t need to be quoted. +if not specified, get OBJECTIVE from environment. ''', default=[os.getenv("OBJECTIVE", "")]) parser.add_argument('-n', '--name', required=False, help=''' -BabyAGI instance name. -If not specified, get BABY_NAME in environment. +babyagi instance name. +if not specified, get BABY_NAME from environment. ''', default=os.getenv("BABY_NAME", "BabyAGI")) group = parser.add_mutually_exclusive_group() group.add_argument('-t', '--task', metavar='', help=''' -Initial task description. Must be quoted. -If not specified, get INITIAL_TASK in environment. +initial task description. must be quoted. +if not specified, get INITIAL_TASK from environment. ''', default=os.getenv("INITIAL_TASK", os.getenv("FIRST_TASK", ""))) group.add_argument('-j', '--join', action='store_true', help=''' -Join an existing objective. +join an existing objective. +install cooperative requirements. +''') +parser.add_argument('-4', '--gpt-4', dest='use_gpt4', action='store_true', help=''' +use GPT-4 instead of GPT-3 ''') -parser.add_argument('-4', '--gpt-4', dest='use_gpt4', action='store_true', help='Use GPT-4 instead of GPT-3') parser.add_argument('-h', '-?', '--help', action='help', help=''' -Show this help message and exit +show this help message and exit ''') args = parser.parse_args() @@ -60,7 +73,20 @@ parser.print_help() parser.exit() +def can_import(module_name): + try: + importlib.import_module(module_name) + return True + except ImportError: + return False + +module_name = "ray" JOIN_EXISTING_OBJECTIVE = args.join +if JOIN_EXISTING_OBJECTIVE and not can_import(module_name): + print("\033[91m\033[1m"+f"Package {module_name} not installed\nInstall: pip install -r requirements-cooperative.txt\n"+"\033[0m\033[0m") + parser.print_help() + parser.exit() + USE_GPT4 = args.use_gpt4 OBJECTIVE = ' '.join(args.objective).strip() diff --git a/requirements-cooperative.txt b/requirements-cooperative.txt new file mode 100644 index 00000000..35f4c4a9 --- /dev/null +++ b/requirements-cooperative.txt @@ -0,0 +1,2 @@ +-r requirements.txt +ray==2.3.1 \ No newline at end of file