Hi everyone,
I’m developing a streamlit app where I want my streamlit multiselect to have default values ( array ) based on an LLM call.
But, I’m getting error when one or more element of default array is not present in the options array. I know this is streamlit’s characteristic but I want a feature like this. Is there any workaround for my use case ?
Workflow of my app :
User makes an LLM call. LLM returns a JSON . These JSON values get prepopulated in the form. All of the form inputs are of multiselect type and I use ‘default’ array to prepopulate these JSON values, I get ‘options’ array of the multiselect by an api call . I get error when one or more element of the default array is not present in the options array.
Hello,
Do you have some example code?
I used to have kind of the same isue, but not sure if it will work for your specific problem :
options = ["apple", "banana", "cherry", "date"]
# Default values returned by LLM call
default_values = ["apple", "blueberry", "cherry"]
# Filter the default values to only include those in options
filtered_defaults = [value for value in default_values if value in options]
# Use the filtered defaults in the multiselect
selected_values = st.multiselect(
"Select fruits",
options=options,
default=filtered_defaults
)
With only selectbox :
index_adjust = [YOURLIST].index(self.default_options.get("FROMLLM", [YOURLIST][0]))
options['adjust_pfs'] = st.selectbox('This is an example', [YOURLIST],
key=f'adjust', index=index_adjust)
Hi @Faltawer ,
thanks for replying.
I’m following a similar approach like the code you shared. But, I want that in multiselect all of the values returned by the LLM should be set as it is.
I know it is not possible with multiselect because that is it’s default behaviour.
But I somehow need to have all the options returned by the LLM.
What other kind of solutions could there be? If a selected value is not in the options and it gets accidentally deleted by the user, it cannot be added again. That doesn’t look like good UX.