Hi everyone,
I have a chat_input
instance defined as:
container.chat_input(
placeholder="Ask anything", key=constants.ChatKeys.CHAT_INPUT.value, accept_file=True, file_type=constants.VALID_FILE_FORMATS
)
In version earlier than 1.43.0 (python 3.12), before file attachment option was embedded in chat input, I was able to successfully test this line as follows:
at.chat_input(key=constants.ChatKeys.CHAT_INPUT.value).set_value(prompt).run()
However, after v1.43.0, with the file attachment option being used, I get the following stack trace from at.exception
with an AttributeError
:
"/Users/user1/miniconda3/envs/chatbot/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 121, in exec_func_with_error_handling
result = func()
^^^^^^
"/Users/user1/miniconda3/envs/chatbot/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 546, in code_to_exec
self._session_state.on_script_will_rerun(
"/Users/user1/miniconda3/envs/chatbot/lib/python3.12/site-packages/streamlit/runtime/state/safe_session_state.py", line 68, in on_script_will_rerun
self._state.on_script_will_rerun(latest_widget_states)
"/Users/user1/miniconda3/envs/chatbot/lib/python3.12/site-packages/streamlit/runtime/state/session_state.py", line 558, in on_script_will_rerun
self._call_callbacks()
"/Users/user1/miniconda3/envs/chatbot/lib/python3.12/site-packages/streamlit/runtime/state/session_state.py", line 567, in _call_callbacks
wid for wid in self._new_widget_state if self._widget_changed(wid)
^^^^^^^^^^^^^^^^^^^^^^^^^
"/Users/user1/miniconda3/envs/chatbot/lib/python3.12/site-packages/streamlit/runtime/state/session_state.py", line 579, in _widget_changed
new_value = self._new_widget_state.get(widget_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
"/Users/user1/miniconda3/envs/chatbot/lib/python3.12/_collections_abc.py", line 807, in get
return self[key]
~~~~^^^^^
"/Users/user1/miniconda3/envs/chatbot/lib/python3.12/site-packages/streamlit/runtime/state/session_state.py", line 128, in __getitem__
deserialized = metadata.deserializer(value, metadata.id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
"/Users/user1/miniconda3/envs/chatbot/lib/python3.12/site-packages/streamlit/elements/widgets/chat.py", line 206, in deserialize
files=_pop_upload_files(ui_value.file_uploader_state),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Upon further deep-dive into the call stack, it seems that the, while testing,ChatInputSerde.deserialize
method is receiving ui_value
argument of type streamlit.proto.Common_pb2.StringTriggerValue
when it’s expecting the type streamlit.proto.Common_pb2.ChatInputValue
.
In an actual (non-test) successful run, the same ChatInputSerde.deserialize
method receives the correct ui_value
argument of type streamlit.proto.Common_pb2.ChatInputValue
.
I suspect that the app testing framework isn’t updated to match the new spec as I noticed the following code block setting the seemingly deprecated legacy string_trigger_value
in widget state for chat input instead of chat_input_value
in streamlit.testing.v1.element_tree.ChatInput
:
@property
def _widget_state(self) -> WidgetState:
ws = WidgetState()
ws.id = self.id
if self._value is not None:
ws.string_trigger_value.data = self._value
return ws
Any thoughts on this issue regarding fixes or workarounds?
Python: v3.12
Streamlit: v1.43.1