Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI args for ai_name, ai_role, and ai_goals #3250

Merged
merged 20 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions autogpt/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Main script for the autogpt package."""
from typing import Optional

import click


Expand Down Expand Up @@ -65,6 +67,22 @@
is_flag=True,
help="Installs external dependencies for 3rd party plugins.",
)
@click.option(
"--ai-name",
type=str,
help="AI name override",
)
@click.option(
"--ai-role",
type=str,
help="AI role override",
)
@click.option(
"--ai-goal",
type=str,
multiple=True,
help="AI goal override; may be used multiple times to pass multiple goals",
)
@click.pass_context
def main(
ctx: click.Context,
Expand All @@ -83,6 +101,9 @@ def main(
skip_news: bool,
workspace_directory: str,
install_plugin_deps: bool,
ai_name: Optional[str],
ai_role: Optional[str],
ai_goal: tuple[str],
) -> None:
"""
Welcome to AutoGPT an experimental open-source application showcasing the capabilities of the GPT-4 pushing the boundaries of AI.
Expand All @@ -109,6 +130,9 @@ def main(
skip_news,
workspace_directory,
install_plugin_deps,
ai_name,
ai_role,
ai_goal,
)


Expand Down
13 changes: 5 additions & 8 deletions autogpt/config/ai_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(
self,
ai_name: str = "",
ai_role: str = "",
ai_goals: list | None = None,
ai_goals: list[str] = [],
api_budget: float = 0.0,
) -> None:
"""
Expand All @@ -49,8 +49,6 @@ def __init__(
Returns:
None
"""
if ai_goals is None:
ai_goals = []
self.ai_name = ai_name
self.ai_role = ai_role
self.ai_goals = ai_goals
Expand All @@ -61,13 +59,12 @@ def __init__(
@staticmethod
def load(ai_settings_file: str = SAVE_FILE) -> "AIConfig":
"""
Returns class object with parameters (ai_name, ai_role, ai_goals, api_budget) loaded from
yaml file if yaml file exists,
else returns class with no parameters.
Returns class object with parameters (ai_name, ai_role, ai_goals, api_budget)
loaded from yaml file if yaml file exists, else returns class with no parameters.

Parameters:
ai_settings_file (int): The path to the config yaml file.
DEFAULT: "../ai_settings.yaml"
ai_settings_file (int): The path to the config yaml file.
DEFAULT: "../ai_settings.yaml"

Returns:
cls (object): An instance of given cls object
Expand Down
2 changes: 1 addition & 1 deletion autogpt/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import contextlib
import os
import re
from typing import Dict, Union
from typing import Dict, Optional, Union

import yaml
from colorama import Fore
Expand Down
15 changes: 11 additions & 4 deletions autogpt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import sys
from pathlib import Path
from typing import Optional

from colorama import Fore, Style

Expand Down Expand Up @@ -48,6 +49,9 @@ def run_auto_gpt(
skip_news: bool,
workspace_directory: str | Path,
install_plugin_deps: bool,
ai_name: Optional[str] = None,
ai_role: Optional[str] = None,
ai_goals: tuple[str] = tuple(),
):
# Configure logging before we do anything else.
logger.set_level(logging.DEBUG if debug else logging.INFO)
Expand Down Expand Up @@ -154,11 +158,14 @@ def run_auto_gpt(
f"reason - {command.disabled_reason or 'Disabled by current config.'}"
)

ai_name = ""
ai_config = construct_main_ai_config(config)
ai_config = construct_main_ai_config(
config,
name=ai_name,
role=ai_role,
goals=ai_goals,
)
ai_config.command_registry = command_registry
if ai_config.ai_name:
ai_name = ai_config.ai_name
ai_name = ai_config.ai_name
# print(prompt)
# Initialize variables
next_action_count = 0
Expand Down
28 changes: 24 additions & 4 deletions autogpt/prompts/prompt.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from colorama import Fore

from autogpt.config.ai_config import AIConfig
Expand Down Expand Up @@ -42,14 +44,32 @@ def build_default_prompt_generator(config: Config) -> PromptGenerator:
return prompt_generator


def construct_main_ai_config(config: Config) -> AIConfig:
def construct_main_ai_config(
config: Config,
name: Optional[str] = None,
role: Optional[str] = None,
goals: tuple[str] = tuple(),
) -> AIConfig:
"""Construct the prompt for the AI to respond to

Returns:
str: The prompt string
"""
ai_config = AIConfig.load(config.ai_settings_file)
if config.skip_reprompt and ai_config.ai_name:

# Apply overrides
if name:
ai_config.ai_name = name
if role:
ai_config.ai_role = role
if goals:
ai_config.ai_goals = list(goals)

if (
all([name, role, goals])
or config.skip_reprompt
and all([ai_config.ai_name, ai_config.ai_role, ai_config.ai_goals])
):
logger.typewriter_log("Name :", Fore.GREEN, ai_config.ai_name)
logger.typewriter_log("Role :", Fore.GREEN, ai_config.ai_role)
logger.typewriter_log("Goals:", Fore.GREEN, f"{ai_config.ai_goals}")
Expand All @@ -58,7 +78,7 @@ def construct_main_ai_config(config: Config) -> AIConfig:
Fore.GREEN,
"infinite" if ai_config.api_budget <= 0 else f"${ai_config.api_budget}",
)
elif ai_config.ai_name:
elif all([ai_config.ai_name, ai_config.ai_role, ai_config.ai_goals]):
logger.typewriter_log(
"Welcome back! ",
Fore.GREEN,
Expand All @@ -77,7 +97,7 @@ def construct_main_ai_config(config: Config) -> AIConfig:
if should_continue.lower() == config.exit_key:
ai_config = AIConfig()

if not ai_config.ai_name:
if any([not ai_config.ai_name, not ai_config.ai_role, not ai_config.ai_goals]):
ai_config = prompt_user(config)
ai_config.save(config.ai_settings_file)

Expand Down
121 changes: 76 additions & 45 deletions autogpt/setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Set up the AI and its goals"""
import re
from typing import Optional

from colorama import Fore, Style
from jinja2 import Template
Expand All @@ -17,14 +18,18 @@
)


def prompt_user(config: Config) -> AIConfig:
def prompt_user(
config: Config, ai_config_template: Optional[AIConfig] = None
) -> AIConfig:
"""Prompt the user for input

Params:
config (Config): The Config object
ai_config_template (AIConfig): The AIConfig object to use as a template

Returns:
AIConfig: The AIConfig object tailored to the user's input
"""
ai_name = ""
ai_config = None

# Construct the prompt
logger.typewriter_log(
Expand All @@ -34,29 +39,39 @@ def prompt_user(config: Config) -> AIConfig:
speak_text=True,
)

# Get user desire
logger.typewriter_log(
"Create an AI-Assistant:",
Fore.GREEN,
"input '--manual' to enter manual mode.",
speak_text=True,
ai_config_template_provided = ai_config_template is not None and any(
[
ai_config_template.ai_goals,
ai_config_template.ai_name,
ai_config_template.ai_role,
]
)

user_desire = utils.clean_input(
config, f"{Fore.LIGHTBLUE_EX}I want Auto-GPT to{Style.RESET_ALL}: "
)
user_desire = ""
if not ai_config_template_provided:
# Get user desire if command line overrides have not been passed in
logger.typewriter_log(
"Create an AI-Assistant:",
Fore.GREEN,
"input '--manual' to enter manual mode.",
speak_text=True,
)

user_desire = utils.clean_input(
config, f"{Fore.LIGHTBLUE_EX}I want Auto-GPT to{Style.RESET_ALL}: "
)

if user_desire == "":
if user_desire.strip() == "":
user_desire = DEFAULT_USER_DESIRE_PROMPT # Default prompt

# If user desire contains "--manual"
if "--manual" in user_desire:
# If user desire contains "--manual" or we have overridden any of the AI configuration
if "--manual" in user_desire or ai_config_template_provided:
logger.typewriter_log(
"Manual Mode Selected",
Fore.GREEN,
speak_text=True,
)
return generate_aiconfig_manual(config)
return generate_aiconfig_manual(config, ai_config_template)

else:
try:
Expand All @@ -72,14 +87,20 @@ def prompt_user(config: Config) -> AIConfig:
return generate_aiconfig_manual(config)


def generate_aiconfig_manual(config: Config) -> AIConfig:
def generate_aiconfig_manual(
config: Config, ai_config_template: Optional[AIConfig] = None
) -> AIConfig:
"""
Interactively create an AI configuration by prompting the user to provide the name, role, and goals of the AI.

This function guides the user through a series of prompts to collect the necessary information to create
an AIConfig object. The user will be asked to provide a name and role for the AI, as well as up to five
goals. If the user does not provide a value for any of the fields, default values will be used.

Params:
config (Config): The Config object
ai_config_template (AIConfig): The AIConfig object to use as a template

Returns:
AIConfig: An AIConfig object containing the user-defined or default AI name, role, and goals.
"""
Expand All @@ -93,46 +114,56 @@ def generate_aiconfig_manual(config: Config) -> AIConfig:
speak_text=True,
)

# Get AI Name from User
logger.typewriter_log(
"Name your AI: ", Fore.GREEN, "For example, 'Entrepreneur-GPT'"
)
ai_name = utils.clean_input(config, "AI Name: ")
if ai_config_template and ai_config_template.ai_name:
ai_name = ai_config_template.ai_name
else:
ai_name = ""
# Get AI Name from User
logger.typewriter_log(
"Name your AI: ", Fore.GREEN, "For example, 'Entrepreneur-GPT'"
)
ai_name = utils.clean_input(config, "AI Name: ")
if ai_name == "":
ai_name = "Entrepreneur-GPT"

logger.typewriter_log(
f"{ai_name} here!", Fore.LIGHTBLUE_EX, "I am at your service.", speak_text=True
)

# Get AI Role from User
logger.typewriter_log(
"Describe your AI's role: ",
Fore.GREEN,
"For example, 'an AI designed to autonomously develop and run businesses with"
" the sole goal of increasing your net worth.'",
)
ai_role = utils.clean_input(config, f"{ai_name} is: ")
if ai_config_template and ai_config_template.ai_role:
ai_role = ai_config_template.ai_role
else:
# Get AI Role from User
logger.typewriter_log(
"Describe your AI's role: ",
Fore.GREEN,
"For example, 'an AI designed to autonomously develop and run businesses with"
" the sole goal of increasing your net worth.'",
)
ai_role = utils.clean_input(config, f"{ai_name} is: ")
if ai_role == "":
ai_role = "an AI designed to autonomously develop and run businesses with the"
" sole goal of increasing your net worth."

# Enter up to 5 goals for the AI
logger.typewriter_log(
"Enter up to 5 goals for your AI: ",
Fore.GREEN,
"For example: \nIncrease net worth, Grow Twitter Account, Develop and manage"
" multiple businesses autonomously'",
)
logger.info("Enter nothing to load defaults, enter nothing when finished.")
ai_goals = []
for i in range(5):
ai_goal = utils.clean_input(
config, f"{Fore.LIGHTBLUE_EX}Goal{Style.RESET_ALL} {i+1}: "
if ai_config_template and ai_config_template.ai_goals:
ai_goals = ai_config_template.ai_goals
else:
# Enter up to 5 goals for the AI
logger.typewriter_log(
"Enter up to 5 goals for your AI: ",
Fore.GREEN,
"For example: \nIncrease net worth, Grow Twitter Account, Develop and manage"
" multiple businesses autonomously'",
)
if ai_goal == "":
break
ai_goals.append(ai_goal)
logger.info("Enter nothing to load defaults, enter nothing when finished.")
ai_goals = []
for i in range(5):
ai_goal = utils.clean_input(
config, f"{Fore.LIGHTBLUE_EX}Goal{Style.RESET_ALL} {i+1}: "
)
if ai_goal == "":
break
ai_goals.append(ai_goal)
if not ai_goals:
ai_goals = [
"Increase net worth",
Expand Down
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if $PYTHON_CMD -c "import sys; sys.exit(sys.version_info < (3, 10))"; then
echo Installing missing packages...
$PYTHON_CMD -m pip install -r requirements.txt
fi
$PYTHON_CMD -m autogpt $@
$PYTHON_CMD -m autogpt "$@"
read -p "Press any key to continue..."
else
echo "Python 3.10 or higher is required to run Auto GPT."
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/data/test_ai_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ai_goals:
- Test goal 1
ai_name: testGPT
ai_role: testRole
api_budget: 1.0