blob

package
v1.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 7 Imported by: 0

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

View Source
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

func Inline(args map[string]any, dir string, urlSafe bool) map[string]any

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

func Offload(payload, dir string, min int) string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL