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.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.