2023-04-15 12:56:23 +00:00
|
|
|
from colorama import Fore
|
|
|
|
from autogpt.config.ai_config import AIConfig
|
|
|
|
from autogpt.config.config import Config
|
|
|
|
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-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-04-11 16:15:45 +00:00
|
|
|
# Add constraints to the PromptGenerator object
|
2023-04-14 19:42:28 +00:00
|
|
|
prompt_generator.add_constraint(
|
2023-04-15 00:04:48 +00:00
|
|
|
"~4000 word limit for short term memory. Your short term memory is short, so"
|
|
|
|
" immediately save important information to files."
|
2023-04-14 19:42:28 +00:00
|
|
|
)
|
|
|
|
prompt_generator.add_constraint(
|
2023-04-15 00:04:48 +00:00
|
|
|
"If you are unsure how you previously did something or want to recall past"
|
|
|
|
" events, thinking about similar events will help you remember."
|
2023-04-14 19:42:28 +00:00
|
|
|
)
|
2023-04-11 16:09:59 +00:00
|
|
|
prompt_generator.add_constraint("No user assistance")
|
2023-04-14 19:42:28 +00:00
|
|
|
prompt_generator.add_constraint(
|
|
|
|
'Exclusively use the commands listed in double quotes e.g. "command name"'
|
|
|
|
)
|
2023-04-11 16:09:59 +00:00
|
|
|
|
2023-04-11 16:15:45 +00:00
|
|
|
# Define the command list
|
2023-04-11 16:09:59 +00:00
|
|
|
commands = [
|
|
|
|
("Google Search", "google", {"input": "<search>"}),
|
2023-04-14 19:42:28 +00:00
|
|
|
(
|
|
|
|
"Browse Website",
|
|
|
|
"browse_website",
|
|
|
|
{"url": "<url>", "question": "<what_you_want_to_find_on_website>"},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"Start GPT Agent",
|
|
|
|
"start_agent",
|
|
|
|
{"name": "<name>", "task": "<short_task_desc>", "prompt": "<prompt>"},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"Message GPT Agent",
|
|
|
|
"message_agent",
|
|
|
|
{"key": "<key>", "message": "<message>"},
|
|
|
|
),
|
2023-04-11 16:09:59 +00:00
|
|
|
("List GPT Agents", "list_agents", {}),
|
|
|
|
("Delete GPT Agent", "delete_agent", {"key": "<key>"}),
|
2023-04-15 19:55:13 +00:00
|
|
|
(
|
|
|
|
"Clone Repository",
|
|
|
|
"clone_repository",
|
|
|
|
{"repository_url": "<url>", "clone_path": "<directory>"},
|
|
|
|
),
|
2023-04-11 16:21:20 +00:00
|
|
|
("Write to file", "write_to_file", {"file": "<file>", "text": "<text>"}),
|
2023-04-11 16:09:59 +00:00
|
|
|
("Read file", "read_file", {"file": "<file>"}),
|
2023-04-11 16:21:20 +00:00
|
|
|
("Append to file", "append_to_file", {"file": "<file>", "text": "<text>"}),
|
2023-04-11 16:09:59 +00:00
|
|
|
("Delete file", "delete_file", {"file": "<file>"}),
|
|
|
|
("Search Files", "search_files", {"directory": "<directory>"}),
|
|
|
|
("Evaluate Code", "evaluate_code", {"code": "<full_code_string>"}),
|
2023-04-14 19:42:28 +00:00
|
|
|
(
|
|
|
|
"Get Improved Code",
|
|
|
|
"improve_code",
|
|
|
|
{"suggestions": "<list_of_suggestions>", "code": "<full_code_string>"},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"Write Tests",
|
|
|
|
"write_tests",
|
|
|
|
{"code": "<full_code_string>", "focus": "<list_of_focus_areas>"},
|
|
|
|
),
|
2023-04-11 16:09:59 +00:00
|
|
|
("Execute Python File", "execute_python_file", {"file": "<file>"}),
|
|
|
|
("Generate Image", "generate_image", {"prompt": "<prompt>"}),
|
2023-04-15 20:58:22 +00:00
|
|
|
("Send Tweet", "send_tweet", {"text": "<text>"}),
|
2023-04-11 16:09:59 +00:00
|
|
|
]
|
|
|
|
|
2023-04-16 08:57:23 +00:00
|
|
|
# Only add the audio to text command if the model is specified
|
|
|
|
if cfg.huggingface_audio_to_text_model:
|
|
|
|
commands.append(
|
2023-04-16 19:15:38 +00:00
|
|
|
("Convert Audio to text", "read_audio_from_file", {"file": "<file>"}),
|
2023-04-16 08:57:23 +00:00
|
|
|
)
|
|
|
|
|
2023-04-15 17:24:57 +00:00
|
|
|
# Add these command last.
|
|
|
|
commands.append(
|
|
|
|
("Do Nothing", "do_nothing", {}),
|
|
|
|
)
|
|
|
|
commands.append(
|
|
|
|
("Task Complete (Shutdown)", "task_complete", {"reason": "<reason>"}),
|
|
|
|
)
|
|
|
|
|
2023-04-11 16:15:45 +00:00
|
|
|
# Add commands to the PromptGenerator object
|
2023-04-11 16:09:59 +00:00
|
|
|
for command_label, command_name, args in commands:
|
|
|
|
prompt_generator.add_command(command_label, command_name, args)
|
|
|
|
|
2023-04-11 16:15:45 +00:00
|
|
|
# Add resources to the PromptGenerator object
|
2023-04-14 19:42:28 +00:00
|
|
|
prompt_generator.add_resource(
|
|
|
|
"Internet access for searches and information gathering."
|
|
|
|
)
|
2023-04-11 16:09:59 +00:00
|
|
|
prompt_generator.add_resource("Long Term memory management.")
|
2023-04-14 19:42:28 +00:00
|
|
|
prompt_generator.add_resource(
|
|
|
|
"GPT-3.5 powered Agents for delegation of simple tasks."
|
|
|
|
)
|
2023-04-11 16:09:59 +00:00
|
|
|
prompt_generator.add_resource("File output.")
|
|
|
|
|
2023-04-11 16:15:45 +00:00
|
|
|
# Add performance evaluations to the PromptGenerator object
|
2023-04-14 19:42:28 +00:00
|
|
|
prompt_generator.add_performance_evaluation(
|
2023-04-15 00:04:48 +00:00
|
|
|
"Continuously review and analyze your actions to ensure you are performing to"
|
|
|
|
" the best of your abilities."
|
2023-04-14 19:42:28 +00:00
|
|
|
)
|
|
|
|
prompt_generator.add_performance_evaluation(
|
|
|
|
"Constructively self-criticize your big-picture behavior constantly."
|
|
|
|
)
|
|
|
|
prompt_generator.add_performance_evaluation(
|
|
|
|
"Reflect on past decisions and strategies to refine your approach."
|
|
|
|
)
|
|
|
|
prompt_generator.add_performance_evaluation(
|
2023-04-15 00:04:48 +00:00
|
|
|
"Every command has a cost, so be smart and efficient. Aim to complete tasks in"
|
|
|
|
" the least number of steps."
|
2023-04-14 19:42:28 +00:00
|
|
|
)
|
2023-04-11 16:09:59 +00:00
|
|
|
|
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}")
|
|
|
|
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}
|
|
|
|
Continue (y/n): """
|
|
|
|
)
|
|
|
|
if should_continue.lower() == "n":
|
|
|
|
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-04-16 03:43:17 +00:00
|
|
|
return config
|