Documentation
¶
Overview ¶
Package vision turns verified image bytes into bounded text.
Index ¶
- Constants
- func ExtractWithXberg(ctx context.Context, path string) (string, error)
- func NormalizeXbergBaseline(text string) string
- func PrepareInline(data []byte, cfg image.Config, mime string) ([]byte, string, error)
- func PrepareRendererPayloadContext(ctx context.Context, data []byte, cfg image.Config, mime string) ([]byte, string, error)
- func ValidateBudget(data []byte) (image.Config, error)
- func ValidateImage(data []byte, declaredMIME string) (image.Config, string, error)
- type BaselineRenderer
- type Options
- type Request
- type Service
- type StreamBuilder
Constants ¶
const ( // MaxImageDim is retained for legacy inline tool rendering. Canonical // baselines preserve source dimensions unless their encoded payload exceeds // MaxRendererPayloadBytes. MaxImageDim = 2000 // MaxRendererPayloadBytes is the hard provider image payload ceiling. MaxRendererPayloadBytes = 5 * 1024 * 1024 // MaxImageInputBytes aliases the canonical session-ingress ceiling. Together // with MaxImagePixels, it protects model and Xberg paths from compressed-byte // and decompression-bomb inputs. MaxImageInputBytes = ai.MaxImageInputBytes MaxImagePixels = 50_000_000 )
const ( // BaselineVLMTimeout leaves five seconds of Enricher's 15 second message // budget for Xberg after a slow model attempt. BaselineVLMTimeout = 10 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func ExtractWithXberg ¶
ExtractWithXberg shells out to the Xberg CLI to extract text from a file. It returns an error when the binary is missing or extraction fails.
func NormalizeXbergBaseline ¶
NormalizeXbergBaseline makes local OCR conform to the same durable contract without inventing scene understanding that Xberg does not provide.
func PrepareInline ¶
PrepareInline preserves the old read-tool behavior: fit to MaxImageDim.
func PrepareRendererPayloadContext ¶
func PrepareRendererPayloadContext(ctx context.Context, data []byte, cfg image.Config, mime string) ([]byte, string, error)
PrepareRendererPayloadContext keeps original pixels and dimensions untouched whenever they fit the renderer payload ceiling. Both baseline rendering and active provider hydration use this adaptive payload preparation. Only a hard payload overflow causes reduction; no fixed dimension ceiling or tiling is applied. The standard-library decode/encode calls themselves are not interruptible, so it checks ctx around each potentially expensive step.
func ValidateBudget ¶
ValidateBudget rejects unsafe image bytes before full decode for callers that do not have a declared MIME to compare.
Types ¶
type BaselineRenderer ¶
BaselineRenderer is the narrow contract session-media enrichment needs. Implementations must honor ctx promptly. Enricher protects its message deadline from non-cooperative renderers, but at most two abandoned calls may continue in the background until their implementation returns.
type Options ¶
type Options struct {
Model ai.Model
APIKey string
Build StreamBuilder
}
Options configures a Service.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service owns one resolved baseline provider. Canonical enrichment resolves a fresh Service for each image-bearing message so deployment settings are not runner-snapshot state.
func New ¶
New creates a service. A missing or invalid model is intentionally an Xberg-only service rather than a construction error.
func NewFromSnapshot ¶
func NewFromSnapshot(snap *config.Snapshot, build StreamBuilder) *Service
NewFromSnapshot builds a service from one current application snapshot.
func (*Service) Baseline ¶
Baseline produces the sole canonical generic OCR + scene representation. A ready result is returned only after an explicit clean stop and exact contract validation. Model failures fall back to Xberg using the verified same bytes.
func (*Service) ModelConfigured ¶
type StreamBuilder ¶
type StreamBuilder func(api, apiKey, baseURL string) (providers.StreamFunc, error)
StreamBuilder constructs a provider stream for one API/credential pair.