forked from Christian-Downs/AutoSAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenai_test.py
More file actions
38 lines (33 loc) · 1.39 KB
/
openai_test.py
File metadata and controls
38 lines (33 loc) · 1.39 KB
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
from openai import OpenAI
client = OpenAI()
def caller(prompt) -> None:
completion = client.chat.completions.create(
model="gpt-4o-mini",
store=True,
messages=[
{"role": "user", "content": "create website using python flask main.py using input "
+ "Give file structure with space before file name ex: \"--- filename.html\", file code, README.md Dont explain running input or overview:"
+ prompt}
]
)
# print(completion.choices[0].message.content)
with open('input.txt', 'w', encoding="utf-8") as file:
# file.write("\n\n---------Chat Reponse-----------")
file.write(str(completion.choices[0].message.content))
# file.write("\n-----------End of reponse-----------\n")
def tester(filepath, error_code) -> None:
try:
with open(filepath, 'r', encoding="utf-8") as file:
file_content = file.read()
completion = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "user", "content":"Error in\n" + file_content + "\n" + error_code + "give updated code no explanation:"}
]
)
with open('outputTest.txt', 'w', encoding="utf-8") as file:
file.write(str(completion.choices[0].message.content))
return str(completion.choices[0].message.content)
except Exception as ex:
print("ERROR")
print(ex)