fix(core): use parsed mime_type for base64 file blocks in openai translator#36940
Conversation
This comment has been minimized.
This comment has been minimized.
|
Closing pending discussion on the issue. |
Merging this PR will not alter performance
Comparing Footnotes
|
e81839c to
805b11c
Compare
|
Pushed an update following the discussion on #36939. Kept the original |
… 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
805b11c to
58f0d26
Compare
Fixes #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;....