-
Notifications
You must be signed in to change notification settings - Fork 16
/
gpt3.py
38 lines (31 loc) · 853 Bytes
/
gpt3.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
'''
authors: @yash-dani @gkysaad
date: July 2020
Turn informat statements into requests to update balance sheets using GPT-3
'''
import ast # standard library
import openai # 3rd party packages
import json
'''
Function to turn informal request into transactional statement
'''
def getGPT3(request):
# setup key and fine tuning data
key = open("key.txt", "r")
fineTuneData = open("fineTuneData.txt", "r")
question = "Q: " + request
openai.api_key = key.read()
# request completion from GPT-3
output = openai.Completion.create(
engine="davinci",
prompt= fineTuneData.read() + question + "\n",
max_tokens=100,
temperature=0.4,
stop=["Q: ",'\n']
)
# process output
try:
output = json.loads(output["choices"][0]["text"].replace('A:',''))
except:
output = output["choices"][0]["text"].replace('A: ','')
return output