-
Notifications
You must be signed in to change notification settings - Fork 4k
[feat] Add backend infrastructure and proto for audio in ChatInput #12832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
✅ PR preview is ready!
|
📉 Python coverage change detectedThe Python unit test coverage has decreased by 0.0611%
💡 Consider adding more unit tests to maintain or improve coverage. Coverage by files
|
22d8d70 to
0cee413
Compare
c16c9ee to
e60cd27
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for audio recording in the chat input widget by extending the protobuf messages and backend implementation to handle audio files.
- Adds
audio_file_infofield toChatInputValueprotobuf message - Adds
accept_audioboolean field toChatInputprotobuf message - Implements audio file handling with WAV validation in the Python backend
- Extends
ChatInputValuedataclass with optionalaudiofield and updates return types
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| proto/streamlit/proto/Common.proto | Adds audio_file_info field to ChatInputValue message for storing audio recording metadata |
| proto/streamlit/proto/ChatInput.proto | Adds accept_audio boolean field to control audio recording button visibility |
| lib/streamlit/elements/widgets/chat.py | Implements audio file extraction and validation logic, updates ChatInputValue dataclass with audio field |
| lib/tests/streamlit/elements/chat_test.py | Adds unit tests for audio file handling in chat input |
8fd6b69 to
893fc6a
Compare
893fc6a to
a97701e
Compare
6fbbc3e to
73aa243
Compare
This PR adds the foundational backend plumbing and protocol definitions to support audio recording in chat_input, without exposing the feature to users yet. **Backend changes:** - Add `audio` field to `ChatInputValue` type to hold recorded audio files - Add `_pop_audio_file()` helper to extract audio from proto messages - Update `ChatInputSerde.deserialize()` to handle audio file uploads - Add comprehensive Python unit tests for audio handling **Proto changes:** - Add `ChatInputValue.audio_file_info` field (Common.proto) - Add `ChatInput.accept_audio` field (ChatInput.proto) The feature remains dark-shipped: the Python API parameter `accept_audio` is not included in this PR and will be added separately. The protocol and backend can handle audio, but users cannot enable it yet. Testing: New Python unit tests validate audio file handling in ChatInputValue and deserialization logic.
Validates both file extension (.wav) and MIME type (audio/wav, audio/wave, audio/x-wav) when processing audio files in chat input. Raises clear StreamlitAPIException if validation fails to provide better error messages and prevent non-WAV files from being processed. Addresses PR feedback comment #1.
Added explanatory comment for the hasattr check when calling remove_file. The check exists because remove_file is not part of the UploadedFileManager Protocol definition, but is implemented by MemoryUploadedFileManager. This maintains compatibility with potential alternative implementations. Addresses PR feedback comment #2.
Moved the accept_file validation back to its original position (after check_widget_policies) to keep the PR diff focused on the audio input feature. This removes unnecessary code churn that makes review harder. Addresses PR feedback comment #3.
Moved the type: ignore[misc] comment back to the register_widget( line instead of the closing paren. This was an unintentional move that added noise to the diff. Addresses PR feedback comment #4.
- Add Numpydoc-style docstring with Parameters and Returns sections - Add explicit audio_file_info check to file removal guard for safety Addresses Graphite Agent feedback on PR #12832
Extract magic strings for audio file validation into module-level constants (_ACCEPTED_AUDIO_EXTENSION and _ACCEPTED_AUDIO_MIME_TYPES) to improve maintainability and make it easier to support additional audio formats. Resolves comment 1
Add comprehensive Numpydoc-style docstring to ChatInputValue dataclass, documenting its purpose, attributes (text, files, audio), and dict-like interface for users of the public API. Resolves comment 2
Add "Raises" section to _pop_audio_file docstring to document the StreamlitAPIException that can be raised during audio file validation, following Numpydoc conventions. Resolves comment 3
Replace hasattr() checks with isinstance(MemoryUploadedFileManager) for explicit type safety, ensuring only approved manager types use the cleanup logic. Resolves comment 1
73aa243 to
11a99ff
Compare
Merge activity
|

Describe your changes
Added python support for audio files in the chat input component.
Key changes:
audiofield toChatInputValueclass to store a single audio file_pop_audio_filefunction to extract audio files from protobuf messagesaccept_audioflag to the ChatInput protoTesting Plan
ChatInputValue, including:Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.