Spaces:
Running
Running
Upload openai-test2.py
Browse files- openai-test2.py +27 -0
openai-test2.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
openai.api_key = "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"
|
5 |
+
|
6 |
+
messages = [
|
7 |
+
{"role": "system", "content": "You are a learning assistant specialized in business information systems."},
|
8 |
+
]
|
9 |
+
|
10 |
+
def chatbot(input):
|
11 |
+
if input:
|
12 |
+
messages.append({"role": "user", "content": input})
|
13 |
+
chat = openai.chat.completions.create(
|
14 |
+
model="gpt-3.5-turbo", messages=messages
|
15 |
+
)
|
16 |
+
reply = chat.choices[0].message.content
|
17 |
+
messages.append({"role": "assistant", "content": reply})
|
18 |
+
return reply
|
19 |
+
|
20 |
+
inputs = gr.inputs.Textbox(lines=7, label="Ask questions related to the course.")
|
21 |
+
outputs = gr.outputs.Textbox(label="Reply")
|
22 |
+
|
23 |
+
gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="Virtual TA",
|
24 |
+
description="This is a prototype of learning assistant designed for MIS 320 online section.",
|
25 |
+
theme="compact").launch(share=True)
|
26 |
+
|
27 |
+
|