Streamlitcallbackhandler hide empty text

Hello, I have implemented streamlitcallbackhandler with my chat bot, but before it writes the answer there is empty text displayed.

Is there any way to hide empty text?

callback = StreamlitCallbackHandler(st.empty())
llm = ChatAnthropic(temperature=0.1, 
                    max_tokens=1000, 
                    model_name=claude- 2,
                    streaming=True,callbacks=[callback])
result = qa.invoke({"question": prompt, 
                    "chat_history": [(message["role"], 
                    message["content"]) for message in st.session_state.messages]})

Hi @starskiin3d,

Thanks for sharing your question with the community! :balloon: Please update your debugging post to include a code snippet and a link to your app’s public GitHub repo – this will allow the community to help you find an answer as quickly as possible. In the meantime, this post will be tagged as needs-more-info.

Done as you requested.

Based on the code you provided, it seems the empty is caused my passing in the st.empty to the callback handler in this line:

callback = StreamlitCallbackHandler(st.empty())

Maybe try using a container instead (I have not tested this, so let me know if it works):

callback = StreamlitCallbackHandler(st.container())

Tried that originally, same issue, the reason why i use st.empty is that once bot finishes with response there is no this small re-render happening at the end, it just finishes the process more smoothly.

But to answer your question is it still happens with st.container()

I’ll give this a try on my end and let you know. Just to be clear, you just want the “empty” message not to show before the it starts writing the processes in the expander right?

Yeah, while waiting there should be nothing there.

1 Like