Skip to main content

Module image

Module image 

Source
Expand description

Turning a file on disk into an image block a provider will accept.

One function does the whole job, and it is here rather than at each entry point because there are three of those already — the Slack connector, the TUI, and whatever comes next — and the caps below are the kind of number that gets copied once and then diverges.

Two caps, and they are enforced for different reasons:

  • MAX_BYTES is a provider limit. Anthropic rejects any single image over 5 MB outright. llama-server does not care — measured here, a 5.6 MB PNG went through and cost ~256 prompt tokens, because the server tiles it before the model ever sees it. So the cap is not about context at all: it is the smaller of what the two backends accept, applied to both, because a conversation is one object and a /model switch must not turn a working transcript into a rejected request.
  • MAX_EDGE is about what is worth carrying. Above roughly this, both families downsample server-side anyway, so the extra pixels buy nothing and are paid for twice — once on the wire, and once for the life of the session, because the transcript is append-only and every turn resends the whole history.

The second cost is the one that decides the shape here. A resized image is what gets recorded, never the original, so the bill is paid once at the door rather than on every turn afterwards.

Constants§

MAX_BYTES
The largest encoded image any provider here will be handed.
MAX_EDGE
Longest edge kept. Both provider families downsample above about this, so pixels beyond it are re-sent every turn and never looked at.

Functions§

block_from_path
Read path and produce an image block bounded by the caps above.