major update to ChatInterface
Browse files
app.py
CHANGED
|
@@ -12,19 +12,28 @@ If I keep asking about irrelevant topics, stop engaging and redirect more firmly
|
|
| 12 |
Begin by asking me my name, the topic of our conversation, and the type of assignment I am working on.
|
| 13 |
"""
|
| 14 |
|
| 15 |
-
messages = [{"role": "system", "content": sys_message}]
|
| 16 |
|
| 17 |
-
def CustomChatGPT(
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
response = openai.ChatCompletion.create(
|
| 20 |
model = "gpt-3.5-turbo",
|
| 21 |
-
messages =
|
|
|
|
|
|
|
| 22 |
)
|
| 23 |
-
ChatGPT_reply = response["choices"][0]["message"]["content"]
|
| 24 |
-
messages.append({"role": "assistant", "content": ChatGPT_reply})
|
| 25 |
-
return ChatGPT_reply
|
| 26 |
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
demo.launch()
|
| 30 |
|
|
|
|
| 12 |
Begin by asking me my name, the topic of our conversation, and the type of assignment I am working on.
|
| 13 |
"""
|
| 14 |
|
|
|
|
| 15 |
|
| 16 |
+
def CustomChatGPT(message, history):
|
| 17 |
+
history_openai_format = [{"role": "system", "content": sys_message}]
|
| 18 |
+
for human, assistant in history:
|
| 19 |
+
history_openai_format.append({"role": "user", "content": human})
|
| 20 |
+
history_openai_format.append({"role": "assistant", "content": assistant})
|
| 21 |
+
history_openai_format.append({"role": "user", "content": message})
|
| 22 |
+
|
| 23 |
response = openai.ChatCompletion.create(
|
| 24 |
model = "gpt-3.5-turbo",
|
| 25 |
+
messages = history_openai_format
|
| 26 |
+
temperature = 1.0
|
| 27 |
+
stream=True
|
| 28 |
)
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
partial_message = ""
|
| 31 |
+
for chunk in response:
|
| 32 |
+
if len(chunk['choices'][0]'delta']) != 0:
|
| 33 |
+
partial_message = partial_message + chunk['choices'][0]'delta']['content']
|
| 34 |
+
yield partial_message
|
| 35 |
+
|
| 36 |
+
gradio.ChatInterface(fn=CustomChatGPT, title = "Middle School Tutor").queue().launch()
|
| 37 |
+
|
| 38 |
|
|
|
|
| 39 |
|