ocr

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GeminiDirectModel = geminiModel

	GeminiBatchModel = geminiModel
	// Reserve 100 MB below Gemini's 2 GB uploaded-input limit so framing and
	// provider-side size accounting cannot turn an exactly packed job invalid.
	GeminiBatchMaxInputBytes    = int64(1_900_000_000)
	GeminiBatchMaxResponseBytes = geminiMaxResponseBytes
)
View Source
const (
	MistralModel = mistralModel
)

Variables

This section is empty.

Functions

func DocumentFailure added in v0.3.0

func DocumentFailure(err error) error

func FormatCurrency added in v0.3.0

func FormatCurrency(cost Currency) string

func GlobalFailure added in v0.3.0

func GlobalFailure(err error) error

func IsGeminiAmbiguousOperation added in v0.3.0

func IsGeminiAmbiguousOperation(err error) bool

func IsGeminiBatchNotFound added in v0.3.0

func IsGeminiBatchNotFound(err error) bool

func IsGeminiDeleteInvalidArgument added in v0.3.0

func IsGeminiDeleteInvalidArgument(err error) bool

func IsGeminiGlobalFailure added in v0.3.0

func IsGeminiGlobalFailure(err error) bool

func IsGeminiMaxTokensError added in v0.3.0

func IsGeminiMaxTokensError(err error) bool

func IsGeminiRangeSizeError added in v0.3.0

func IsGeminiRangeSizeError(err error) bool

func MistralPricePerPage

func MistralPricePerPage() float64

func NormalizeGeminiBatchState added in v0.3.0

func NormalizeGeminiBatchState(remoteState string) (string, error)

func TemporaryFailure added in v0.3.0

func TemporaryFailure(err error) error

Types

type BillingReport added in v0.3.0

type BillingReport struct {
	KnownCost     Currency
	Indeterminate bool
}

func (*BillingReport) Add added in v0.3.0

func (r *BillingReport) Add(other BillingReport)

type Currency added in v0.3.0

type Currency int64

Currency is stored as billionths of a US dollar. That precision represents every baked-in per-token and per-page price exactly without concurrent float arithmetic.

func GeminiBatchCost added in v0.3.0

func GeminiBatchCost(at time.Time, inputTokens, outputTokens int64) Currency

func GeminiCost added in v0.3.0

func GeminiCost(at time.Time, inputTokens, outputTokens int64) Currency

func GeminiCostWithPrices added in v0.3.0

func GeminiCostWithPrices(prices GeminiTokenPrices, inputTokens, outputTokens int64) Currency

func MistralCost added in v0.3.0

func MistralCost(pages int) Currency

func MistralPageCost added in v0.3.0

func MistralPageCost() Currency

type Failure added in v0.3.0

type Failure struct {
	Kind FailureKind
	Err  error
}

func (*Failure) Error added in v0.3.0

func (e *Failure) Error() string

func (*Failure) Unwrap added in v0.3.0

func (e *Failure) Unwrap() error

type FailureKind added in v0.3.0

type FailureKind string
const (
	FailureUnclassified FailureKind = "unclassified"
	FailureTemporary    FailureKind = "temporary"
	FailureDocument     FailureKind = "document"
	FailureGlobal       FailureKind = "global"
)

func ClassifyFailure added in v0.3.0

func ClassifyFailure(err error) FailureKind

Fallback is deliberately conservative because advancing the chain can incur another provider charge. Only verified permanent document/content failures advance; temporary and ambiguous failures stay pending for a later run.

type GeminiAmbiguousOperationError added in v0.3.0

type GeminiAmbiguousOperationError struct {
	Operation string
	Err       error
}

func (*GeminiAmbiguousOperationError) Error added in v0.3.0

func (*GeminiAmbiguousOperationError) Unwrap added in v0.3.0

type GeminiBatchAPIError added in v0.3.0

type GeminiBatchAPIError struct {
	StatusCode int
	Body       []byte
}

func (*GeminiBatchAPIError) Error added in v0.3.0

func (e *GeminiBatchAPIError) Error() string

type GeminiBatchTransport added in v0.3.0

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

GeminiBatchTransport keeps the discounted Batch API's Files and batch-job lifecycle explicit instead of hiding non-idempotent calls behind an SDK.

func NewGeminiBatchTransport added in v0.3.0

func NewGeminiBatchTransport(apiKey string) *GeminiBatchTransport

func (*GeminiBatchTransport) CancelBatch added in v0.3.0

func (c *GeminiBatchTransport) CancelBatch(ctx context.Context, name string) error

func (*GeminiBatchTransport) CreateBatch added in v0.3.0

func (c *GeminiBatchTransport) CreateBatch(
	ctx context.Context,
	model, displayName, inputFileName string,
) (GeminiRemoteBatch, error)

func (*GeminiBatchTransport) DeleteBatch added in v0.3.0

func (c *GeminiBatchTransport) DeleteBatch(ctx context.Context, name string) error

func (*GeminiBatchTransport) DeleteFile added in v0.3.0

func (c *GeminiBatchTransport) DeleteFile(ctx context.Context, name string) error

func (*GeminiBatchTransport) DownloadFile added in v0.3.0

func (c *GeminiBatchTransport) DownloadFile(ctx context.Context, name string) (io.ReadCloser, error)

func (*GeminiBatchTransport) GetBatch added in v0.3.0

func (*GeminiBatchTransport) ListBatches added in v0.3.0

func (c *GeminiBatchTransport) ListBatches(ctx context.Context) ([]GeminiRemoteBatch, error)

func (*GeminiBatchTransport) ListFiles added in v0.3.0

func (*GeminiBatchTransport) UploadJSONL added in v0.3.0

func (c *GeminiBatchTransport) UploadJSONL(
	ctx context.Context,
	displayName string,
	source io.ReadSeeker,
	size int64,
) (GeminiRemoteFile, error)

type GeminiClient added in v0.3.0

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

func NewGeminiClient added in v0.3.0

func NewGeminiClient(apiKey string, runAt time.Time) *GeminiClient

func NewGeminiClientFromEnv added in v0.3.0

func NewGeminiClientFromEnv(runAt time.Time) (*GeminiClient, error)

func (*GeminiClient) OCRFile added in v0.3.0

func (c *GeminiClient) OCRFile(ctx context.Context, filePath string, fileType string) ([]PageResult, BillingReport, error)

func (*GeminiClient) OCRRange added in v0.3.0

func (c *GeminiClient) OCRRange(
	ctx context.Context,
	filePath, fileType string,
	start, end int,
) ([]PageResult, BillingReport, error)

func (*GeminiClient) OCRRangeResult added in v0.3.0

func (c *GeminiClient) OCRRangeResult(
	ctx context.Context,
	filePath, fileType string,
	start, end int,
) (RangeResult, error)

func (*GeminiClient) PrepareFileRequests added in v0.3.0

func (c *GeminiClient) PrepareFileRequests(ctx context.Context, filePath, fileType string) ([]GeminiPreparedRequest, error)

func (*GeminiClient) PrepareRangeRequest added in v0.3.0

func (c *GeminiClient) PrepareRangeRequest(
	ctx context.Context,
	filePath, fileType string,
	start, end int,
) (GeminiPreparedRequest, error)

func (*GeminiClient) WalkFileRequests added in v0.3.0

func (c *GeminiClient) WalkFileRequests(
	ctx context.Context,
	filePath, fileType string,
	yield func(GeminiPreparedRequest) error,
	reject func(*GeminiRangeSizeError) error,
) error

type GeminiDecodedResult added in v0.3.0

type GeminiDecodedResult struct {
	Pages        []PageResult
	InputTokens  *int64
	OutputTokens *int64
	Billing      BillingReport
}

func DecodeGeminiBatchResult added in v0.3.0

func DecodeGeminiBatchResult(
	body []byte,
	expectedPages int,
	fallbackModel string,
	prices GeminiTokenPrices,
) (GeminiDecodedResult, error)

type GeminiPlanningError added in v0.3.0

type GeminiPlanningError struct {
	PageStart int
	PageEnd   int
	Cause     error
}

func (*GeminiPlanningError) Error added in v0.3.0

func (e *GeminiPlanningError) Error() string

func (*GeminiPlanningError) Unwrap added in v0.3.0

func (e *GeminiPlanningError) Unwrap() error

type GeminiPreparedRequest added in v0.3.0

type GeminiPreparedRequest struct {
	PageStart int
	PageEnd   int
	Body      []byte
}

GeminiClient uses the REST API directly so the OCR provider has no SDK dependency and its request and billing behavior remain explicit.

type GeminiRangeSizeError added in v0.3.0

type GeminiRangeSizeError struct {
	PageStart int
	PageEnd   int
	Cause     error
}

func (*GeminiRangeSizeError) Error added in v0.3.0

func (e *GeminiRangeSizeError) Error() string

func (*GeminiRangeSizeError) Unwrap added in v0.3.0

func (e *GeminiRangeSizeError) Unwrap() error

type GeminiRemoteBatch added in v0.3.0

type GeminiRemoteBatch struct {
	Name           string
	DisplayName    string
	Model          string
	InputFileName  string
	State          string
	OutputFileName string
	ErrorMessage   string
	CreateTime     string
	UpdateTime     string
}

type GeminiRemoteFile added in v0.3.0

type GeminiRemoteFile struct {
	Name        string `json:"name"`
	DisplayName string `json:"displayName"`
	URI         string `json:"uri"`
	State       string `json:"state"`
	MIMEType    string `json:"mimeType"`
	SizeBytes   string `json:"sizeBytes"`
}

type GeminiTokenPrices added in v0.3.0

type GeminiTokenPrices struct {
	Input  Currency
	Output Currency
}

func GeminiBatchPrices added in v0.3.0

func GeminiBatchPrices(at time.Time) GeminiTokenPrices

func GeminiPrices added in v0.3.0

func GeminiPrices(at time.Time) GeminiTokenPrices

Gemini's standard paid rates change at the documented UTC pricing cutover. Keep estimates and actual usage on the run's single schedule even if workers cross midnight. Recheck against https://ai.google.dev/gemini-api/docs/pricing.

type MistralClient

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

func NewMistralClient

func NewMistralClient(apiKey string) *MistralClient

func NewMistralClientFromEnv

func NewMistralClientFromEnv() (*MistralClient, error)

func (*MistralClient) OCRFile

func (c *MistralClient) OCRFile(ctx context.Context, filePath string, fileType string) ([]PageResult, BillingReport, error)

func (*MistralClient) OCRRangeResult added in v0.3.0

func (c *MistralClient) OCRRangeResult(
	ctx context.Context,
	filePath, fileType string,
	start, end int,
) (RangeResult, error)

func (*MistralClient) PricePerPage

func (c *MistralClient) PricePerPage() float64

type PageResult

type PageResult struct {
	PageIndex int
	Markdown  string
	Model     string
}

type Provider

type Provider interface {
	OCRRangeResult(
		ctx context.Context,
		filePath string,
		fileType string,
		start int,
		end int,
	) (RangeResult, error)
}

Provider processes only a requested source-page range so successful pages from earlier models or runs never need to be sent over the network again.

type RangeResult added in v0.3.0

type RangeResult struct {
	Pages   []PageResult
	Billing BillingReport
}

Jump to

Keyboard shortcuts

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