-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathopenai.py
33 lines (26 loc) · 858 Bytes
/
openai.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
import openai
import time
import numpy as np
from tqdm import tqdm
# models
GPT_MODEL = "gpt-3.5-turbo"
returned_data = []
for i in range(0, 50):
for j in tqdm(range(10)):
idx = i * 10 + j
# an example question in PubMedQA
query = inputs[idx]
print(query)
response = openai.ChatCompletion.create(
messages=[
{'role': 'system', 'content': 'answer the question given the context using a single word from below: yes, no, maybe'},
{'role': 'user', 'content': query},
],
model=GPT_MODEL,
max_tokens=512,
n=1,
temperature=0.8,
)
returned_data.append(response['choices'][0]['message']['content'])
np.save('gpt3.5_answer_' + str(i) + '.npy', returned_data)
time.sleep(1)