feat: expand SupportedContentType enum with common media types#2233
feat: expand SupportedContentType enum with common media types#2233lxcxjxhx wants to merge 2 commits into
Conversation
Add support for image, audio, video, and document content types to address TODO comment in storage.py. This enables PyRIT to handle multimodal data (images, audio, video, PDFs) when uploading to Azure Blob Storage. Added types: - Text: HTML, JSON, XML, CSV, Markdown - Image: PNG, JPEG, GIF, WebP, SVG, BMP - Audio: WAV, MP3, OGG, FLAC, M4A - Video: MP4, WebM, OGG, AVI - Document: PDF, ZIP, TAR, GZIP Includes unit tests to verify all enum values.
| # TODO, add other media supported types | ||
| # Text types | ||
| PLAIN_TEXT = "text/plain" | ||
| HTML = "text/html" |
There was a problem hiding this comment.
I don't think these values change normal upload behavior: AzureSQLMemory leaves AzureBlobStorageIO at its text/plain default, and serializers cannot pass a per-file content type. Please wire MIME selection into write_file_async (or infer it from the path/serializer) and consolidate the separate AzureBlobStorageTarget enum; otherwise this does not enable the advertised media types.
There was a problem hiding this comment.
Thank you for the detailed feedback, @romanlutz! I've addressed your concerns:
-
Modified
AzureBlobStorageIO.write_file_async: Added an optionalcontent_typeparameter that allows specifying the MIME type per file. -
Auto-detection of MIME types: Implemented logic using
mimetypes.guess_typeto automatically infer the content type from file extensions when not explicitly provided. -
Updated serializers: Modified
save_data_async,save_b64_image_async, andsave_formatted_audio_asyncto pass the inferredcontent_typewhen saving data. -
Consolidated
SupportedContentTypeenum: Removed the duplicateAzureBlobStorageTargetenum and unified the content type definitions inpyrit.memory.storage.storage. -
Added unit tests: Created tests to verify the content type inference and propagation logic.
-
Testing: Due to local environment constraints (incomplete dependencies on Windows), I'm relying on the CI/CD pipeline to run the full test suite automatically.
The changes should now properly enable the advertised media types by wiring MIME selection into the file upload workflow. Please let me know if you need any additional modifications!
- Modify AzureBlobStorageIO.write_file_async to accept content_type parameter - Infer content_type from file extension using mimetypes.guess_type - Pass content_type through serializers (save_data_async, save_b64_image_async, save_formatted_audio_async) - Consolidate SupportedContentType enum imports - Add unit tests for content_type inference and propagation Addresses maintainer feedback on PR microsoft#2233
|
感谢 @romanlutz 的详细反馈!我已经按照您的建议进行了修改:
这些修改应该能够正确支持广告中声明的媒体类型,通过将 MIME 选择逻辑集成到文件上传工作流中。如果需要进一步修改,请告诉我! |
|
@microsoft-github-policy-service agree |
|
For context, I'm adding a translation here (I can't read Chinese):
|
Motivation
The \SupportedContentType\ enum in \pyrit/memory/storage/storage.py\ had a TODO comment indicating that more media types should be added. Currently only \PLAIN_TEXT\ was supported, which limits PyRIT's ability to handle multimodal data (images, audio, video, PDFs) when uploading to Azure Blob Storage.
This is particularly relevant since the existing doc example \doc/code/executor/5_workflow.py\ already references \SupportedContentType.HTML\ which doesn't exist in the enum yet.
Changes
Expanded \SupportedContentType\ enum with commonly used media types:
Text types: HTML, JSON, XML, CSV, Markdown
Image types: PNG, JPEG, GIF, WebP, SVG, BMP
Audio types: WAV, MP3, OGG, FLAC, M4A
Video types: MP4, WebM, OGG, AVI
Document types: PDF, ZIP, TAR, GZIP
Added unit test \ est_supported_content_type_has_expected_values\ to verify all enum values.
Testing
Checklist