-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_train.py
27 lines (21 loc) · 794 Bytes
/
model_train.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
import openai
import json
from decouple import config
def train_gpt_model(prompt_path,response_path,input_argument):
openai.api_key = config('OPEN_AI_API_KEY')
with open(f"{prompt_path}/Question{input_argument}.txt",'r') as prompt_file:
prompt = prompt_file.read()
messages = []
print(prompt)
messages.append({"role":"user","content":f"{prompt}"})
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages
)
reply = response["choices"][0]["message"]["content"]
messages.append({"role":"assistant","content":reply})
response = messages
jsonString = json.dumps(response)
with open(f"{response_path}/response{input_argument}.json",'w') as outfile:
outfile.write(jsonString)
print(reply)