2023-04-15 12:56:23 +00:00
|
|
|
from colorama import Fore
|
2023-04-17 02:51:36 +00:00
|
|
|
|
2023-04-15 12:56:23 +00:00
|
|
|
from autogpt.config.ai_config import AIConfig
|
|
|
|
from autogpt.config.config import Config
|
2023-05-17 17:12:10 +00:00
|
|
|
from autogpt.config.prompt_config import PromptConfig
|
2023-05-25 18:31:11 +00:00
|
|
|
from autogpt.llm.api_manager import ApiManager
|
2023-04-15 12:56:23 +00:00
|
|
|
from autogpt.logs import logger
|
2023-04-16 03:15:34 +00:00
|
|
|
from autogpt.prompts.generator import PromptGenerator
|
2023-04-15 12:56:23 +00:00
|
|
|
from autogpt.setup import prompt_user
|
|
|
|
from autogpt.utils import clean_input
|
|
|
|
|
|
|
|
CFG = Config()
|
2023-04-11 16:09:59 +00:00
|
|
|
|
2023-06-10 00:25:03 +00:00
|
|
|
DEFAULT_TRIGGERING_PROMPT = "Determine exactly one command to use, and respond using the format specified above:"
|
2023-04-27 16:27:15 +00:00
|
|
|
|
2023-04-13 18:36:48 +00:00
|
|
|
|
2023-04-16 03:15:34 +00:00
|
|
|
def build_default_prompt_generator() -> PromptGenerator:
|
2023-04-11 16:15:45 +00:00
|
|
|
"""
|
2023-04-15 00:04:48 +00:00
|
|
|
This function generates a prompt string that includes various constraints,
|
|
|
|
commands, resources, and performance evaluations.
|
2023-04-13 18:36:48 +00:00
|
|
|
|
2023-04-11 16:15:45 +00:00
|
|
|
Returns:
|
|
|
|
str: The generated prompt string.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Initialize the PromptGenerator object
|
2023-04-11 16:09:59 +00:00
|
|
|
prompt_generator = PromptGenerator()
|
|
|
|
|
2023-05-17 17:12:10 +00:00
|
|
|
# Initialize the PromptConfig object and load the file set in the main config (default: prompts_settings.yaml)
|
|
|
|
prompt_config = PromptConfig(CFG.prompt_settings_file)
|
|
|
|
|
2023-04-11 16:15:45 +00:00
|
|
|
# Add constraints to the PromptGenerator object
|
2023-05-17 17:12:10 +00:00
|
|
|
for constraint in prompt_config.constraints:
|
|
|
|
prompt_generator.add_constraint(constraint)
|
2023-04-11 16:09:59 +00:00
|
|
|
|
2023-04-11 16:15:45 +00:00
|
|
|
# Add resources to the PromptGenerator object
|
2023-05-17 17:12:10 +00:00
|
|
|
for resource in prompt_config.resources:
|
|
|
|
prompt_generator.add_resource(resource)
|
2023-04-11 16:09:59 +00:00
|
|
|
|
2023-04-11 16:15:45 +00:00
|
|
|
# Add performance evaluations to the PromptGenerator object
|
2023-05-17 17:12:10 +00:00
|
|
|
for performance_evaluation in prompt_config.performance_evaluations:
|
|
|
|
prompt_generator.add_performance_evaluation(performance_evaluation)
|
|
|
|
|
2023-04-16 03:15:34 +00:00
|
|
|
return prompt_generator
|
2023-04-15 12:56:23 +00:00
|
|
|
|
|
|
|
|
2023-04-16 03:43:17 +00:00
|
|
|
def construct_main_ai_config() -> AIConfig:
|
2023-04-15 12:56:23 +00:00
|
|
|
"""Construct the prompt for the AI to respond to
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
str: The prompt string
|
|
|
|
"""
|
|
|
|
config = AIConfig.load(CFG.ai_settings_file)
|
|
|
|
if CFG.skip_reprompt and config.ai_name:
|
|
|
|
logger.typewriter_log("Name :", Fore.GREEN, config.ai_name)
|
|
|
|
logger.typewriter_log("Role :", Fore.GREEN, config.ai_role)
|
|
|
|
logger.typewriter_log("Goals:", Fore.GREEN, f"{config.ai_goals}")
|
2023-04-23 21:04:31 +00:00
|
|
|
logger.typewriter_log(
|
|
|
|
"API Budget:",
|
|
|
|
Fore.GREEN,
|
|
|
|
"infinite" if config.api_budget <= 0 else f"${config.api_budget}",
|
|
|
|
)
|
2023-04-15 12:56:23 +00:00
|
|
|
elif config.ai_name:
|
|
|
|
logger.typewriter_log(
|
|
|
|
"Welcome back! ",
|
|
|
|
Fore.GREEN,
|
|
|
|
f"Would you like me to return to being {config.ai_name}?",
|
|
|
|
speak_text=True,
|
|
|
|
)
|
|
|
|
should_continue = clean_input(
|
|
|
|
f"""Continue with the last settings?
|
|
|
|
Name: {config.ai_name}
|
|
|
|
Role: {config.ai_role}
|
|
|
|
Goals: {config.ai_goals}
|
2023-04-23 21:04:31 +00:00
|
|
|
API Budget: {"infinite" if config.api_budget <= 0 else f"${config.api_budget}"}
|
2023-04-27 19:26:47 +00:00
|
|
|
Continue ({CFG.authorise_key}/{CFG.exit_key}): """
|
2023-04-15 12:56:23 +00:00
|
|
|
)
|
2023-04-27 19:26:47 +00:00
|
|
|
if should_continue.lower() == CFG.exit_key:
|
2023-04-15 12:56:23 +00:00
|
|
|
config = AIConfig()
|
|
|
|
|
|
|
|
if not config.ai_name:
|
|
|
|
config = prompt_user()
|
2023-04-16 10:25:28 +00:00
|
|
|
config.save(CFG.ai_settings_file)
|
2023-04-15 12:56:23 +00:00
|
|
|
|
2023-05-15 23:34:48 +00:00
|
|
|
if CFG.restrict_to_workspace:
|
|
|
|
logger.typewriter_log(
|
|
|
|
"NOTE:All files/directories created by this agent can be found inside its workspace at:",
|
|
|
|
Fore.YELLOW,
|
|
|
|
f"{CFG.workspace_path}",
|
|
|
|
)
|
2023-04-23 21:04:31 +00:00
|
|
|
# set the total api budget
|
2023-04-26 16:37:49 +00:00
|
|
|
api_manager = ApiManager()
|
2023-04-23 21:04:31 +00:00
|
|
|
api_manager.set_total_budget(config.api_budget)
|
|
|
|
|
2023-04-23 05:36:10 +00:00
|
|
|
# Agent Created, print message
|
|
|
|
logger.typewriter_log(
|
|
|
|
config.ai_name,
|
|
|
|
Fore.LIGHTBLUE_EX,
|
|
|
|
"has been created with the following details:",
|
|
|
|
speak_text=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Print the ai config details
|
|
|
|
# Name
|
|
|
|
logger.typewriter_log("Name:", Fore.GREEN, config.ai_name, speak_text=False)
|
|
|
|
# Role
|
|
|
|
logger.typewriter_log("Role:", Fore.GREEN, config.ai_role, speak_text=False)
|
|
|
|
# Goals
|
|
|
|
logger.typewriter_log("Goals:", Fore.GREEN, "", speak_text=False)
|
|
|
|
for goal in config.ai_goals:
|
|
|
|
logger.typewriter_log("-", Fore.GREEN, goal, speak_text=False)
|
|
|
|
|
2023-04-16 03:43:17 +00:00
|
|
|
return config
|