-
Notifications
You must be signed in to change notification settings - Fork 3
/
check_code.py
87 lines (80 loc) · 2.87 KB
/
check_code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import os
from openai import OpenAI
from dotenv import load_dotenv
import json
load_dotenv()
client = OpenAI(api_key=os.getenv("OPEN_AI_API_KEY"))
model = os.getenv("CHECK_CODE_MODEL")
vision_model = "gpt-4-vision-preview"
image_generation = "dalle-3"
code_interpreter = "code-interpreter"
system = """
# You are PythonCheckerGPT, you are the last agent in the workflow and your job is to read the output and respond True if everything is running fine and if its not explain what should be fixed and run fix_test_code.
"""
def check_code(prompt):
print("I am checking the code.")
response = client.chat.completions.create(
model=model,
function_call="auto",
response_format={"type": "json_object"},
functions=[
{
"name": "fix_test_code",
"description": "This function will fix the test code.",
"parameters": {
"type": "object",
"properties": {
"description": {
"type": "string",
"description": "Explain what needs to be fixed in this.",
},
},
"required": ["description"],
},
},
{
"name": "fix_code",
"description": "This function will fix the main code.",
"parameters": {
"type": "object",
"properties": {
"description": {
"type": "string",
"description": "Explain what needs to be fixed in this.",
},
},
"required": ["description"],
},
},
{
"name": "correct",
"description": "This function will run if the code is correct.",
"parameters": {
"type": "object",
"properties": {
"description": {
"type": "string",
"enum": ["True"],
"description": "Explain what needs to be fixed in this.",
},
},
"required": ["description"],
},
},
],
messages=[
{"role": "system", "content": system},
{
"role": "user",
"content": f"Respond True if code is correct and call the correct function if not respond only in JSON:\n{prompt}\n",
},
],
temperature=0,
max_tokens=500,
stop=None,
n=1,
presence_penalty=0,
frequency_penalty=0,
)
function_call = response.choices[0].message.function_call
return function_call