feat: add multi-modal input support (image, PDF, audio) across all content generators - #1564
Conversation
📋 Review SummaryThis PR implements comprehensive multi-modal input support (images, PDFs, and audio files) across all content generators (OpenAI-compatible, Gemini, and Anthropic). The core change embeds binary media directly in 🔍 General Feedback
🎯 Specific Feedback🟡 High
🟢 Medium
🔵 Low
✅ Highlights
|
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
Convert Gemini video parts into OpenAI-compatible `video_url` entries and keep `file` for PDFs. Co-authored-by: Cursor <cursoragent@cursor.com>
feat: add multi-modal input support (image, PDF, audio) across all content generators
TLDR
This PR implements comprehensive multi-modal input support (images, PDFs, and audio files) across all three content generators: OpenAI-compatible, Gemini, and Anthropic.
Strategic Importance: Multi-modal support is a critical foundation for expanding Qwen Code's capabilities beyond pure coding environments. This enables:
This lays the groundwork for Qwen Code to evolve from a coding-focused tool into a comprehensive AI assistant for broader computer use and collaborative work scenarios.
Key changes:
FunctionResponse.partsfor proper propagationimageblocks, PDFs todocumentblocks, with graceful fallback for unsupported typesimage_url, audio toinput_audio, and files (including PDFs) tofiletypefileDatastructure (instead ofinlineData) for better cross-provider compatibilityDive Deeper
Architecture Changes
The previous approach returned binary content with a simple text description like
"Binary content of type image/png was processed.", which prevented the model from actually seeing the content. The new approach:coreToolScheduler.ts): ModifiedcreateFunctionResponsePartto accept optionalmediaPartsparameter. Media is now properly embedded infunctionResponse.parts:Anthropic Converter: Complete refactoring to process parts inline and create proper media blocks:
type: 'image'with base64 sourcetype: 'document'with base64 sourceOpenAI Converter: Added
createToolMessageandcreateMediaContentPartmethods:type: 'image_url'with data URLtype: 'input_audio'with format detection (wav, mp3, etc.)type: 'file'with filename and dataPDF Handling: PDFs are now transmitted as
fileDatarather thaninlineDatasince Anthropic requires thedocumenttype for PDFs, and OpenAI-compatible APIs handle them as files.Additional Improvements
displayNameto all media content for better traceabilityreasoningfield (in addition toreasoning_content) in OpenAI responses for broader compatibility.gemini-clipboardto.qwen-clipboardfor branding consistencyReviewer Test Plan
Image Reading: Ask the model to read and describe an image file
PDF Reading: Ask the model to read and summarize a PDF document
Tool Use with Images: Ask the model to use tools that involve reading multiple images
Clipboard Paste: Test Ctrl+V with an image in clipboard
Provider/Modality Test Matrix
Linked issues / bugs
Closes #1504