Hi everyone, I am new to streamlit and currently trying to build a multi-state(workflow) chatbot system with streamlit.
In my design, the llm response will be streamed to streamlit UI in json format from backend.
In streamlit, I want after a user-input question, the assistant will organize the answer into multiple expanders. Each expander represents one state with the think content inside expander.
My thoughts the code structure would be like:
with st.chat_message('user'):
st.markdown(user_input)
with st.chat_message('assistant'):
# a generator yields one json response one time
output_generator = request_handler(user_input)
for output_iter in output_generator:
if state == '0':
if first_response_in_this_state:
st.expander('state1 starts')
else:
if is_thinking:
st.expander('state1 executing...')
# update the thinkings under expander
st.markdown(thinking contents)
else:
st.expander('state1 finish...')
# update the result after the expander
elif state == '1':
....
The way I show with expander in code above probably creates mult expanders but just for explaining the code workflow. In my code, i tried to use one single expander object but don’t know how to call or modify the object properly.
I can get the UI work without using expanders. I am not sure how to change the label of expander and its corresponding expanding content dynamically in my code structure (Or maybe my structure is not a good choice). Any helps and suggestions are really appreciated.
Thanks in advanced.