Documentation
¶
Overview ¶
Package providers defines the common interface for LLM provider implementations.
Index ¶
- Constants
- Variables
- func As[T any](p Provider) (T, bool)
- func BuildParametersMap(p tool.Parameters) map[string]any
- func BuildPropertyEntry(prop tool.Property) map[string]any
- func BuildPropertyMap(props map[string]tool.Property) map[string]any
- func ClassifyHTTPError(statusCode int, providerName, msg string, retryAfter time.Duration) error
- func Float32sToFloat64s(vals []float32) []float64
- func IsNetworkError(err error) bool
- func ParseRetryAfter(resp *http.Response) time.Duration
- func Ptr[T any](v T) *T
- func WrapNetworkError(err error) error
- type Embedder
- type ModelLoader
- type Provider
- type RateLimitError
- type Reranker
- type RetryProvider
- type Synthesizer
- type Transcriber
Constants ¶
const DefaultRetryAfter = 5 * time.Second
DefaultRetryAfter is applied when a provider returns 429 but doesn't expose the Retry-After header (Google, OpenRouter, Ollama).
Variables ¶
var ( ErrRateLimit = errors.New("rate limited") ErrAuth = errors.New("authentication failed") ErrServerError = errors.New("server error") ErrNetwork = errors.New("network error") ErrCreditExhausted = errors.New("credits exhausted") ErrContentFilter = errors.New("content filtered") // ErrEstimateNotSupported is returned when a provider does not support native token estimation. ErrEstimateNotSupported = errors.New("provider does not support native token estimation") )
Provider error sentinels — returned by handleError() in each provider so the assistant loop can show actionable user-facing messages.
var ErrContextExhausted = errors.New("context length exceeded")
ErrContextExhausted indicates the conversation exceeded the model's context window. Providers wrap their provider-specific context-length errors with this sentinel so the assistant loop can detect and trigger emergency compaction.
Functions ¶
func As ¶
As unwraps wrapper layers (RetryProvider, etc.) to find the first provider that satisfies interface T. Follows the same pattern as errors.As.
func BuildParametersMap ¶
func BuildParametersMap(p tool.Parameters) map[string]any
BuildParametersMap converts tool parameters to the full JSON Schema map format used by OpenAI and OpenRouter.
func BuildPropertyEntry ¶
BuildPropertyEntry converts a single Property to a JSON Schema map, recursing into nested types.
func BuildPropertyMap ¶
BuildPropertyMap converts tool properties to the generic map format used by OpenAI-compatible provider SDKs.
func ClassifyHTTPError ¶
ClassifyHTTPError maps an HTTP status code to a provider-agnostic sentinel. Providers call this AFTER their message-based pre-checks (context exhaustion, content filter, credit/quota patterns) which vary per SDK. When retryAfter is zero and status is 429, DefaultRetryAfter is applied.
func Float32sToFloat64s ¶
Float32sToFloat64s converts a slice of float32 values to float64.
func IsNetworkError ¶
IsNetworkError reports whether err is a network-level failure (connection refused, DNS resolution, timeout) as opposed to an API-level error from the provider SDK. Network errors bypass SDK error types, so this must be checked BEFORE SDK assertions.
func ParseRetryAfter ¶
ParseRetryAfter extracts a Retry-After duration from an HTTP response. Returns zero if the response is nil or the header is absent/unparseable.
func WrapNetworkError ¶
WrapNetworkError wraps a network error with the ErrNetwork sentinel.
Types ¶
type Embedder ¶
type Embedder interface {
Embed(context.Context, embedding.Request) (embedding.Response, usage.Usage, error)
}
Embedder is an optional interface for providers that support embedding.
type ModelLoader ¶
type ModelLoader interface {
LoadModel(ctx context.Context, name string) error
UnloadModel(ctx context.Context, name string) error
}
ModelLoader is an optional interface for providers that support explicit model load/unload.
type Provider ¶
type Provider interface {
Chat(context.Context, request.Request, stream.Func) (message.Message, usage.Usage, error)
Models(context.Context) (model.Models, error)
Model(context.Context, string) (model.Model, error)
Estimate(context.Context, request.Request, string) (int, error)
}
Provider defines the core interface for LLM provider implementations.
type RateLimitError ¶
RateLimitError carries retry metadata alongside the ErrRateLimit sentinel. RetryAfter is parsed from the Retry-After header where available (Anthropic, OpenAI). Providers without header access (Google, Ollama, OpenRouter) get DefaultRetryAfter.
func (*RateLimitError) Error ¶
func (e *RateLimitError) Error() string
func (*RateLimitError) Is ¶
func (e *RateLimitError) Is(target error) bool
func (*RateLimitError) Unwrap ¶
func (e *RateLimitError) Unwrap() error
type RetryProvider ¶
type RetryProvider struct {
Provider // embedded for pass-through of Models, Model, Estimate, etc.
Bo backoff.BackOff
}
RetryProvider wraps a Provider with exponential-backoff retry logic for Chat(). All other Provider methods pass through to the embedded provider unchanged.
Retry is stream-safe: once the stream callback has been invoked (partial content emitted to the terminal), the error is marked permanent and no retry is attempted.
Fields are exported because the factory creating RetryProvider lives in internal/providers/ (different package).
func (*RetryProvider) Chat ¶
func (r *RetryProvider) Chat(ctx context.Context, req request.Request, fn stream.Func) (message.Message, usage.Usage, error)
Chat calls the underlying provider's Chat with retry logic for transient errors.
func (*RetryProvider) Unwrap ¶
func (r *RetryProvider) Unwrap() Provider
Unwrap returns the inner provider, enabling providers.As[T]() to find opt-in interfaces through the retry wrapper.
type Synthesizer ¶
type Synthesizer interface {
Synthesize(context.Context, synthesize.Request) (synthesize.Response, error)
}
Synthesizer is an optional interface for providers that support speech synthesis.
type Transcriber ¶
type Transcriber interface {
Transcribe(context.Context, transcribe.Request) (transcribe.Response, error)
}
Transcriber is an optional interface for providers that support audio transcription.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package adapter bridges Aura's LLM types with Fantasy's unified provider abstraction.
|
Package adapter bridges Aura's LLM types with Fantasy's unified provider abstraction. |
|
Package anthropic implements the Anthropic Messages API provider.
|
Package anthropic implements the Anthropic Messages API provider. |
|
Package capabilities defines model capability flags.
|
Package capabilities defines model capability flags. |
|
Package codex implements the OpenAI Plus (ChatGPT Codex) provider.
|
Package codex implements the OpenAI Plus (ChatGPT Codex) provider. |
|
Package copilot implements the GitHub Copilot dual-protocol provider.
|
Package copilot implements the GitHub Copilot dual-protocol provider. |
|
Package google implements the Google Gemini API provider.
|
Package google implements the Google Gemini API provider. |
|
Package llamacpp implements the llama.cpp server provider.
|
Package llamacpp implements the llama.cpp server provider. |
|
Package noop provides a no-operation LLM provider that returns fixed responses without making any network calls.
|
Package noop provides a no-operation LLM provider that returns fixed responses without making any network calls. |
|
Package ollama implements the Ollama provider.
|
Package ollama implements the Ollama provider. |
|
Package openai implements a generic OpenAI-compatible provider for any /v1/chat/completions endpoint.
|
Package openai implements a generic OpenAI-compatible provider for any /v1/chat/completions endpoint. |
|
Package openrouter implements the OpenRouter provider.
|
Package openrouter implements the OpenRouter provider. |
|
Package registry provides model capability enrichment using Catwalk metadata.
|
Package registry provides model capability enrichment using Catwalk metadata. |
|
Package transport provides HTTP transport with Bearer token authentication.
|
Package transport provides HTTP transport with Bearer token authentication. |