gemma

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gemma asks inferd's vision model what only a model can answer: a second reading of a word Tesseract is unsure of, a description of a picture, and the values of a chart (ADR 0044).

The converter runs without it. Open reads inferd's admin socket and returns ErrUnavailable when no daemon is running, it is still loading, or its model sees no images; the caller then goes on as if it had never asked. Every answer passes a guard before it is used. A model's failures read as fluently as its successes, which is what the guards are for: a loop of repeated lines, a reply longer than its image could hold, a reply cut off by the token bound, or the wrong shape is refused, and the caller falls back.

Index

Constants

View Source
const (
	ReadPrompt     = "Transcribe the text in this image exactly as written. Output only the text."
	DescribePrompt = "Describe this image for someone who cannot see it, in one line of the form " +
		"`tag: description`, where tag is one lowercase word for what the image is (photo, diagram, " +
		"logo, screenshot, drawing, map) and description is one sentence of what it shows. " +
		"Output only that line."
	ChartPrompt = "This image is a chart. Write its data as a Markdown table: a header row naming " +
		"each column, a separator row, then one row per data point, with the values as the chart " +
		"shows them. Output only the table."
)

Prompts, each with the shape of its answer stated, since a vision model left to choose writes Markdown, LaTeX and a preamble. ReadPrompt is the one the word-reading spike measured; Google's documented question, "What does the text in this image say?", was answered with a summary and matched 2 of 712 words (ADR 0043).

Variables

View Source
var ErrRefused = ocr.ErrRefused

ErrRefused reports that an answer failed its guard. It is ocr.ErrRefused, so ocr.Confirm counts a refusal as a disagreement and any other error as the model failing.

View Source
var ErrUnavailable = errors.New("inferd has no ready vision model")

ErrUnavailable reports that inferd has no ready model that sees images.

Functions

func Clean

func Clean(s string) string

Clean removes leaked control tokens and the space around the answer. A captioning reply the user ran through transformers ended in "<turn|>".

func GuardRead

func GuardRead(s string, maxRunes int) error

GuardRead is Read's guard.

func Loops

func Loops(s string) bool

Loops reports a repetition loop, the failure a vision model ends in on dense input: a line said three times or more where there are four lines or more, or a run of one word eight times. The spike saw three lines repeated fifty times on one page.

func ParseTable

func ParseTable(s string) ([][]string, error)

ParseTable reads a GFM table from s: a header row, a separator row, then data rows.

func RGB

func RGB(img image.Image) []byte

RGB packs img as width*height*3 interleaved octets, the daemon's image format (inferd ADR 0016): it links no codec, so the bytes go as decoded pixels. Alpha is dropped.

Types

type Description

type Description struct{ Tag, Text string }

Description is a picture described: what kind of image it is, and what it shows.

func ParseDescription

func ParseDescription(s string) (Description, error)

ParseDescription reads "tag: description" from s.

func (Description) String

func (d Description) String() string

String is the Markdown form, "tag: description".

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model is inferd's vision backend.

func Open

func Open(ctx context.Context, addr, admin string, timeout time.Duration) (*Model, error)

Open finds inferd's vision backend from its admin socket. addr and admin are the generation and admin endpoints, empty for the platform defaults, and timeout bounds each request to the model: zero is inferd.DefaultTimeout, and negative waits as long as the model takes.

func (*Model) Chart

func (m *Model) Chart(ctx context.Context, img image.Image) ([][]string, error)

Chart reads a chart's values as a table, header first. Its guard refuses a reply that is not a GFM table of at least one data row, with every row as wide as the header.

func (*Model) Describe

func (m *Model) Describe(ctx context.Context, img image.Image) (Description, error)

Describe describes a picture. Its guard refuses any reply not of the form "tag: description".

func (*Model) Name

func (m *Model) Name() string

Name identifies the model for the page report: "gemma-4-e4b via inferd".

func (*Model) Read

func (m *Model) Read(ctx context.Context, img image.Image, maxRunes int) (string, error)

Read is a second reading of the text in a crop, a word or a line, of at most maxRunes characters. Its guard refuses a loop, a reply longer than maxRunes, a reply on more lines than the crop could hold, and Markdown or LaTeX, which a transcription has no use for.

Jump to

Keyboard shortcuts

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