fix(openai): omit filename for URL-backed PDFs in Responses API requests#2166
Open
dgrijalva wants to merge 1 commit into
Open
fix(openai): omit filename for URL-backed PDFs in Responses API requests#2166dgrijalva wants to merge 1 commit into
dgrijalva wants to merge 1 commit into
Conversation
The PDF arm of TryFrom<crate::completion::Message> for Vec<InputItem>
set filename: Some("document.pdf") unconditionally, so URL-backed PDFs
were serialized with both file_url and filename — a combination the
Responses API rejects with 400 mutually_exclusive_parameters. PR 0xPlaygrounds#1432
fixed the same bug in the parallel TryFrom<message::Message> for
Vec<Message> conversion, but not on this path, which is the one
CompletionModel::completion() requests are built through.
filename now comes from the same match as file_data/file_url:
Some("document.pdf") for base64 documents, None for URLs.
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.
Fixes #2164
Problem
Two conversions in
responses_api/mod.rsproduceinput_filecontent parts. #1432 (closing #1429) fixedTryFrom<message::Message> for Vec<Message>, but requests built byCompletionModel::completion()go throughTryFrom<crate::completion::Message> for Vec<InputItem>, whose PDF arm still setfilename: Some("document.pdf")unconditionally — including alongsidefile_url, which the API rejects with 400mutually_exclusive_parameters(file inputs docs).Implementation
filenameis now produced by the samematchasfile_data/file_url:Some("document.pdf")for base64 documents,Nonefor URLs — mirroring what #1432 did in the parallel conversion. No public API changes.Testing
input_fileJSON for URL PDFs on all three paths (Vec<InputItem>, the full wire request viaTryFrom<(String, CompletionRequest)>, andVec<Message>), plus base64 PDFs keeping their filename.url_pdf_document_promptrecorded against the live API (recording fails with the 400 before this fix); full OpenAI cassette suite replays green.cargo clippy --all-features --all-targetsandcargo fmt -- --checkclean.Related: #1429, #1432