AutoGPT/autogpt/prompts/prompt.py

114 lines
3.8 KiB
Python
Raw Normal View History

from colorama import Fore
2023-04-17 02:51:36 +00:00
from autogpt.config.ai_config import AIConfig
from autogpt.config.config import Config
from autogpt.config.prompt_config import PromptConfig
from autogpt.llm.api_manager import ApiManager
from autogpt.logs import logger
from autogpt.prompts.generator import PromptGenerator
from autogpt.setup import prompt_user
from autogpt.utils import clean_input
CFG = Config()
DEFAULT_TRIGGERING_PROMPT = "Determine exactly one command to use, and respond using the format specified above:"
2023-04-13 18:36:48 +00:00
def build_default_prompt_generator() -> PromptGenerator:
2023-04-11 16:15:45 +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
prompt_generator = PromptGenerator()
# 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
for constraint in prompt_config.constraints:
prompt_generator.add_constraint(constraint)
2023-04-11 16:15:45 +00:00
# Add resources to the PromptGenerator object
for resource in prompt_config.resources:
prompt_generator.add_resource(resource)
2023-04-11 16:15:45 +00:00
# Add performance evaluations to the PromptGenerator object
for performance_evaluation in prompt_config.performance_evaluations:
prompt_generator.add_performance_evaluation(performance_evaluation)
return prompt_generator
def construct_main_ai_config() -> AIConfig:
"""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}")
Make Auto-GPT aware of its running cost (#762) * Implemented running cost counter for chat completions This data is known to the AI as additional system context, and is printed out to the user * Added comments to api_manager.py * Added user-defined API budget. The user is now prompted if they want to give the AI a budget for API calls. If they enter nothing, there is no monetary limit, but if they define a budget then the AI will be told to shut down gracefully once it has come within 1 cent of its limit, and to shut down immediately once it has exceeded its limit. If a budget is defined, Auto-GPT is always aware of how much it was given and how much remains to be spent. * Chat completion calls are now done through api_manager. Total running cost is printed. * Implemented api budget setting and tracking User can now configure a maximum api budget, and the AI is aware of that and its remaining budget. The AI is instructed to shut down when exceeding the budget. * Update autogpt/api_manager.py Change "per token" to "per 1000 tokens" in a comment on the api cost Co-authored-by: Rob Luke <code@robertluke.net> * Fixed lint errors * Include embedding costs * Add embedding completion cost * lint * Added 'requires_api_key' decorator to test_commands.py, switched to a valid chat completions model * Refactor API manager, add debug mode, and add tests - Extract model costs to to avoid duplication - Add debug mode parameter to ApiManager class - Move debug mode configuration to - Log AI response and budget messages in debug mode - Implement 'test_api_manager.py' * Fixed test_setup failing. An extra user input is needed for api budget * Linting --------- Co-authored-by: Rob Luke <code@robertluke.net> Co-authored-by: Nicholas Tindle <nick@ntindle.com>
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}",
)
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}
Make Auto-GPT aware of its running cost (#762) * Implemented running cost counter for chat completions This data is known to the AI as additional system context, and is printed out to the user * Added comments to api_manager.py * Added user-defined API budget. The user is now prompted if they want to give the AI a budget for API calls. If they enter nothing, there is no monetary limit, but if they define a budget then the AI will be told to shut down gracefully once it has come within 1 cent of its limit, and to shut down immediately once it has exceeded its limit. If a budget is defined, Auto-GPT is always aware of how much it was given and how much remains to be spent. * Chat completion calls are now done through api_manager. Total running cost is printed. * Implemented api budget setting and tracking User can now configure a maximum api budget, and the AI is aware of that and its remaining budget. The AI is instructed to shut down when exceeding the budget. * Update autogpt/api_manager.py Change "per token" to "per 1000 tokens" in a comment on the api cost Co-authored-by: Rob Luke <code@robertluke.net> * Fixed lint errors * Include embedding costs * Add embedding completion cost * lint * Added 'requires_api_key' decorator to test_commands.py, switched to a valid chat completions model * Refactor API manager, add debug mode, and add tests - Extract model costs to to avoid duplication - Add debug mode parameter to ApiManager class - Move debug mode configuration to - Log AI response and budget messages in debug mode - Implement 'test_api_manager.py' * Fixed test_setup failing. An extra user input is needed for api budget * Linting --------- Co-authored-by: Rob Luke <code@robertluke.net> Co-authored-by: Nicholas Tindle <nick@ntindle.com>
2023-04-23 21:04:31 +00:00
API Budget: {"infinite" if config.api_budget <= 0 else f"${config.api_budget}"}
Continue ({CFG.authorise_key}/{CFG.exit_key}): """
)
if should_continue.lower() == CFG.exit_key:
config = AIConfig()
if not config.ai_name:
config = prompt_user()
config.save(CFG.ai_settings_file)
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}",
)
Make Auto-GPT aware of its running cost (#762) * Implemented running cost counter for chat completions This data is known to the AI as additional system context, and is printed out to the user * Added comments to api_manager.py * Added user-defined API budget. The user is now prompted if they want to give the AI a budget for API calls. If they enter nothing, there is no monetary limit, but if they define a budget then the AI will be told to shut down gracefully once it has come within 1 cent of its limit, and to shut down immediately once it has exceeded its limit. If a budget is defined, Auto-GPT is always aware of how much it was given and how much remains to be spent. * Chat completion calls are now done through api_manager. Total running cost is printed. * Implemented api budget setting and tracking User can now configure a maximum api budget, and the AI is aware of that and its remaining budget. The AI is instructed to shut down when exceeding the budget. * Update autogpt/api_manager.py Change "per token" to "per 1000 tokens" in a comment on the api cost Co-authored-by: Rob Luke <code@robertluke.net> * Fixed lint errors * Include embedding costs * Add embedding completion cost * lint * Added 'requires_api_key' decorator to test_commands.py, switched to a valid chat completions model * Refactor API manager, add debug mode, and add tests - Extract model costs to to avoid duplication - Add debug mode parameter to ApiManager class - Move debug mode configuration to - Log AI response and budget messages in debug mode - Implement 'test_api_manager.py' * Fixed test_setup failing. An extra user input is needed for api budget * Linting --------- Co-authored-by: Rob Luke <code@robertluke.net> Co-authored-by: Nicholas Tindle <nick@ntindle.com>
2023-04-23 21:04:31 +00:00
# set the total api budget
api_manager = ApiManager()
Make Auto-GPT aware of its running cost (#762) * Implemented running cost counter for chat completions This data is known to the AI as additional system context, and is printed out to the user * Added comments to api_manager.py * Added user-defined API budget. The user is now prompted if they want to give the AI a budget for API calls. If they enter nothing, there is no monetary limit, but if they define a budget then the AI will be told to shut down gracefully once it has come within 1 cent of its limit, and to shut down immediately once it has exceeded its limit. If a budget is defined, Auto-GPT is always aware of how much it was given and how much remains to be spent. * Chat completion calls are now done through api_manager. Total running cost is printed. * Implemented api budget setting and tracking User can now configure a maximum api budget, and the AI is aware of that and its remaining budget. The AI is instructed to shut down when exceeding the budget. * Update autogpt/api_manager.py Change "per token" to "per 1000 tokens" in a comment on the api cost Co-authored-by: Rob Luke <code@robertluke.net> * Fixed lint errors * Include embedding costs * Add embedding completion cost * lint * Added 'requires_api_key' decorator to test_commands.py, switched to a valid chat completions model * Refactor API manager, add debug mode, and add tests - Extract model costs to to avoid duplication - Add debug mode parameter to ApiManager class - Move debug mode configuration to - Log AI response and budget messages in debug mode - Implement 'test_api_manager.py' * Fixed test_setup failing. An extra user input is needed for api budget * Linting --------- Co-authored-by: Rob Luke <code@robertluke.net> Co-authored-by: Nicholas Tindle <nick@ntindle.com>
2023-04-23 21:04:31 +00:00
api_manager.set_total_budget(config.api_budget)
Automatic prompting (#2896) * Add automatic ai prompting * Tweak the default prompt. * Print agent info upon creation. * Improve system prompt * Switch to fast_llm_model by default * Add format output command to user prompt. This vastly improves formatting success rate. * Add fallback to manual mode if llm output cannot be parsed (or other error). * Add unit test to cover ai creation setup. * Replace redundent prompt with manual mode instructions. * Add missing docstrings and typing. * Runs black on changes. * Runs isort * Update Python version and benchmark file in benchmark.yml * Refactor main function and imports in cli.py * Update import statement in ai_config.py * Add set_temperature and set_memory_backend methods in config.py * Remove unused import in prompt.py * Add goal oriented tasks workflow * Added agent_utils to create agent * added pytest and vcrpy * added write file cassette * created goal oriented task write file with cassettes to not pay openai tokens * solve conflicts * add ability set azure because github workflow needs it off * solve conflicts in cli.py * black because linter fails * solve conflict * setup github action to v3 Signed-off-by: Merwane Hamadi <merwanehamadi@gmail.com> * fix conflicts Signed-off-by: Merwane Hamadi <merwanehamadi@gmail.com> * Plugins: debug line always printed in plugin load * add decorator to tests Signed-off-by: Merwane Hamadi <merwanehamadi@gmail.com> * move decorator higher up Signed-off-by: Merwane Hamadi <merwanehamadi@gmail.com> * merge --------- Signed-off-by: Merwane Hamadi <merwanehamadi@gmail.com> Co-authored-by: Merwane Hamadi <merwanehamadi@gmail.com> Co-authored-by: Merwane Hamadi <merwane.hamadi@redica.com> Co-authored-by: Richard Beales <rich@richbeales.net> Co-authored-by: Nicholas Tindle <nick@ntindle.com> Co-authored-by: BillSchumacher <34168009+BillSchumacher@users.noreply.github.com>
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)
return config