fallback

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package fallback provides a Model implementation that chains multiple models together, falling back to the next model when one fails with a retryable error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FallbackModel

type FallbackModel struct {
	models.BaseModel
	// contains filtered or unexported fields
}

FallbackModel wraps multiple models and tries each in order until one succeeds.

func New

func New(chain []models.Model, opts ...Option) (*FallbackModel, error)

New creates a FallbackModel from the given chain of models. At least two models are required.

func (*FallbackModel) Invoke

Invoke tries each model in the chain, falling back on retryable errors.

func (*FallbackModel) InvokeStream

func (f *FallbackModel) InvokeStream(ctx context.Context, req *models.InvokeRequest) (<-chan types.ResponseChunk, error)

InvokeStream tries each model in the chain for streaming. Only falls back if the stream fails to open (not mid-stream failures).

type Option

type Option func(*Options)

Option configures a FallbackModel.

func WithMaxRetries

func WithMaxRetries(n int) Option

WithMaxRetries sets the maximum number of retries per model. Use 0 for no retries (each model is tried once before falling back).

func WithRetryDelay

func WithRetryDelay(d time.Duration) Option

WithRetryDelay sets the delay between retries.

type Options

type Options struct {
	MaxRetries int           // Max retries per model before falling back (default: 1)
	RetryDelay time.Duration // Delay between retries (default: 500ms)
}

Options holds configuration for fallback behavior.

Jump to

Keyboard shortcuts

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