Documentation
¶
Overview ¶
Package provider defines the provider contracts and builds providers from explicit factory registries.
The package deliberately does not import concrete SDK-backed providers. Applications that need Docker Agent's built-in provider set should import pkg/model/provider/providers and use its NewDefaultRegistry. Embedders can instead build a smaller registry with NewRegistry. EmptyRegistry is available for components that support running without model providers.
Index ¶
- Variables
- func ContextWindowResolver(p Provider) func(context.Context) (int64, error)
- func ResolveType(cfg *latest.ModelConfig, customProviders map[string]latest.ProviderConfig) string
- type BatchEmbeddingProvider
- type CloneError
- type EmbeddingProvider
- type Factory
- type Provider
- func Clone(ctx context.Context, p Provider, opts ...options.Opt) (Provider, error)
- func CloneWithOptions(ctx context.Context, p Provider, opts ...options.Opt) Providerdeprecated
- func New(ctx context.Context, cfg *latest.ModelConfig, env environment.Provider, ...) (Provider, error)deprecated
- func NewWithModels(ctx context.Context, cfg *latest.ModelConfig, ...) (Provider, error)deprecated
- type Registry
- func (r *Registry) Has(providerType string) bool
- func (r *Registry) New(ctx context.Context, cfg *latest.ModelConfig, env environment.Provider, ...) (Provider, error)
- func (r *Registry) NewWithModels(ctx context.Context, cfg *latest.ModelConfig, ...) (Provider, error)
- func (r *Registry) Types() []string
- type RerankingProvider
- type ServedStream
- type ServingModel
- type ServingStream
Constants ¶
This section is empty.
Variables ¶
var ErrNoRebuilder = errors.New("provider cannot be cloned without its rebuild function")
ErrNoRebuilder means a provider has no construction function for cloning.
var ErrUncopyableConfig = errors.New("provider clone requires copyable configuration")
ErrUncopyableConfig means mutable configuration cannot be safely copied.
Functions ¶
func ContextWindowResolver ¶ added in v1.142.0
ContextWindowResolver returns an optional live context-window lookup, preserving access through instrumentation wrappers. Providers without discovery return nil.
func ResolveType ¶ added in v1.132.0
func ResolveType(cfg *latest.ModelConfig, customProviders map[string]latest.ProviderConfig) string
ResolveType returns the registry key a model config is served by once custom providers (providers: section), built-in aliases and an explicit api_type are applied — i.e. the factory Registry.New will look up for it. A routing model resolves to its fallback provider/model. The config is not mutated.
Types ¶
type BatchEmbeddingProvider ¶
type BatchEmbeddingProvider = contracts.BatchEmbeddingProvider
BatchEmbeddingProvider is an embedding provider that supports batches.
type CloneError ¶ added in v1.151.0
CloneError identifies the provider whose reconstruction failed.
func (*CloneError) Error ¶ added in v1.151.0
func (e *CloneError) Error() string
func (*CloneError) Unwrap ¶ added in v1.151.0
func (e *CloneError) Unwrap() error
type EmbeddingProvider ¶
type EmbeddingProvider = contracts.EmbeddingProvider
EmbeddingProvider is a provider that supports embeddings.
type Factory ¶ added in v1.84.0
type Factory func(ctx context.Context, cfg *latest.ModelConfig, env environment.Provider, opts ...options.Opt) (Provider, error)
func Adapt ¶ added in v1.132.0
func Adapt[P Provider](newClient func(context.Context, *latest.ModelConfig, environment.Provider, ...options.Opt) (P, error)) Factory
Adapt turns a provider package's concrete constructor (e.g. anthropic.NewClient, which returns *anthropic.Client) into a Factory so it can be registered without a hand-written closure:
provider.NewRegistry(map[string]provider.Factory{"anthropic": provider.Adapt(anthropic.NewClient)})
type Provider ¶
Provider is the common interface implemented by model providers.
func Clone ¶ added in v1.151.0
Clone reconstructs a provider with ordered option overrides, or returns an error. Non-zero token caps also constrain routed children, subject to provider floors. The last non-zero cap wins; zero retains the latest explicit cap.
func New
deprecated
func New(ctx context.Context, cfg *latest.ModelConfig, env environment.Provider, opts ...options.Opt) (Provider, error)
New creates a provider with an empty registry and therefore returns an unknown-provider error for every concrete provider.
Deprecated: construct a Registry explicitly and call Registry.New.
func NewWithModels
deprecated
func NewWithModels(ctx context.Context, cfg *latest.ModelConfig, models map[string]latest.ModelConfig, env environment.Provider, opts ...options.Opt) (Provider, error)
NewWithModels creates a provider with an empty registry and therefore returns an unknown-provider error for every concrete provider.
Deprecated: construct a Registry explicitly and call Registry.NewWithModels.
type Registry ¶ added in v1.84.0
type Registry struct {
// contains filtered or unexported fields
}
func DefaultRegistry
deprecated
added in
v1.84.0
func DefaultRegistry() *Registry
DefaultRegistry returns an empty registry because this package deliberately does not import concrete provider implementations.
Deprecated: use EmptyRegistry or construct a Registry explicitly.
func EmptyRegistry ¶ added in v1.139.0
func EmptyRegistry() *Registry
EmptyRegistry returns a registry with no provider factories. It is useful for components that support running without models; it cannot construct a concrete provider until factories are explicitly supplied to NewRegistry.
func NewRegistry ¶ added in v1.84.0
func (*Registry) Has ¶ added in v1.132.0
Has reports whether a factory is registered for providerType, a key as returned by ResolveType.
func (*Registry) NewWithModels ¶ added in v1.84.0
func (r *Registry) NewWithModels(ctx context.Context, cfg *latest.ModelConfig, models map[string]latest.ModelConfig, env environment.Provider, opts ...options.Opt) (Provider, error)
type RerankingProvider ¶
type RerankingProvider = contracts.RerankingProvider
RerankingProvider is a provider that can score documents by relevance.
type ServedStream ¶ added in v1.153.0
type ServedStream = contracts.ServedStream
ServedStream reports a model that served the response in place of the dispatched one.
type ServingModel ¶ added in v1.151.0
type ServingModel = contracts.ServingModel
ServingModel identifies the endpoint that produced a completion stream.
func ServedBy ¶ added in v1.153.0
func ServedBy(stream chat.MessageStream) (ServingModel, bool)
ServedBy reports the model that served a finished stream in place of the dispatched one; false when the stream doesn't say or nothing changed.
type ServingStream ¶ added in v1.151.0
type ServingStream = contracts.ServingStream
ServingStream reports the serving endpoint when it differs from the dispatched provider.
Directories
¶
| Path | Synopsis |
|---|---|
|
anthropictest
Package anthropictest serves scripted Anthropic Messages API streams for runtime tests that drive a real Anthropic client.
|
Package anthropictest serves scripted Anthropic Messages API streams for runtime tests that drive a real Anthropic client. |
|
federation
Package federation builds the Anthropic Workload Identity Federation pieces (identity-token providers and SDK request options) from a typed latest.AuthConfig.
|
Package federation builds the Anthropic Workload Identity Federation pieces (identity-token providers and SDK request options) from a typed latest.AuthConfig. |
|
vertex
Package vertex provides an Anthropic client for Claude models hosted on Google Cloud's Vertex AI.
|
Package vertex provides an Anthropic client for Claude models hosted on Google Cloud's Vertex AI. |
|
Package base provides compatibility aliases for shared provider state.
|
Package base provides compatibility aliases for shared provider state. |
|
Package catalog provides embedded metadata for built-in model providers, without linking their SDK implementations.
|
Package catalog provides embedded metadata for built-in model providers, without linking their SDK implementations. |
|
Package contracts defines the interfaces and shared state used by model providers.
|
Package contracts defines the interfaces and shared state used by model providers. |
|
dmrmodels
Package dmrmodels handles Docker Model Runner endpoint discovery and model listing.
|
Package dmrmodels handles Docker Model Runner endpoint discovery and model listing. |
|
internal
|
|
|
Package providers wires every built-in model provider into a provider.Registry.
|
Package providers wires every built-in model provider into a provider.Registry. |
|
Package rulebased provides a rule-based model router that selects the appropriate model based on text similarity using a lightweight in-memory BM25 ranker.
|
Package rulebased provides a rule-based model router that selects the appropriate model based on text similarity using a lightweight in-memory BM25 ranker. |
|
Package vertexai provides support for non-Gemini models hosted on Google Cloud's Vertex AI Model Garden.
|
Package vertexai provides support for non-Gemini models hosted on Google Cloud's Vertex AI Model Garden. |