fix: replace unsupported 'file' content type with text fallback for PDF (#1832)#1838
Closed
echoVic wants to merge 1 commit intoQwenLM:mainfrom
Closed
fix: replace unsupported 'file' content type with text fallback for PDF (#1832)#1838echoVic wants to merge 1 commit intoQwenLM:mainfrom
echoVic wants to merge 1 commit intoQwenLM:mainfrom
Conversation
…DF (QwenLM#1832) DashScope/Qwen API returns 400 error when receiving content parts with type: 'file'. The API only supports 'text', 'image_url', 'video_url', and 'video' content types. When read_file reads a PDF, the converter was generating type: 'file' parts which DashScope rejects. This change replaces PDF content parts with a descriptive text fallback, preventing the 400 error. - Remove OpenAIContentPartFile type (no longer used) - Convert inlineData PDF parts to text description instead of file type - Convert fileData PDF parts to text description instead of file type - Update converter tests to match new behavior Fixes QwenLM#1832
Collaborator
|
@echoVic Thank for your contribution! But we're going with #1982 because it solves the same problem more comprehensively: instead of blocking PDFs entirely, it assigns appropriate modalities per model. This means we can support it once a model can read PDFs natively. Thanks again for taking the time to dig into this and write such a thorough PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
read_filereads a PDF file, the OpenAI content converter generates content parts withtype: 'file', but DashScope/Qwen API only supportstext,image_url,video_url, andvideocontent types. This causes a 400 error:Root Cause
In
converter.ts, thecreateMediaContentPartmethod converts PDFinlineDataandfileDataparts totype: 'file'format (OpenAIContentPartFile), which is not supported by the DashScope API.Fix
type: 'file'formatOpenAIContentPartFiletype definitionAll 49 existing tests pass.
Fixes #1832