Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

Merge branch 'master' into add_documentation

Toran Bruce Richardse87b6912bd9d
diff --cc scripts/ai_config.py
index 038d5e5dd2,59c7520134..8fabf3dcee
--- a/scripts/ai_config.py
+++ b/scripts/ai_config.py
@@@ -1,48 -1,21 +1,50 @@@
import yaml
import data
-
+ import os
class AIConfig:
- """Class to store the AI's name, role, and goals."""
- def __init__(self, ai_name="", ai_role="", ai_goals=[]):
- """Initialize the AIConfig class"""
+ """
+ A class object that contains the configuration information for the AI
+
+ Attributes:
+ ai_name (str): The name of the AI.
+ ai_role (str): The description of the AI's role.
+ ai_goals (list): The list of objectives the AI is supposed to complete.
+ """
+
+ def __init__(self, ai_name: str="", ai_role: str="", ai_goals: list=[]) -> None:
+ """
+ Initialize a class instance
+
+ Parameters:
+ ai_name (str): The name of the AI.
+ ai_role (str): The description of the AI's role.
+ ai_goals (list): The list of objectives the AI is supposed to complete.
+ Returns:
+ None
+ """
++
self.ai_name = ai_name
self.ai_role = ai_role
self.ai_goals = ai_goals
# Soon this will go in a folder where it remembers more stuff about the run(s)
- SAVE_FILE = "../ai_settings.yaml"
+ SAVE_FILE = os.path.join(os.path.dirname(__file__), '..', 'ai_settings.yaml')
@classmethod
- def load(cls, config_file=SAVE_FILE):
- """Load variables from yaml file if it exists, otherwise use defaults."""
+ def load(cls: object, config_file: str=SAVE_FILE) -> object:
+ """
+ Returns class object with parameters (ai_name, ai_role, ai_goals) loaded from yaml file if yaml file exists,
+ else returns class with no parameters.
+
+ Parameters:
+ cls (class object): An AIConfig Class object.
+ config_file (int): The path to the config yaml file. DEFAULT: "../ai_settings.yaml"
+
+ Returns:
+ cls (object): A instance of given cls object
+ """
++
try:
with open(config_file) as file:
config_params = yaml.load(file, Loader=yaml.FullLoader)
@@@ -55,30 -28,15 +57,32 @@@
return cls(ai_name, ai_role, ai_goals)
- def save(self, config_file=SAVE_FILE):
- """Save variables to yaml file."""
+ def save(self, config_file: str=SAVE_FILE) -> None:
+ """
+ Saves the class parameters to the specified file yaml file path as a yaml file.
+
+ Parameters:
+ config_file(str): The path to the config yaml file. DEFAULT: "../ai_settings.yaml"
+
+ Returns:
+ None
+ """
++
config = {"ai_name": self.ai_name, "ai_role": self.ai_role, "ai_goals": self.ai_goals}
with open(config_file, "w") as file:
yaml.dump(config, file)
+ def construct_full_prompt(self) -> str:
+ """
+ Returns a prompt to the user with the class information in an organized fashion.
+
+ Parameters:
+ None
+
+ Returns:
+ full_prompt (str): A string containing the intitial prompt for the user including the ai_name, ai_role and ai_goals.
+ """
+
- def construct_full_prompt(self):
- """Construct the full prompt for the AI to use."""
prompt_start = """Your decisions must always be made independently without seeking user assistance. Play to your strengths as an LLM and pursue simple strategies with no legal complications."""
# Construct full prompt
diff --cc scripts/ai_functions.py
index eee26e1529,0150335caf..dc774b37cb
--- a/scripts/ai_functions.py
+++ b/scripts/ai_functions.py
@@@ -5,16 -5,9 +5,17 @@@ from call_ai_function import call_ai_fu
from json_parser import fix_and_parse_json
cfg = Config()
-# Evaluating code
+
def evaluate_code(code: str) -> List[str]:
- """Evaluates the given code and returns a list of suggestions for improvements."""
+ """
+ A function that takes in a string and returns a response from create chat completion api call.
+
+ Parameters:
+ code (str): Code to be evaluated.
+ Returns:
+ A result string from create chat completion. A list of suggestions to improve the code.
+ """
++
function_string = "def analyze_code(code: str) -> List[str]:"
args = [code]
description_string = """Analyzes the given code and returns a list of suggestions for improvements."""
@@@ -24,16 -17,9 +25,17 @@@
return result_string
-# Improving code
def improve_code(suggestions: List[str], code: str) -> str:
- """Improves the provided code based on the suggestions provided, making no other changes."""
+ """
+ A function that takes in code and suggestions and returns a response from create chat completion api call.
+
+ Parameters:
+ suggestions (List): A list of suggestions around what needs to be improved.
+ code (str): Code to be improved.
+ Returns:
+ A result string from create chat completion. Improved code in response.
+ """
++
function_string = (
"def generate_improved_code(suggestions: List[str], code: str) -> str:"
)
@@@ -44,16 -30,9 +46,18 @@@
return result_string
-# Writing tests
++
def write_tests(code: str, focus: List[str]) -> str:
- """Generates test cases for the existing code, focusing on specific areas if required."""
+ """
+ A function that takes in code and focus topics and returns a response from create chat completion api call.
+
+ Parameters:
+ focus (List): A list of suggestions around what needs to be improved.
+ code (str): Code for test cases to be generated against.
+ Returns:
+ A result string from create chat completion. Test cases for the submitted code in response.
+ """
++
function_string = (
"def create_test_cases(code: str, focus: Optional[str] = None) -> str:"
)