Files
Auto-GPT/scripts/ai_functions.py
Andres Caicedo 1b4a5301d0 Update ai_functions.py
Just import dumps from JSON library.
2023-04-04 10:49:28 +02:00

46 lines
1.7 KiB
Python

from typing import List, Optional
from json import dumps
from config import Config
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]:
"""Evaluates the given code and returns a list of suggestions for improvements."""
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 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."""
function_string = (
"def generate_improved_code(suggestions: List[str], code: str) -> str:"
)
args = [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: List[str]) -> str:
"""Generates test cases for the existing code, focusing on specific areas if required."""
function_string = (
"def create_test_cases(code: str, focus: Optional[str] = None) -> str:"
)
args = [code, dumps(focus)]
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