feat: add FilePart and user_message_with_file for document inputs - #42
Open
osvaldoM wants to merge 2 commits into
Open
feat: add FilePart and user_message_with_file for document inputs#42osvaldoM wants to merge 2 commits into
osvaldoM wants to merge 2 commits into
Conversation
Providers accept documents (e.g. PDFs) natively as file parts alongside
text and image parts; the model then reads both the embedded text layer
and the rendered pages. Serializes to the Mastra /generate wire format
({type: 'file', data: <data URL>, mediaType, filename?}), verified
end-to-end against a local Mastra with Azure gpt-5.2.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…n README Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
osvaldoM
marked this pull request as ready for review
August 19, 2026 09:15
sizief
approved these changes
Aug 21, 2026
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.
What
Adds
Ai::FilePart(alongsideTextPart/ImagePart) and anAi.user_message_with_file(text, file_data, media_type, filename: nil)helper, and widensMessageContentto accept it.Why
The expenses OCR pipeline currently rasterizes every PDF to a JPEG before sending it to the vision model — even digital PDFs whose exact text is embedded in the file. Sending the PDF as-is lets the provider use the embedded text layer: in a head-to-head on real documents this was ~20% faster on text-based PDFs and extracted several identifiers (invoice numbers, tax IDs) digit-exact that the rasterized path misread.
First consumer:
Ocr::FinancialDocument::Providers::FactorialAgent::OcrClientin the monolith (https://github.com/factorialco/factorial/pull/110406).Testing
verified end-to-end against Mastra's
/api/agents/:id/generateroute with Azuregpt-5.2, which answered correctly from an attached PDF.