Spaces:
Sleeping
Sleeping
Commit
·
97ef844
1
Parent(s):
b802ad8
Update app.py
Browse files
app.py
CHANGED
@@ -73,41 +73,42 @@ for message in st.session_state.messages:
|
|
73 |
with st.chat_message(name_to_role(message['name'])):
|
74 |
st.markdown(message['content'])
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
messages=[ st.session_state.student_message_system_prompt ] + [
|
84 |
-
{ "role": reverse_name_to_role(m["name"]), "content": m["content"] }
|
85 |
-
for m in st.session_state.messages
|
86 |
-
],
|
87 |
-
stream=True,
|
88 |
-
api_key=API_KEY
|
89 |
-
):
|
90 |
-
full_response += response.choices[0].delta.get("content", "")
|
91 |
-
message_placeholder.markdown(full_response + "▌")
|
92 |
-
message_placeholder.markdown(full_response)
|
93 |
-
print("Append to student:", full_response)
|
94 |
-
st.session_state.messages.append({ "name": "student", "content": full_response })
|
95 |
-
if st.button('Small Talk'):
|
96 |
-
with st.chat_message(name_to_role('tutor')): # tutor
|
97 |
# assistant == tutor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
message_placeholder = st.empty()
|
99 |
full_response = ""
|
100 |
for response in openai.ChatCompletion.create(
|
101 |
model=st.session_state["openai_model"],
|
102 |
-
messages=[
|
103 |
-
{
|
104 |
for m in st.session_state.messages
|
105 |
],
|
106 |
stream=True,
|
107 |
-
api_key=API_KEY
|
108 |
):
|
109 |
full_response += response.choices[0].delta.get("content", "")
|
110 |
message_placeholder.markdown(full_response + "▌")
|
111 |
message_placeholder.markdown(full_response)
|
112 |
-
|
113 |
-
st.success(full_response)
|
|
|
73 |
with st.chat_message(name_to_role(message['name'])):
|
74 |
st.markdown(message['content'])
|
75 |
|
76 |
+
|
77 |
+
if prompt := st.chat_input("Start talking with your tutor!"):
|
78 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
79 |
+
with st.chat_message(name_to_role('tutor')):
|
80 |
+
st.markdown(prompt)
|
81 |
+
|
82 |
+
if st.button('Small Talk'):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
# assistant == tutor
|
84 |
+
message_placeholder = st.empty()
|
85 |
+
full_response = ""
|
86 |
+
for response in openai.ChatCompletion.create(
|
87 |
+
model=st.session_state["openai_model"],
|
88 |
+
messages=[ st.session_state.tutor_message_system_prompt ] + [
|
89 |
+
{ "role": name_to_role(m["name"]), "content": m["content"] }
|
90 |
+
for m in st.session_state.messages
|
91 |
+
],
|
92 |
+
stream=True,
|
93 |
+
api_key=API_KEY
|
94 |
+
):
|
95 |
+
full_response += response.choices[0].delta.get("content", "")
|
96 |
+
message_placeholder.markdown(full_response + "▌")
|
97 |
+
message_placeholder.markdown(full_response)
|
98 |
+
st.success(full_response)
|
99 |
+
|
100 |
+
with st.chat_message(name_to_role('student')):
|
101 |
message_placeholder = st.empty()
|
102 |
full_response = ""
|
103 |
for response in openai.ChatCompletion.create(
|
104 |
model=st.session_state["openai_model"],
|
105 |
+
messages=[
|
106 |
+
{"role": m["role"], "content": m["content"]}
|
107 |
for m in st.session_state.messages
|
108 |
],
|
109 |
stream=True,
|
|
|
110 |
):
|
111 |
full_response += response.choices[0].delta.get("content", "")
|
112 |
message_placeholder.markdown(full_response + "▌")
|
113 |
message_placeholder.markdown(full_response)
|
114 |
+
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
|