Add native document encoder - #185
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces two new document encoders, "document_url" and "native", to support direct base64-encoded document passthrough for gateway and OpenAI-compatible backends. It also registers these encoders, adds corresponding unit tests, and exposes an "--extra-body" option in the "cat" command. Feedback on the changes highlights that importing the private helper "_to_message" from "mm.encoders.image" in both new encoders introduces tight coupling, and suggests refactoring it into a shared module or constructing the message dictionary directly.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| yield to_message( | ||
| [ | ||
| { | ||
| "type": "file", |
There was a problem hiding this comment.
This is supposed to be input_file with file_url key: see https://developers.openai.com/api/docs/guides/file-inputs#file-urls
There was a problem hiding this comment.
The shapes in the link you shared don't work with openrouter models. Here's what worked.
pdf_path = "path/to/your/document.pdf"
base64_pdf = encode_pdf_to_base64(pdf_path)
data_url = f"data:application/pdf;base64,{base64_pdf}"
messages = [
{
"role": "user",
"content": [
{
"type": "file",
"file": {
"filename": "document.pdf",
"file_data": data_url
}
},
]
}
]
Refs:
- https://openrouter.ai/docs/guides/overview/multimodal/pdfs#using-base64-encoded-pdfs
- https://openrouter.ai/docs/guides/overview/multimodal/pdfs#using-pdf-urls|
I think we need to introduce an
|
We can wire it at the encoder level without needing to write a new pipeline, which would warrant plumbing given pipelines are detected based on the file kind. |
Co-Authored-By: Chukwuma Nwaugha <nwaughac@gmail.com>
Co-Authored-By: Chukwuma Nwaugha <nwaughac@gmail.com>
Can we do this as a followup? Also, do you have additional reviews to bring this PR to a good place for merging? |
Summary
Adds two new document encoders and updates all documentation to reflect them.
nativeencoder passes the raw document as an OpenAI-compatible base64 file part (the document analogue of the existing video native encoder),document_urlpasses it as a base64 document_url part — the native input shape accepted by thevlm.rungateway for models with native PDF document input support.Both encoders don't initiate page extraction, rasterization, or text parsing, mirroring the design of the existing
gemini-nativedocument encoder.How to test
Implements VLM-433