mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-17 22:14:28 +01:00
Implements Code Improvement, powered by AI Functions.
This commit is contained in:
@@ -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
|
||||
@@ -5,6 +5,7 @@ import datetime
|
||||
import agent_manager as agents
|
||||
import speak
|
||||
from config import Config
|
||||
import ai_functions as ai
|
||||
from file_operations import read_file, write_to_file, append_to_file, delete_file
|
||||
cfg = 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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user