fix(core): use parsed mime_type for base64 file blocks in openai translator#126
Open
LennyMalcolm0 wants to merge 3 commits into
Open
fix(core): use parsed mime_type for base64 file blocks in openai translator#126LennyMalcolm0 wants to merge 3 commits into
LennyMalcolm0 wants to merge 3 commits into
Conversation
… file blocks The base64 file branch in `_convert_openai_format_to_data_block` was hard-coding `mime_type="application/pdf"`, while the image branch right above used `parsed["mime_type"]`. So a non-PDF data URI (e.g. CSV) passed via the OpenAI Chat Completions file block shape got silently relabeled as PDF in the v1 content block, which is wrong for non-OpenAI chat models that consume v1 blocks via shared `_normalize_messages`. Changes: 1. Use `parsed["mime_type"]` in the base64 file branch, matching the image branch right above it. 2. In `convert_to_openai_data_block(api="chat/completions")`, raise a clear `ValueError` when MIME is not `application/pdf`, pointing the caller to the Responses API. This keeps Chat Completions semantics intact and fails fast with a friendlier error than OpenAI's raw 400. 3. Regression tests for both behaviors. Fixes langchain-ai#36939
AI review: all acceptance criteria metThe pull request successfully addresses the issue where the MIME type for base64 file blocks was hardcoded to 'application/pdf'. By extracting the MIME type from the parsed data URI, it now correctly supports non-PDF file types like CSV and plain text. All acceptance criteria are fully met, and appropriate unit tests have been added to verify the changes. Acceptance criteriaMet
SuggestionsNitpicks
|
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 langchain-ai#36939.
The file branch of
_convert_openai_format_to_data_blockhard-codesmime_type="application/pdf", while the image branch right above it usesparsed["mime_type"]from the data URI. So a CSV sent via the OpenAI file block shape comes out withmime_type="application/pdf"in the v1 content block.One-line change to read it off the parsed data URI, same as the image branch.
_parse_data_urireturnsNonewhen the mime_type is missing, soparsed["mime_type"]is always set inside this branch.Test added with a CSV and a text/plain data URI. Existing tests still pass since they use
data:application/pdf;....Cloned from langchain-ai#36940 for DevAsign stress testing.