-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassistant.py
More file actions
35 lines (25 loc) · 1.14 KB
/
assistant.py
File metadata and controls
35 lines (25 loc) · 1.14 KB
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
import openai
openai.api_key = str(open("token.txt").read())
class SmartGurucool():
def __init__(self):
self.messages = [
{"role": "system", "content": "You are a helpful assistant."},
]
def SmartGuruResponse(self, user_text):
self.user_text = user_text
while True:
# if user says stop, then breaking the loop
if self.user_text == "stop":
break
# storing the user question in the messages list
self.messages.append({"role": "user", "content": self.user_text})
# getting the response from OpenAI API
response= openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=self.messages
)
# appending the generated response so that AI remebers past responses
self.messages.append({"role":"assistant", "content":str(response['choices'][0]['message']['content'])})
# returning the response
print(response['choices'][0]['message']['content'])
return response['choices'][0]['message']['content']