forked from Significant-Gravitas/AutoGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make prompt parameters configurable (Significant-Gravitas#3375)
Co-authored-by: Nicholas Tindle <[email protected]> Co-authored-by: k-boikov <[email protected]>
- Loading branch information
1 parent
579ef1c
commit 157007d
Showing
10 changed files
with
168 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# sourcery skip: do-not-use-staticmethod | ||
""" | ||
A module that contains the PromptConfig class object that contains the configuration | ||
""" | ||
import yaml | ||
from colorama import Fore | ||
|
||
from autogpt import utils | ||
from autogpt.config.config import Config | ||
from autogpt.logs import logger | ||
|
||
CFG = Config() | ||
|
||
|
||
class PromptConfig: | ||
""" | ||
A class object that contains the configuration information for the prompt, which will be used by the prompt generator | ||
Attributes: | ||
constraints (list): Constraints list for the prompt generator. | ||
resources (list): Resources list for the prompt generator. | ||
performance_evaluations (list): Performance evaluation list for the prompt generator. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
config_file: str = CFG.prompt_settings_file, | ||
) -> None: | ||
""" | ||
Initialize a class instance with parameters (constraints, resources, performance_evaluations) loaded from | ||
yaml file if yaml file exists, | ||
else raises error. | ||
Parameters: | ||
constraints (list): Constraints list for the prompt generator. | ||
resources (list): Resources list for the prompt generator. | ||
performance_evaluations (list): Performance evaluation list for the prompt generator. | ||
Returns: | ||
None | ||
""" | ||
# Validate file | ||
(validated, message) = utils.validate_yaml_file(config_file) | ||
if not validated: | ||
logger.typewriter_log("FAILED FILE VALIDATION", Fore.RED, message) | ||
logger.double_check() | ||
exit(1) | ||
|
||
with open(config_file, encoding="utf-8") as file: | ||
config_params = yaml.load(file, Loader=yaml.FullLoader) | ||
|
||
self.constraints = config_params.get("constraints", []) | ||
self.resources = config_params.get("resources", []) | ||
self.performance_evaluations = config_params.get("performance_evaluations", []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
constraints: [ | ||
'~4000 word limit for short term memory. Your short term memory is short, so immediately save important information to files.', | ||
'If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.', | ||
'No user assistance', | ||
'Exclusively use the commands listed below e.g. command_name' | ||
] | ||
resources: [ | ||
'Internet access for searches and information gathering.', | ||
'Long Term memory management.', | ||
'GPT-3.5 powered Agents for delegation of simple tasks.', | ||
'File output.' | ||
] | ||
performance_evaluations: [ | ||
'Continuously review and analyze your actions to ensure you are performing to the best of your abilities.', | ||
'Constructively self-criticize your big-picture behavior constantly.', | ||
'Reflect on past decisions and strategies to refine your approach.', | ||
'Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps.', | ||
'Write all code to a file.' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from autogpt.config.prompt_config import PromptConfig | ||
|
||
""" | ||
Test cases for the PromptConfig class, which handles loads the Prompts configuration | ||
settings from a YAML file. | ||
""" | ||
|
||
|
||
def test_prompt_config_loading(tmp_path): | ||
"""Test if the prompt configuration loads correctly""" | ||
|
||
yaml_content = """ | ||
constraints: | ||
- A test constraint | ||
- Another test constraint | ||
- A third test constraint | ||
resources: | ||
- A test resource | ||
- Another test resource | ||
- A third test resource | ||
performance_evaluations: | ||
- A test performance evaluation | ||
- Another test performance evaluation | ||
- A third test performance evaluation | ||
""" | ||
config_file = tmp_path / "test_prompt_settings.yaml" | ||
config_file.write_text(yaml_content) | ||
|
||
prompt_config = PromptConfig(config_file) | ||
|
||
assert len(prompt_config.constraints) == 3 | ||
assert prompt_config.constraints[0] == "A test constraint" | ||
assert prompt_config.constraints[1] == "Another test constraint" | ||
assert prompt_config.constraints[2] == "A third test constraint" | ||
assert len(prompt_config.resources) == 3 | ||
assert prompt_config.resources[0] == "A test resource" | ||
assert prompt_config.resources[1] == "Another test resource" | ||
assert prompt_config.resources[2] == "A third test resource" | ||
assert len(prompt_config.performance_evaluations) == 3 | ||
assert prompt_config.performance_evaluations[0] == "A test performance evaluation" | ||
assert ( | ||
prompt_config.performance_evaluations[1] | ||
== "Another test performance evaluation" | ||
) | ||
assert ( | ||
prompt_config.performance_evaluations[2] | ||
== "A third test performance evaluation" | ||
) |