reading

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: Apache-2.0 Imports: 4 Imported by: 2 modules, 2 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadPages

func ReadPages(ctx context.Context, r Reader, pages [][]byte, mimeType string, opts *ReadOptions) ([]string, error)

ReadPages is a convenience function that wraps raw page bytes as BinaryContent.

Types

type FallbackReader

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

FallbackReader tries multiple Readers in order, returning the first result where at least one page produced non-empty text.

func NewFallbackReader

func NewFallbackReader(readers ...Reader) *FallbackReader

NewFallbackReader creates a Reader that tries each reader in order.

func (*FallbackReader) Close

func (f *FallbackReader) Close() error

Close closes all underlying readers, collecting any errors.

func (*FallbackReader) Read

func (f *FallbackReader) Read(ctx context.Context, pages []ai.BinaryContent, opts *ReadOptions) ([]string, error)

Read tries each reader in order, returning the first result where any page produced non-empty text. If all readers fail or return empty results, returns the last error (or empty strings if no errors occurred).

type ReadOptions

type ReadOptions struct {
	// Prompt is a custom extraction prompt (empty = default OCR).
	Prompt string

	// MaxTokens is the max output tokens per page (0 = provider default).
	MaxTokens int
}

ReadOptions configures a Read call.

type Reader

type Reader interface {
	// Read extracts text from one or more pages. Each page should be a
	// single image (PNG, JPEG) or a single-page PDF as ai.BinaryContent.
	// Returns one string per input page.
	Read(ctx context.Context, pages []ai.BinaryContent, opts *ReadOptions) ([]string, error)

	// Close releases any resources held by the reader (sessions, connections, etc.)
	Close() error
}

Reader extracts text from images and single-page PDFs using OCR models.

Jump to

Keyboard shortcuts

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