kaleidoskop-hug commited on
Commit
5a7aeea
1 Parent(s): 47b9fa3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -3
app.py CHANGED
@@ -69,16 +69,19 @@ st.sidebar.markdown("*Generated content may be inaccurate or false.*")
69
  def edit_message(position):
70
  returnText = st.text_area("message:", value = st.session_state.messages[position-1]["content"])
71
 
72
- if st.button("Submit"):
73
  st.session_state.messages[position-1]["content"] = returnText
74
  st.rerun()
75
-
 
 
 
 
76
 
77
  def remove_message(position):
78
  st.toast("try to remove message no: " + str(position-1) + " and "+ str(position))
79
  del st.session_state.messages[position-2:position]
80
 
81
-
82
  st.subheader(f'{selected_model}')
83
 
84
  # Initialize chat history
@@ -96,6 +99,29 @@ for message in st.session_state.messages:
96
  if message["role"] == "assistant":
97
  col2.button("", icon = ":material/delete:", key="button_remove_message_"+str(pos), args=[pos], on_click=remove_message)
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  # Accept user input
100
  if prompt := st.chat_input(f"Hi I'm {selected_model}, ask me a question"):
101
  # Display user message in chat message container and Add user message to chat history
 
69
  def edit_message(position):
70
  returnText = st.text_area("message:", value = st.session_state.messages[position-1]["content"])
71
 
72
+ if st.button("Save"):
73
  st.session_state.messages[position-1]["content"] = returnText
74
  st.rerun()
75
+ if st.session_state.messages[position-1]["role"] == "user"
76
+ if st.button("Save & Retry"):
77
+ st.session_state.messages[position-1]["content"] = returnText
78
+ del session_state.messages[position-1:]
79
+ st.session_state.instant_request = True
80
 
81
  def remove_message(position):
82
  st.toast("try to remove message no: " + str(position-1) + " and "+ str(position))
83
  del st.session_state.messages[position-2:position]
84
 
 
85
  st.subheader(f'{selected_model}')
86
 
87
  # Initialize chat history
 
99
  if message["role"] == "assistant":
100
  col2.button("", icon = ":material/delete:", key="button_remove_message_"+str(pos), args=[pos], on_click=remove_message)
101
 
102
+ if "instant_request" not in st.session_state:
103
+ st.session_state.instant_request = False
104
+
105
+
106
+ if st.session_state.instant_request:
107
+ assistant = ask_assistant_stream(model_links[selected_model], st.session_state.messages, temp_values, max_token_value)
108
+ pos = len(st.session_state.messages)+1
109
+ if "stream" in assistant:
110
+ with st.chat_message("assistant"):
111
+ col1, col2 = st.columns([9,1])
112
+ response = col1.write_stream(assistant["stream"])
113
+ col2.button("", icon = ":material/edit:", key="button_edit_message_"+str(pos), args=[pos], on_click=edit_message)
114
+ col2.button("", icon = ":material/delete:", key="button_remove_message_"+str(pos), args=[pos], on_click=remove_message)
115
+ else:
116
+ with st.chat_message("assistant"):
117
+ col1, col2 = st.columns([9,1])
118
+ response = col1.write("Failure!")
119
+ col2.button("", icon = ":material/delete:", key="button_remove_message_"+str(pos), args=[pos], on_click=remove_message)
120
+
121
+ st.session_state.messages.append({"role": "assistant", "content": response})
122
+ st.session_state.instant_request = False
123
+
124
+
125
  # Accept user input
126
  if prompt := st.chat_input(f"Hi I'm {selected_model}, ask me a question"):
127
  # Display user message in chat message container and Add user message to chat history