Skip to content

Commit

Permalink
Merge pull request #20 from Torantulino/autoformat-testing
Browse files Browse the repository at this point in the history
Autoformat testing
  • Loading branch information
Torantulino authored Apr 2, 2023
2 parents f930f92 + 01b3ef2 commit 73ef935
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
28 changes: 19 additions & 9 deletions scripts/ai_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@
import openai


# This is a magic function that can do anything with no-code. See
# https://github.com/Torantulino/AI-Functions for more info.
def call_ai_function(function, args, description, model="gpt-4"):
# parse args to comma seperated string
args = ", ".join(args)
messages = [{"role": "system",
"content": f"You are now the following python function: ```# {description}\n{function}```\n\nOnly respond with your `return` value."},
{"role": "user",
"content": args}]
messages = [
{
"role": "system",
"content": f"You are now the following python function: ```# {description}\n{function}```\n\nOnly respond with your `return` value.",
},
{"role": "user", "content": args},
]

response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=0
model=model, messages=messages, temperature=0
)

return response.choices[0].message["content"]


# Evaluating code


Expand All @@ -33,8 +37,11 @@ def evaluate_code(code: str) -> List[str]:

# Improving code


def improve_code(suggestions: List[str], code: str) -> str:
function_string = "def generate_improved_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."""

Expand All @@ -44,8 +51,11 @@ def improve_code(suggestions: List[str], code: str) -> str:

# Writing tests


def write_tests(code: str, focus: List[str]) -> str:
function_string = "def create_test_cases(code: str, focus: Optional[str] = None) -> str:"
function_string = (
"def create_test_cases(code: str, focus: Optional[str] = None) -> str:"
)
args = [code, json.dumps(focus)]
description_string = """Generates test cases for the existing code, focusing on specific areas if required."""

Expand Down
7 changes: 5 additions & 2 deletions scripts/keys.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
OPENAI_API_KEY="YOUR-OPENAI-KEY" # Get yours from: https://beta.openai.com/account/api-keys
ELEVENLABS_API_KEY="YOUR-ELEVENLABS-KEY" # To access your ElevenLabs API key, head to https://elevenlabs.io, you can view your xi-api-key using the 'Profile' tab on the website.
# Get yours from: https://beta.openai.com/account/api-keys
OPENAI_API_KEY = "YOUR-OPENAI-KEY"
# To access your ElevenLabs API key, head to https://elevenlabs.io, you
# can view your xi-api-key using the 'Profile' tab on the website.
ELEVENLABS_API_KEY = "YOUR-ELEVENLABS-KEY"

0 comments on commit 73ef935

Please sign in to comment.