Add file content part support for multimodal chat completions#98
Merged
Conversation
PDF attachments were rejected with a 400 while images worked. The secure
attachments feature added handler-side support for OpenAI `file` content
parts (convert_messages / _convert_content_part / validate_attachments) but
never added a matching branch to the request schema.
The OHTTP inner request runs through connexion's full request-body
validation pipeline. The user-message content-part `oneOf` only allowed
text / image_url / input_audio, so a `{type:"file", file:{...}}` part
matched no branch and connexion returned 400 before the handler ran.
image_url parts (JPG/PNG) passed because they had a valid branch.
Add ChatCompletionRequestMessageContentPartFile (and its `file` object with
filename / file_data / file_id) and include it in the user content-part
oneOf, plus a regression test asserting a PDF file part passes validation.
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.
Summary
Adds support for file content parts in multimodal chat completion requests, enabling the gateway to handle PDF attachments and other file inputs alongside text and image content. This is a prerequisite for the "secure attachments" feature where PDF files arrive as OpenAI
filecontent parts.Changes
OpenAPI Schema: Added
ChatCompletionRequestMessageContentPartFileschema with nestedfileobject supporting three input modes:file_data: Base64-encoded inline file data (with optionalfilename)file_id: Reference to a previously uploaded filefilename: Name hint for inline dataUpdated the
ChatCompletionRequestUserMessageContentPartoneOfunion to include the new file part type alongside existing text, image, and audio parts.Test Coverage: Added
TestUserMessageContentPartValidationunit test class with schema-validation regression tests:test_image_part_passes_schema_validation: Verifies image content parts pass validation (baseline)test_pdf_file_part_passes_schema_validation: Verifies file content parts with PDF data pass validationTests use a standalone
_build_app()helper to build a connexion app directly from the OpenAPI spec, avoiding the optionalflask_testingdependency and ensuring validation runs in the lean test environment.Implementation Details
https://claude.ai/code/session_01HF83iVseKjA673AM4n4uN2