Update app.py
Browse files
app.py
CHANGED
|
@@ -83,6 +83,26 @@ def remove_message(position):
|
|
| 83 |
st.toast("try to remove message no: " + str(position-1) + " and "+ str(position))
|
| 84 |
del st.session_state.messages[position-2:position]
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
st.subheader(f'{selected_model}')
|
| 87 |
|
| 88 |
# Initialize chat history
|
|
@@ -105,23 +125,7 @@ if "instant_request" not in st.session_state:
|
|
| 105 |
|
| 106 |
|
| 107 |
if st.session_state.instant_request:
|
| 108 |
-
|
| 109 |
-
pos = len(st.session_state.messages)+1
|
| 110 |
-
if "stream" in assistant:
|
| 111 |
-
with st.chat_message("assistant"):
|
| 112 |
-
col1, col2 = st.columns([9,1])
|
| 113 |
-
response = col1.write_stream(assistant["stream"])
|
| 114 |
-
col2.button("", icon = ":material/edit:", key="button_edit_message_"+str(pos), args=[pos], on_click=edit_message)
|
| 115 |
-
col2.button("", icon = ":material/delete:", key="button_remove_message_"+str(pos), args=[pos], on_click=remove_message)
|
| 116 |
-
else:
|
| 117 |
-
with st.chat_message("assistant"):
|
| 118 |
-
col1, col2 = st.columns([9,1])
|
| 119 |
-
response = col1.write("Failure!")
|
| 120 |
-
col2.button("", icon = ":material/delete:", key="button_remove_message_"+str(pos), args=[pos], on_click=remove_message)
|
| 121 |
-
|
| 122 |
-
st.session_state.messages.append({"role": "assistant", "content": response})
|
| 123 |
-
st.session_state.instant_request = False
|
| 124 |
-
|
| 125 |
|
| 126 |
# Accept user input
|
| 127 |
if prompt := st.chat_input(f"Hi I'm {selected_model}, ask me a question"):
|
|
@@ -134,18 +138,4 @@ if prompt := st.chat_input(f"Hi I'm {selected_model}, ask me a question"):
|
|
| 134 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 135 |
|
| 136 |
# Display assistant response in chat message container
|
| 137 |
-
|
| 138 |
-
pos = len(st.session_state.messages)+1
|
| 139 |
-
if "stream" in assistant:
|
| 140 |
-
with st.chat_message("assistant"):
|
| 141 |
-
col1, col2 = st.columns([9,1])
|
| 142 |
-
response = col1.write_stream(assistant["stream"])
|
| 143 |
-
col2.button("", icon = ":material/edit:", key="button_edit_message_"+str(pos), args=[pos], on_click=edit_message)
|
| 144 |
-
col2.button("", icon = ":material/delete:", key="button_remove_message_"+str(pos), args=[pos], on_click=remove_message)
|
| 145 |
-
else:
|
| 146 |
-
with st.chat_message("assistant"):
|
| 147 |
-
col1, col2 = st.columns([9,1])
|
| 148 |
-
response = col1.write("Failure!")
|
| 149 |
-
col2.button("", icon = ":material/delete:", key="button_remove_message_"+str(pos), args=[pos], on_click=remove_message)
|
| 150 |
-
|
| 151 |
-
st.session_state.messages.append({"role": "assistant", "content": response})
|
|
|
|
| 83 |
st.toast("try to remove message no: " + str(position-1) + " and "+ str(position))
|
| 84 |
del st.session_state.messages[position-2:position]
|
| 85 |
|
| 86 |
+
def ask_assistant_write_stream():
|
| 87 |
+
# Display assistant response in chat message container
|
| 88 |
+
assistant = ask_assistant_stream(model_links[selected_model], st.session_state.messages, temp_values, max_token_value)
|
| 89 |
+
pos = len(st.session_state.messages)+1
|
| 90 |
+
if "stream" in assistant:
|
| 91 |
+
with st.chat_message("assistant"):
|
| 92 |
+
col1, col2 = st.columns([9,1])
|
| 93 |
+
response = col1.write_stream(assistant["stream"])
|
| 94 |
+
col2.button("", icon = ":material/edit:", key="button_edit_message_"+str(pos), args=[pos], on_click=edit_message)
|
| 95 |
+
col2.button("", icon = ":material/delete:", key="button_remove_message_"+str(pos), args=[pos], on_click=remove_message)
|
| 96 |
+
else:
|
| 97 |
+
with st.chat_message("assistant"):
|
| 98 |
+
col1, col2 = st.columns([9,1])
|
| 99 |
+
response = col1.write("Failure!")
|
| 100 |
+
col2.button("", icon = ":material/delete:", key="button_remove_message_"+str(pos), args=[pos], on_click=remove_message)
|
| 101 |
+
|
| 102 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
|
| 106 |
st.subheader(f'{selected_model}')
|
| 107 |
|
| 108 |
# Initialize chat history
|
|
|
|
| 125 |
|
| 126 |
|
| 127 |
if st.session_state.instant_request:
|
| 128 |
+
ask_assistant_write_stream()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
# Accept user input
|
| 131 |
if prompt := st.chat_input(f"Hi I'm {selected_model}, ask me a question"):
|
|
|
|
| 138 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 139 |
|
| 140 |
# Display assistant response in chat message container
|
| 141 |
+
ask_assistant_write_stream()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|