Balams commited on
Commit
f282bf7
1 Parent(s): 78a0bfe

Create openAI_ChatGPT_Assistant.py

Browse files
Files changed (1) hide show
  1. openAI_ChatGPT_Assistant.py +20 -0
openAI_ChatGPT_Assistant.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio
3
+
4
+ openai.api_key = "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"
5
+
6
+ messages = [{"role": "system", "content": "Chat GPT"}]
7
+
8
+ def CustomChatGPT(user_input):
9
+ messages.append({"role": "user", "content": user_input})
10
+ response = openai.ChatCompletion.create(
11
+ model = "gpt-3.5-turbo",
12
+ messages = messages
13
+ )
14
+ ChatGPT_reply = response["choices"][0]["message"]["content"]
15
+ messages.append({"role": "assistant", "content": ChatGPT_reply})
16
+ return ChatGPT_reply
17
+
18
+ demo = gradio.Interface(fn=CustomChatGPT, inputs = "text", outputs = "text", title = "OpenAI ChatGPT Assistant")
19
+
20
+ demo.launch()