Hello!
I’ve made a Streamlit chatbot and I currently have it behind okta. A snippet of my code is below.
What happens:
when you click the ‘Click to login via OKTA’ which is the st_oauth function that does a post request to Okta token verification etc. it brings me to my app which is great. Then I select a table from a drop down and I click submit, which works great also.
However… when I click the Reset button if I have the ‘del st.session_state()’ code this sends me back to the “login to okta”… I want it to just clear the chat
If possible I’d like to get rid of the “Reset” button and just be able to “Submit” a table more then once from the selectbox.
streamlit_app1.py
hi = st_oauth('myoauth', 'Click to login via OKTA')
selected_table = st.sidebar.selectbox(
"Select a table to view the data definition:", options=list(snow_ddl.ddl_dict.keys())
)
click = st.sidebar.button("Submit", type="primary")
reset_chat = st.sidebar.button("Reset Chat")
# Add a reset button
if reset_chat:
for key in st.session_state.keys():
print(f'key in st.session_state {st.session_state}')
print(f'key in reset chat: {st.session_state.keys()}')
st.empty()
# st.session_state.page = ""
# st.experimental_rerun()
# del st.session_state[key] // this doesnt work as it should because it makes me click the login via okta link again above
if click:
print(f"this is the selected table: {selected_table}")
key_to_check = selected_table # users selection of article, social, etc.
tables_available = [category[key_to_check] for category in table_categories if key_to_check in category]
tables_description = [category['table_description'] for category in table_categories if
key_to_check in category]
print(f'tables_available... {tables_available}')
print(f"st.session_state after click: {st.session_state}")
if "messages" not in st.session_state:
# system prompt includes table information, rules, and prompts the LLM to produce
# a welcome message to the user.
print(f'begin session_state role system...')
st.session_state.messages = [{"role": "system", "content": get_system_prompt(tables_available[0], tables_description)}]
# Prompt for user input and save
if prompt := st.chat_input():
st.session_state.messages.append({"role": "user", "content": prompt})