Skip to content

feat: add FilePart and user_message_with_file for document inputs - #42

Open
osvaldoM wants to merge 2 commits into
mainfrom
feat/file-part-messages
Open

feat: add FilePart and user_message_with_file for document inputs#42
osvaldoM wants to merge 2 commits into
mainfrom
feat/file-part-messages

Conversation

@osvaldoM

@osvaldoM osvaldoM commented Aug 18, 2026

Copy link
Copy Markdown

What

Adds Ai::FilePart (alongside TextPart/ImagePart) and an Ai.user_message_with_file(text, file_data, media_type, filename: nil) helper, and widens MessageContent to 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::OcrClient in the monolith (https://github.com/factorialco/factorial/pull/110406).

Testing

verified end-to-end against Mastra's /api/agents/:id/generate route with Azure gpt-5.2, which answered correctly from an attached PDF.

osvaldo and others added 2 commits August 18, 2026 21:29
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
osvaldoM marked this pull request as ready for review August 19, 2026 09:15
@osvaldoM
osvaldoM requested a review from a team as a code owner August 19, 2026 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants