Add docs and format code
parent
b19eb74874
commit
fd1cfd2eff
|
@ -1,51 +1,78 @@
|
|||
from promptgenerator import PromptGenerator
|
||||
|
||||
|
||||
def get_prompt():
|
||||
"""
|
||||
This function generates a prompt string that includes various constraints, commands, resources, and performance evaluations.
|
||||
|
||||
Returns:
|
||||
str: The generated prompt string.
|
||||
"""
|
||||
|
||||
# Initialize the PromptGenerator object
|
||||
prompt_generator = PromptGenerator()
|
||||
|
||||
# Add constraints
|
||||
prompt_generator.add_constraint("~4000 word limit for short term memory. Your short term memory is short, so immediately save important information to files.")
|
||||
prompt_generator.add_constraint("If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.")
|
||||
# Add constraints to the PromptGenerator object
|
||||
prompt_generator.add_constraint(
|
||||
"~4000 word limit for short term memory. Your short term memory is short, so immediately save important information to files.")
|
||||
prompt_generator.add_constraint(
|
||||
"If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.")
|
||||
prompt_generator.add_constraint("No user assistance")
|
||||
prompt_generator.add_constraint('Exclusively use the commands listed in double quotes e.g. "command name"')
|
||||
prompt_generator.add_constraint(
|
||||
'Exclusively use the commands listed in double quotes e.g. "command name"')
|
||||
|
||||
# Add commands
|
||||
# Define the command list
|
||||
commands = [
|
||||
("Google Search", "google", {"input": "<search>"}),
|
||||
("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>"}),
|
||||
("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>"}),
|
||||
("List GPT Agents", "list_agents", {}),
|
||||
("Delete GPT Agent", "delete_agent", {"key": "<key>"}),
|
||||
("Write to file", "write_to_file", {"file": "<file>", "text": "<text>"}),
|
||||
("Write to file", "write_to_file", {
|
||||
"file": "<file>", "text": "<text>"}),
|
||||
("Read file", "read_file", {"file": "<file>"}),
|
||||
("Append to file", "append_to_file", {"file": "<file>", "text": "<text>"}),
|
||||
("Append to file", "append_to_file", {
|
||||
"file": "<file>", "text": "<text>"}),
|
||||
("Delete file", "delete_file", {"file": "<file>"}),
|
||||
("Search Files", "search_files", {"directory": "<directory>"}),
|
||||
("Evaluate Code", "evaluate_code", {"code": "<full_code_string>"}),
|
||||
("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>"}),
|
||||
("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>"}),
|
||||
("Execute Python File", "execute_python_file", {"file": "<file>"}),
|
||||
("Task Complete (Shutdown)", "task_complete", {"reason": "<reason>"}),
|
||||
("Generate Image", "generate_image", {"prompt": "<prompt>"}),
|
||||
("Do Nothing", "do_nothing", {}),
|
||||
]
|
||||
|
||||
# Add commands to the PromptGenerator object
|
||||
for command_label, command_name, args in commands:
|
||||
prompt_generator.add_command(command_label, command_name, args)
|
||||
|
||||
# Add resources
|
||||
prompt_generator.add_resource("Internet access for searches and information gathering.")
|
||||
# Add resources to the PromptGenerator object
|
||||
prompt_generator.add_resource(
|
||||
"Internet access for searches and information gathering.")
|
||||
prompt_generator.add_resource("Long Term memory management.")
|
||||
prompt_generator.add_resource("GPT-3.5 powered Agents for delegation of simple tasks.")
|
||||
prompt_generator.add_resource(
|
||||
"GPT-3.5 powered Agents for delegation of simple tasks.")
|
||||
prompt_generator.add_resource("File output.")
|
||||
|
||||
# Add performance evaluation
|
||||
prompt_generator.add_performance_evaluation("Continuously review and analyze your actions to ensure you are performing to the best of your abilities.")
|
||||
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("Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps.")
|
||||
# Add performance evaluations to the PromptGenerator object
|
||||
prompt_generator.add_performance_evaluation(
|
||||
"Continuously review and analyze your actions to ensure you are performing to the best of your abilities.")
|
||||
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(
|
||||
"Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps.")
|
||||
|
||||
# Generate prompt string
|
||||
# Generate the prompt string
|
||||
prompt_string = prompt_generator.generate_prompt_string()
|
||||
|
||||
return prompt_string
|
||||
|
|
|
@ -2,7 +2,14 @@ import json
|
|||
|
||||
|
||||
class PromptGenerator:
|
||||
"""
|
||||
A class for generating custom prompt strings based on constraints, commands, resources, and performance evaluations.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Initialize the PromptGenerator object with empty lists of constraints, commands, resources, and performance evaluations.
|
||||
"""
|
||||
self.constraints = []
|
||||
self.commands = []
|
||||
self.resources = []
|
||||
|
@ -24,14 +31,28 @@ class PromptGenerator:
|
|||
}
|
||||
|
||||
def add_constraint(self, constraint):
|
||||
"""
|
||||
Add a constraint to the constraints list.
|
||||
|
||||
Args:
|
||||
constraint (str): The constraint to be added.
|
||||
"""
|
||||
self.constraints.append(constraint)
|
||||
|
||||
# {CommandLabel}: "{CommandName}", args: "{arg#Name}": "{arg#Prompt}"
|
||||
def add_command(self, command_label, command_name, args=None):
|
||||
"""
|
||||
Add a command to the commands list with a label, name, and optional arguments.
|
||||
|
||||
Args:
|
||||
command_label (str): The label of the command.
|
||||
command_name (str): The name of the command.
|
||||
args (dict, optional): A dictionary containing argument names and their values. Defaults to None.
|
||||
"""
|
||||
if args is None:
|
||||
args = {}
|
||||
|
||||
command_args = {arg_key: arg_value for arg_key, arg_value in args.items()}
|
||||
|
||||
command_args = {arg_key: arg_value for arg_key,
|
||||
arg_value in args.items()}
|
||||
|
||||
command = {
|
||||
"label": command_label,
|
||||
|
@ -42,23 +63,60 @@ class PromptGenerator:
|
|||
self.commands.append(command)
|
||||
|
||||
def _generate_command_string(self, command):
|
||||
args_string = ', '.join(f'"{key}": "{value}"' for key, value in command['args'].items())
|
||||
"""
|
||||
Generate a formatted string representation of a command.
|
||||
|
||||
Args:
|
||||
command (dict): A dictionary containing command information.
|
||||
|
||||
Returns:
|
||||
str: The formatted command string.
|
||||
"""
|
||||
args_string = ', '.join(
|
||||
f'"{key}": "{value}"' for key, value in command['args'].items())
|
||||
return f'{command["label"]}: "{command["name"]}", args: {args_string}'
|
||||
|
||||
|
||||
def add_resource(self, resource):
|
||||
"""
|
||||
Add a resource to the resources list.
|
||||
|
||||
Args:
|
||||
resource (str): The resource to be added.
|
||||
"""
|
||||
self.resources.append(resource)
|
||||
|
||||
def add_performance_evaluation(self, evaluation):
|
||||
"""
|
||||
Add a performance evaluation item to the performance_evaluation list.
|
||||
|
||||
Args:
|
||||
evaluation (str): The evaluation item to be added.
|
||||
"""
|
||||
self.performance_evaluation.append(evaluation)
|
||||
|
||||
|
||||
def _generate_numbered_list(self, items, item_type='list'):
|
||||
"""
|
||||
Generate a numbered list from given items based on the item_type.
|
||||
|
||||
Args:
|
||||
items (list): A list of items to be numbered.
|
||||
item_type (str, optional): The type of items in the list. Defaults to 'list'.
|
||||
|
||||
Returns:
|
||||
str: The formatted numbered list.
|
||||
"""
|
||||
if item_type == 'command':
|
||||
return "\n".join(f"{i+1}. {self._generate_command_string(item)}" for i, item in enumerate(items))
|
||||
else:
|
||||
return "\n".join(f"{i+1}. {item}" for i, item in enumerate(items))
|
||||
|
||||
def generate_prompt_string(self):
|
||||
"""
|
||||
Generate a prompt string based on the constraints, commands, resources, and performance evaluations.
|
||||
|
||||
Returns:
|
||||
str: The generated prompt string.
|
||||
"""
|
||||
formatted_response_format = json.dumps(self.response_format, indent=4)
|
||||
prompt_string = (
|
||||
f"Constraints:\n{self._generate_numbered_list(self.constraints)}\n\n"
|
||||
|
|
Loading…
Reference in New Issue