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.
Implements Code Improvement, powered by AI Functions.
Torantulino3edae91524c8
diff --git a/scripts/ai_functions.py b/scripts/ai_functions.pyindex 030feac48b..7d651bd97d 100644--- a/scripts/ai_functions.py+++ b/scripts/ai_functions.py@@ -14,3 +14,35 @@ def call_ai_function(function, args, description, model = "gpt-4"):)return response.choices[0].message["content"]++### Evaluating code++def evaluate_code(code: str) -> List[str]:+ 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."""++ result_string = call_ai_function(function_string, args, description_string)+ return json.loads(result_string)+++### Improving code++def improve_code(suggestions: List[str], code: str) -> str:+ function_string = "def generate_improved_code(suggestions: List[str], code: str) -> str:"+ args = [json.dumps(suggestions), code]+ description_string = """Improves the provided code based on the suggestions provided, making no other changes."""++ result_string = call_ai_function(function_string, args, description_string)+ return result_string+++### Writing tests++def write_tests(code: str, focus: Optional[str] = None) -> str:+ function_string = "def create_test_cases(code: str, focus: Optional[str] = None) -> str:"+ args = [focus] if focus else []+ description_string = """Generates test cases for the existing code, focusing on specific areas if required."""++ result_string = call_ai_function(function_string, args, description_string)+ return result_string\ No newline at end of filediff --git a/scripts/commands.py b/scripts/commands.pyindex bac8b75962..d5be8ffec8 100644--- a/scripts/commands.py+++ b/scripts/commands.py@@ -5,6 +5,7 @@ import datetimeimport agent_manager as agentsimport speakfrom config import Config+import ai_functions as aifrom file_operations import read_file, write_to_file, append_to_file, delete_filecfg = Config()@@ -66,6 +67,12 @@ def execute_command(command_name, arguments):return delete_file(arguments["file"])elif command_name == "browse_website":return browse_website(arguments["url"])+ elif command_name == "evaluate_code":+ return ai.evaluate_code(arguments["code"])+ elif command_name == "improve_code":+ return ai.improve_code(arguments["suggestions"], arguments["code"])+ elif command_name == "write_tests":+ return ai.write_tests(arguments["code"], arguments.get("focus"))elif command_name == "task_complete":shutdown()else:@@ -77,8 +84,6 @@ def execute_command(command_name, arguments):def get_datetime():return "Current date and time: " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")--### Implemented Commands: ###def google_search(query, num_results=8):search_results = []for j in browse.search(query, num_results=num_results):diff --git a/scripts/data/prompt.txt b/scripts/data/prompt.txtindex 1c7280db07..744575bcef 100644--- a/scripts/data/prompt.txt+++ b/scripts/data/prompt.txt@@ -19,7 +19,10 @@ COMMANDS:12. Read file: "read_file", args: "file": "<file>"13. Append to file: "append_to_file", args: "file": "<file>", "text": "<text>"14. Delete file: "delete_file", args: "file": "<file>"-15. Task Complete (Shutdown): "task_complete", args: "reason": "<reason>"+15. Evaluate Code: "evaluate_code", args: "code": "<code>"+16. Get Improved Code: "improve_code", args: "suggestions": "<list_of_suggestions>", "code": "<string>"+17. Write Tests: "write_tests", args: "code": "<string>", "focus": "<optional_focus>"+18. Task Complete (Shutdown): "task_complete", args: "reason": "<reason>"RESOURCES: