fallback

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package fallback provides a Provider that tries a list of providers in order, returning the first successful result. This gives automatic failover when a primary provider is unavailable, rate-limited, or returns an error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

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

Provider tries a list of providers in order, using the first one that succeeds.

func New

func New(providers []provider.Provider) (*Provider, error)

New creates a fallback provider from an ordered list of providers. The first provider in the list is the primary; subsequent providers are fallbacks. Returns an error if the list is empty.

Each input provider is wrapped in provider.WithPanicSafety as a defense in depth: callers that obtain providers via provider.Build are already safe, but a future caller that constructs raw providers and passes them here would otherwise lose the safety net (a nil-pointer deref inside a third- party SDK would crash the whole process during fan-out). Re-wrapping is cheap and idempotent, so this is safe regardless of how the inputs were produced.

func (*Provider) Complete

func (f *Provider) Complete(ctx context.Context, prompt string, opts provider.Options) (*provider.Result, error)

Complete tries each provider in order, returning the first successful result. If the context is cancelled, it stops immediately without trying further fallbacks. On a provider error, it logs which provider failed and tries the next one. A successful (err==nil) response with empty/whitespace-only output is treated as a soft failure and falls through to the next provider — almost always a transient hiccup rather than a legitimate empty answer, and serving it would defeat the entire purpose of having fallbacks. Mirrors the empty-output skip in pkg/provider/cached. If all providers fail, it returns a combined error.

func (*Provider) DefaultModel

func (f *Provider) DefaultModel() string

DefaultModel returns the default model of the primary provider.

func (*Provider) Name

func (f *Provider) Name() string

Name returns a combined name showing the full fallback chain.

Jump to

Keyboard shortcuts

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