-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQA.py
25 lines (24 loc) · 1.18 KB
/
QA.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
# QA.py
import openai
import os
import time
def create_qa(query, summary_filename):
print("Creating QA...")
try:
with open(summary_filename, "r") as sf: # Open the summary file
summaries = sf.read()
messages = [{'role': 'system', 'content': summaries}, {'role': 'user', 'content': f"How well does this report answer the query '{query}' on a scale of 1-10? If the rating is less than 10, why?"}]
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-16k",
messages=messages
)
gpt_qa = response.choices[0].message['content'].strip()
print(f"GPT-3 QA: {gpt_qa}")
os.makedirs("QA", exist_ok=True) # Create the "QA" directory if it doesn't exist
qa_filename = os.path.join("QA", f"QA_{query}_{time.time()}.txt") # Store the QA filename
with open(qa_filename, "w") as qf: # Open the QA file
qf.write(f"GPT-3 QA:\n{gpt_qa}\n") # Write the GPT-3 QA to the QA file
except FileNotFoundError:
print(f"Could not find file: {summary_filename}")
return None
return gpt_qa # Return the query generated by GPT-3