-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpt.py
20 lines (19 loc) · 794 Bytes
/
gpt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import os
import openai
from webex_bot.models.command import Command
from webex_bot.models.response import Response
openaiapikey = os.environ.get("OPENAIKEY")
class gpt(Command):
messages = []
messages.append({"role" : "system", "content" : "I am webexGPT ask me any question, I'll be able to answer"})
def __init__(self):
super().__init__()
def execute(self, message, attachment_actions, activity):
openai.api_key = (openaiapikey)
self.messages.append({"role" :"user","content":message})
completion = openai.ChatCompletion.create(
model = "gpt-3.5-turbo",
messages=self.messages)
gpt_res = completion.choices[0].message.content
self.messages.append({"role":"assistant","content": message})
return gpt_res