feat(model/claude): translate file/PDF parts to Anthropic document blocks - #919
Open
gutopolewacz wants to merge 1 commit into
Open
feat(model/claude): translate file/PDF parts to Anthropic document blocks#919gutopolewacz wants to merge 1 commit into
gutopolewacz wants to merge 1 commit into
Conversation
…ocks A schema.ChatMessagePartTypeFileURL content part (e.g. a PDF returned by the filesystem middleware's multimodal read_file over a MultiModalReader backend) had no translation and fell into the default branch, failing with "anthropic message type not supported: file". Add a case for ChatMessagePartTypeFileURL to both convSchemaMessage (user-input multi content) and convToolMultiContent (tool result), mapping a PDF file part to an Anthropic document block (Base64PDFSource or URLPDFSource). The handling mirrors the existing image case (URL vs raw base64, MIMEType required for base64, reject a "data:" prefix), with an application/pdf guard because the base64 document source is PDF-only. Documents are supported inside tool results via ToolResultBlockParamContentUnion.OfDocument, so the multimodal read_file path can now deliver a PDF to the model natively. No new dependency.
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.
Refs #918
What
Adds translation of
schema.ChatMessagePartTypeFileURL(PDF) content parts to the Anthropic Messagesdocumentblock incomponents/model/claude.Why
Currently a PDF file part errors with
anthropic message type not supported: file. This blocks the multimodalread_fileflow (theadk/middlewares/filesystemmiddleware withUseMultiModalRead: trueover aMultiModalReaderbackend such asadk/backend/local): a PDF arrives as aFileContentPartTypePDFpart, is converted by theschemalayer toMessageInputPart{Type: ChatMessagePartTypeFileURL, File}, and then fails at the Claude translation layer — so a PDF read cannot be delivered to the model as a native document.How
convSchemaMessage(user-input multi content) andconvToolMultiContent(tool result) gain acase schema.ChatMessagePartTypeFileURL.pdfDocumentSourceandnewPDFDocumentBlock, build theDocumentBlockParamfrom the file part (URL or raw base64).data:prefix. Anapplication/pdfguard is added because the base64 document source is PDF-only.ToolResultBlockParamContentUnion.OfDocument, so the tool path (the multimodalread_filecase) works.Tests
Added
Test_convSchemaMessage_Document, mirroringTest_convSchemaMessage_MultiContentfor the document path: base64 success, URL success,data:-prefix error, missing-MIME error, non-PDF-MIME error, missing-source error, and the tool-result path (base64 + nil-file).Compatibility
Purely additive; existing text/image behavior is unchanged. No new dependency and no SDK bump —
DocumentBlockParam,Base64PDFSourceParam,URLPDFSourceParam, andToolResultBlockParamContentUnion.OfDocumentare all present in the currently usedanthropic-sdk-go.