Documentation
¶
Overview ¶
Package blob keeps generated media out of the model's context.
Some APIs answer with the file itself, base64'd into the JSON: a Gemini image comes back as 1.17 MB in `content[0].data`, a Lyria clip as 993 KB. Handing that to the model is roughly 300,000 tokens for one call, and the model cannot do anything with the bytes anyway — it cannot look at them, and it cannot save them.
So the bytes go to a directory and the model gets the path instead. What it needs to know is where the file is, how big it is and what it is; that fits in one line.
Index ¶
Constants ¶
const MinBytes = 8 << 10
MinBytes is the size from which a base64 string is worth writing out. Below it, the file would cost more in path and ceremony than in tokens.
Variables ¶
This section is empty.
Functions ¶
func Inline ¶ added in v1.9.0
Inline is Offload's mirror: on the way IN, a file on disk becomes the base64 the API expects.
The same asymmetry that made Offload necessary applies in reverse. To attach a 185 KB PDF to a Gmail message, the argument the model must produce is the whole RFC 2822 message, base64'd — a quarter of a megabyte it has to hold in its context and type out. The tool can take it; the model cannot carry it. Measured in the field: the send went through with a small attachment and was impossible with the real one, for that reason alone.
So the model writes `file:<path>` and the bytes never pass through it. Only that prefix is touched, at any depth, in any string argument.
SCOPED ON PURPOSE. Reading is confined to `dir` — without it, a spec (or a model reading a hostile page) could ask for any file the process can open. Everything is resolved and checked against the root, so `file:../../etc/shadow` does not leave it.
Errors are NOT fatal, as in Offload: an argument that cannot be read goes through untouched and the API answers what it answers. Swallowing the call here would hide, behind our own error, a request the model would otherwise learn from.
func Offload ¶
Offload rewrites the payload, replacing every oversized base64 string with a small object pointing at the file it was written to. Anything that is not JSON, or has nothing big in it, comes back untouched — this is a pass-through by default, never a transformation the caller has to think about.
Errors are deliberately NOT fatal: a response that could not be written to disk is still a response the model should see. In that case the original payload goes through unchanged, and the caller is left with the same behaviour it had before this package existed.
Types ¶
This section is empty.