From 7f4a7d7ccdbe2033a8c90cd72f416dec10724a58 Mon Sep 17 00:00:00 2001 From: Coley Date: Fri, 7 Apr 2023 16:47:09 -0400 Subject: [PATCH 1/9] Added class, method and function doc strings --- scripts/ai_config.py | 60 +++++++++++++++++++++++++++++++++++++---- scripts/ai_functions.py | 32 +++++++++++++++++----- 2 files changed, 81 insertions(+), 11 deletions(-) diff --git a/scripts/ai_config.py b/scripts/ai_config.py index 2f432748..6ac243c2 100644 --- a/scripts/ai_config.py +++ b/scripts/ai_config.py @@ -3,7 +3,25 @@ import data class AIConfig: - def __init__(self, ai_name="", ai_role="", ai_goals=[]): + """ + 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 @@ -12,8 +30,18 @@ class AIConfig: SAVE_FILE = "../ai_settings.yaml" @classmethod - def load(cls, config_file=SAVE_FILE): - # Load variables from yaml file if it exists + 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) @@ -26,12 +54,30 @@ class AIConfig: return cls(ai_name, ai_role, ai_goals) - def save(self, config_file=SAVE_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): + 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. + """ 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 @@ -41,3 +87,7 @@ class AIConfig: full_prompt += f"\n\n{data.load_prompt()}" return full_prompt + +if __name__ == "__main__": + import doctest + doctest.testmod() \ No newline at end of file diff --git a/scripts/ai_functions.py b/scripts/ai_functions.py index 05aa93a2..e54f0966 100644 --- a/scripts/ai_functions.py +++ b/scripts/ai_functions.py @@ -5,9 +5,16 @@ from call_ai_function import call_ai_function from json_parser import fix_and_parse_json cfg = Config() -# Evaluating code def evaluate_code(code: str) -> List[str]: + """ + 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.""" @@ -17,9 +24,16 @@ def evaluate_code(code: str) -> List[str]: return result_string -# Improving code - def improve_code(suggestions: List[str], code: str) -> str: + """ + 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:" ) @@ -30,10 +44,16 @@ def improve_code(suggestions: List[str], code: str) -> str: return result_string -# Writing tests - - def write_tests(code: str, focus: List[str]) -> str: + """ + 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:" ) From 7ae5ffe389729a2f5e4c1d859e5fae1b687ba94a Mon Sep 17 00:00:00 2001 From: Coley Date: Fri, 7 Apr 2023 16:52:50 -0400 Subject: [PATCH 2/9] linted changes --- scripts/ai_config.py | 24 +++++++++++++----------- scripts/ai_functions.py | 10 ++++------ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/scripts/ai_config.py b/scripts/ai_config.py index 6ac243c2..4656f23a 100644 --- a/scripts/ai_config.py +++ b/scripts/ai_config.py @@ -5,16 +5,17 @@ import data class AIConfig: """ 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: + + 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. @@ -30,15 +31,15 @@ class AIConfig: SAVE_FILE = "../ai_settings.yaml" @classmethod - def load(cls:object, config_file:str=SAVE_FILE) -> object: + 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 """ @@ -54,13 +55,13 @@ class AIConfig: return cls(ai_name, ai_role, ai_goals) - def save(self, config_file:str=SAVE_FILE) -> None: + 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 """ @@ -71,10 +72,10 @@ class AIConfig: 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. """ @@ -88,6 +89,7 @@ class AIConfig: full_prompt += f"\n\n{data.load_prompt()}" return full_prompt + if __name__ == "__main__": import doctest doctest.testmod() \ No newline at end of file diff --git a/scripts/ai_functions.py b/scripts/ai_functions.py index e54f0966..eee26e15 100644 --- a/scripts/ai_functions.py +++ b/scripts/ai_functions.py @@ -9,7 +9,7 @@ cfg = Config() def evaluate_code(code: str) -> List[str]: """ 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: @@ -20,14 +20,14 @@ def evaluate_code(code: str) -> List[str]: description_string = """Analyzes the given code and returns a list of suggestions for improvements.""" result_string = call_ai_function(function_string, args, description_string) - + return result_string def improve_code(suggestions: List[str], code: str) -> str: """ 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. @@ -47,7 +47,7 @@ def improve_code(suggestions: List[str], code: str) -> str: def write_tests(code: str, focus: List[str]) -> str: """ 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. @@ -62,5 +62,3 @@ def write_tests(code: str, focus: List[str]) -> str: result_string = call_ai_function(function_string, args, description_string) return result_string - - From 77c98a03119c1b62777bec50100012298a0967c0 Mon Sep 17 00:00:00 2001 From: Coley Date: Fri, 7 Apr 2023 16:57:39 -0400 Subject: [PATCH 3/9] Removed doctest call --- scripts/ai_config.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/ai_config.py b/scripts/ai_config.py index 4656f23a..038d5e5d 100644 --- a/scripts/ai_config.py +++ b/scripts/ai_config.py @@ -89,7 +89,3 @@ class AIConfig: full_prompt += f"\n\n{data.load_prompt()}" return full_prompt - -if __name__ == "__main__": - import doctest - doctest.testmod() \ No newline at end of file From 0dc7bee345692801ccfc1ac673381d907112850f Mon Sep 17 00:00:00 2001 From: blankster Date: Mon, 10 Apr 2023 13:38:43 +0200 Subject: [PATCH 4/9] Update README.md Added remark regarding daily free Google custom search limit and how to increase it --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ccac1948..a15e509b 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,8 @@ To use the `google_official_search` command, you need to set up your Google API 8. Set up your search engine by following the prompts. You can choose to search the entire web or specific sites. 9. Once you've created your search engine, click on "Control Panel" and then "Basics". Copy the "Search engine ID" and set it as an environment variable named `CUSTOM_SEARCH_ENGINE_ID` on your machine. See setting up environment variables below. +*Remember that your free daily custom search quota is 100 searces. If you want to increase this limit, you need to assign a billing account to the project to profit from up to 10K daily searches.* + ### Setting up environment variables For Windows Users: ``` From 891f8d84c84549c0de31044f5b469299b0cd253e Mon Sep 17 00:00:00 2001 From: blankster Date: Mon, 10 Apr 2023 13:44:36 +0200 Subject: [PATCH 5/9] Update README.md Spelling mistakes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a15e509b..b11afb5e 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ To use the `google_official_search` command, you need to set up your Google API 8. Set up your search engine by following the prompts. You can choose to search the entire web or specific sites. 9. Once you've created your search engine, click on "Control Panel" and then "Basics". Copy the "Search engine ID" and set it as an environment variable named `CUSTOM_SEARCH_ENGINE_ID` on your machine. See setting up environment variables below. -*Remember that your free daily custom search quota is 100 searces. If you want to increase this limit, you need to assign a billing account to the project to profit from up to 10K daily searches.* +*Remember that your free daily custom search quota allows only up to 100 searches. To increase this limit, you need to assign a billing account to the project to profit from up to 10K daily searches.* ### Setting up environment variables For Windows Users: From 186235f488b970f457a026967a416dbca82a9ac2 Mon Sep 17 00:00:00 2001 From: Toran Bruce Richards Date: Mon, 10 Apr 2023 13:54:27 +0100 Subject: [PATCH 6/9] Fixes missing cfg in main.py --- scripts/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/main.py b/scripts/main.py index 844c2375..c4fa2a20 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -17,6 +17,8 @@ import traceback import yaml import argparse +cfg = Config() + def check_openai_api_key(): """Check if the OpenAI API key is set in config.py or as an environment variable.""" if not cfg.openai_api_key: From 026361aa3a634da6234776d1d49fa2a0fa029367 Mon Sep 17 00:00:00 2001 From: cryptidv Date: Mon, 10 Apr 2023 14:22:11 +0100 Subject: [PATCH 7/9] Changed occurances of 'cfg.debug_mode' to 'cfg.debug' --- scripts/chat.py | 6 +++--- scripts/json_parser.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/chat.py b/scripts/chat.py index 4a7056d2..c00e4d4a 100644 --- a/scripts/chat.py +++ b/scripts/chat.py @@ -64,14 +64,14 @@ def chat_with_ai( model = cfg.fast_llm_model # TODO: Change model from hardcode to argument # Reserve 1000 tokens for the response - if cfg.debug_mode: + if cfg.debug: print(f"Token limit: {token_limit}") send_token_limit = token_limit - 1000 relevant_memory = permanent_memory.get_relevant(str(full_message_history[-5:]), 10) - if cfg.debug_mode: + if cfg.debug: print('Memory Stats: ', permanent_memory.get_stats()) next_message_to_add_index, current_tokens_used, insertion_index, current_context = generate_context( @@ -110,7 +110,7 @@ def chat_with_ai( # assert tokens_remaining >= 0, "Tokens remaining is negative. This should never happen, please submit a bug report at https://www.github.com/Torantulino/Auto-GPT" # Debug print the current context - if cfg.debug_mode: + if cfg.debug: print(f"Token limit: {token_limit}") print(f"Send Token Count: {current_tokens_used}") print(f"Tokens remaining for response: {tokens_remaining}") diff --git a/scripts/json_parser.py b/scripts/json_parser.py index 4165a1d2..1fd68244 100644 --- a/scripts/json_parser.py +++ b/scripts/json_parser.py @@ -91,7 +91,7 @@ def fix_json(json_str: str, schema: str) -> str: result_string = call_ai_function( function_string, args, description_string, model=cfg.fast_llm_model ) - if cfg.debug_mode: + if cfg.debug: print("------------ JSON FIX ATTEMPT ---------------") print(f"Original JSON: {json_str}") print("-----------") From 37b4473137d9fc5601c1a11fdc1859b65bfb75a2 Mon Sep 17 00:00:00 2001 From: Toran Bruce Richards Date: Mon, 10 Apr 2023 14:23:20 +0100 Subject: [PATCH 8/9] Fixes extra arg given in chat-with-ai call in main --- scripts/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.py b/scripts/main.py index c4fa2a20..3dfcaa15 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -320,7 +320,7 @@ while True: user_input, full_message_history, memory, - cfg.fast_token_limit, cfg.debug) # TODO: This hardcodes the model to use GPT3.5. Make this an argument + cfg.fast_token_limit) # TODO: This hardcodes the model to use GPT3.5. Make this an argument # Print Assistant thoughts print_assistant_thoughts(assistant_reply) From c300276d6d816e44c4d0be0e0e397191d3200826 Mon Sep 17 00:00:00 2001 From: Toran Bruce Richards Date: Mon, 10 Apr 2023 14:32:13 +0100 Subject: [PATCH 9/9] Change debug_mode to debug in chat.py. --- scripts/chat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/chat.py b/scripts/chat.py index 4a7056d2..67cfe52a 100644 --- a/scripts/chat.py +++ b/scripts/chat.py @@ -64,7 +64,7 @@ def chat_with_ai( model = cfg.fast_llm_model # TODO: Change model from hardcode to argument # Reserve 1000 tokens for the response - if cfg.debug_mode: + if cfg.debug: print(f"Token limit: {token_limit}") send_token_limit = token_limit - 1000