-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat.py
36 lines (31 loc) · 1000 Bytes
/
chat.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
import openai
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import json
OPENAI_API_KEY = ''
with open("./configs/openAI.json") as file:
data = json.load(file)
OPENAI_API_KEY = data["OPENAI_API_KEY"]
scopes = [
'https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/drive'
]
creds = ServiceAccountCredentials.from_json_keyfile_name(
"./configs/gsheets.json", scopes=scopes)
file = gspread.authorize(creds)
workbook = file.open("ANPR")
sheet = workbook.sheet1
records = sheet.get_all_records()
model = 'text-davinci-003'
openai.api_key = OPENAI_API_KEY
def ask(message):
response = openai.Completion.create(
model="text-davinci-003",
prompt="{0} in {1}".format(message, records),
temperature=0.7,
max_tokens=120,
top_p=0.9,
frequency_penalty=0.0,
presence_penalty=1
)
return str(response["choices"][0]["text"])