How to add widget in chat_message and keep them in chat history

I’m developing a chat robot and I want to implement a feature that allow user evaluate every message from assistant, just like below

20240607183610

The solution seems add some widget just like button within chat_message.

But the problem is there is a refresh when new conversation occurred. Below is the code. (Sorry, i fail to find the way to insert code)

for message in st.session_state.messages:
i = 0
with st.chat_message(message[“role”]):
st.markdown(message[“content”])
if message[‘role’] == ‘assistant’:
st.button(‘Begin’, key=i, on_click=set_state, args=)
i += 1

There will be an error that duplicate widget id.

I want to ask two questions:
1, How to delete button with key?
2. Is there a recommend solution for this case?

Thanks.

Use the button </> (preformatted text).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.