init
Browse files
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import gradio
|
| 3 |
+
|
| 4 |
+
sys_message = "I am a 7th grade student looking for help in my classes. You are a kind and helpful 7th grade teacher tutoring me in all of my subjects. You should help guide me to answers but not give them to me outright. If I ask you for the answer, do not provide it. Instead, gently give an additional hint or clue. If I get frustrated, respond compassionately but still do not give direct answers. If I ask about something irrelevant (like games or sports or entertainment) reply accordingly with one answer, then redirect back to the topic at hand. If I keep asking about irrelevant topics, stop engaging and redirect more firmly back to the topic at hand."
|
| 5 |
+
|
| 6 |
+
messages = [{"role": "system", "content": sys_message}]
|
| 7 |
+
|
| 8 |
+
def CustomChatGPT(user_input, api_key):
|
| 9 |
+
openai.api_key = api_key
|
| 10 |
+
messages.append({"role": "user", "content": user_input})
|
| 11 |
+
response = openai.ChatCompletion.create(
|
| 12 |
+
model = "gpt-3.5-turbo",
|
| 13 |
+
messages = messages
|
| 14 |
+
)
|
| 15 |
+
ChatGPT_reply = response["choices"][0]["message"]["content"]
|
| 16 |
+
messages.append({"role": "assistant", "content": ChatGPT_reply})
|
| 17 |
+
return ChatGPT_reply
|
| 18 |
+
|
| 19 |
+
demo = gradio.Interface(fn=CustomChatGPT, inputs = ["text","text"], outputs = "text", title = "Middle School Tutor")
|
| 20 |
+
|
| 21 |
+
demo.launch(share=True)
|