Skip to content

Commit 0e6e4dd

Browse files
committed
feat: provisional solution to streamlit issue st.chat_input collapse after submit #12081
1 parent 058ea95 commit 0e6e4dd

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

pages/ask_uos_chat.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,10 @@ def handle_user_input(self):
236236
user_id = self.get_user_id()
237237
history = self.get_history(user_id)
238238

239-
if prompt := st.chat_input(placeholder=session_state["_"]("Message")):
239+
if prompt := st.chat_input(
240+
placeholder=session_state["_"]("Message"),
241+
key=f"chat_input_{st.session_state.input_key_counter}",
242+
):
240243
if not session_state.feedback_saved:
241244
self.log_feedback()
242245
st.session_state.feedback_saved = False
@@ -254,6 +257,10 @@ def handle_user_input(self):
254257
if history.messages[-1].type != ROLES[0]: # "ai"
255258
self.generate_response(prompt)
256259

260+
st.session_state.input_key_counter += 1
261+
262+
st.rerun() # Rerun to update the chat messages and input field
263+
257264
def get_agent(self):
258265
if st.session_state["agent"] is None:
259266
st.session_state["agent"] = CampusManagementOpenAIToolsAgent.run(

pages/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def initialize_session_sate() -> None:
2424
"agent_language": settings.language,
2525
"agent": None,
2626
"ask_uos_user_id": None,
27+
"input_key_counter": 0,
2728
}
2829

2930
for key, value in defaults.items():

0 commit comments

Comments
 (0)