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_BYTESis 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/modelswitch must not turn a working transcript into a rejected request.MAX_EDGEis 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
pathand produce an image block bounded by the caps above.