provider

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownProvider   = errors.New("provider: unknown provider")
	ErrUnauthorized      = errors.New("provider: unauthorized (check API key)")
	ErrRateLimit         = errors.New("provider: rate limit exceeded")
	ErrContextTooLong    = errors.New("provider: input exceeds model context window")
	ErrModelNotSupported = errors.New("provider: model not supported by this provider")
	ErrTimeout           = errors.New("provider: request timed out")
)

Functions

func Names

func Names() []string

func Register

func Register(name string, factory Factory)

Register installs a provider factory under the given name. Intended to be called from package init() functions of provider subpackages. Panics on duplicate registration to surface programmer errors at startup rather than silently overriding.

Types

type Event

type Event struct {
	Type  EventType
	Delta string
	Usage Usage
	Err   error
}

type EventType

type EventType int
const (
	EventDelta EventType = iota
	EventUsage
	EventDone
	EventError
)

func (EventType) String

func (e EventType) String() string

type Factory

type Factory func(cfg config.ProviderConfig) (Provider, error)

type Pricing

type Pricing struct {
	InputPer1M  float64
	OutputPer1M float64

	// CachedInputPer1M is the per-1M-token price for cached input tokens.
	// Zero means "same as InputPer1M" (no cache discount or not supported).
	CachedInputPer1M float64
}

func (Pricing) Cost

func (p Pricing) Cost(u Usage) float64

type Provider

type Provider interface {
	Name() string

	DefaultModel() string

	ContextWindow(model string) int

	EstimateTokens(text string) int

	Pricing(model string) Pricing

	Review(ctx context.Context, req Request) (Response, error)

	ReviewStream(ctx context.Context, req Request) (<-chan Event, error)

	TestConnection(ctx context.Context) error
}

func New

func New(name string, cfg config.ProviderConfig) (Provider, error)

type Request

type Request struct {
	Model        string
	SystemPrompt string
	UserPrompt   string
	Lang         string
	MaxTokens    int

	// ProviderOpts is an escape hatch (ADR-0001 risk #1) for features that
	// don't fit the common interface, e.g. Anthropic prompt caching or
	// OpenAI logprobs. Providers cast to their expected type; unknown values
	// are ignored.
	ProviderOpts any
}

type Response

type Response struct {
	Content string
	Model   string
	Usage   Usage
}

type Usage

type Usage struct {
	InputTokens  int
	OutputTokens int

	// CachedInputTokens is the subset of InputTokens served from a provider-
	// side prompt cache (Anthropic ephemeral cache, OpenAI cached completions).
	// Zero if unknown or unsupported.
	CachedInputTokens int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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