Skip to content

Commit 7fd5df7

Browse files
committed
Reset Genie Streamlit conversation
1 parent ca0420a commit 7fd5df7

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

streamlit/views/genie_api.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ def reset_conversation():
2828
genie_space_id = st.text_input(
2929
"Genie Space ID", placeholder="01efe16a65e21836acefb797ae6a8fe4", help="Room ID in the Genie Space URL"
3030
)
31-
reset_conversation()
32-
st.session_state.genie_space_id = genie_space_id
31+
if genie_space_id != st.session_state.get("genie_space_id", ""):
32+
reset_conversation()
33+
st.session_state.genie_space_id = genie_space_id
3334

3435

3536
def display_message(message: Dict):
@@ -91,23 +92,24 @@ def process_genie_response(response: GenieMessage):
9192
conversation = w.genie.create_message_and_wait(
9293
genie_space_id, st.session_state.conversation_id, prompt
9394
)
94-
except OperationFailed as e:
95-
st.error("Conversation failed. Check the required permissions.")
96-
raise e
95+
except Exception as e:
96+
status.update(label="Conversation failed. Check the required permissions.", state="error")
97+
st.button("New Chat", on_click=reset_conversation)
98+
raise e
9799
if conversation.error:
98100
st.error(conversation.error.type, conversation.error.error)
99101
process_genie_response(conversation)
100102
else:
101103
try:
102104
conversation = w.genie.start_conversation_and_wait(genie_space_id, prompt)
103-
except OperationFailed as e:
104-
st.error("Failed to initialize Genie. Check the required permissions.")
105+
except Exception as e:
106+
status.update(label="Failed to initialize Genie. Check the required permissions.", state="error")
107+
st.button("New Chat", on_click=reset_conversation)
105108
raise e
106109
if conversation.error:
107110
st.error(conversation.error.type, conversation.error.error)
108111
process_genie_response(conversation)
109112
status.update(label="", state="complete")
110-
111113
st.button("New Chat", on_click=reset_conversation)
112114
st.link_button("Open Genie", f"{w.config.host}/genie/rooms/{genie_space_id}/chats/{st.session_state.conversation_id}")
113115
else:

0 commit comments

Comments
 (0)