Documentation
¶
Overview ¶
Package contracts defines the interfaces and shared state used by model providers. It has no dependency on provider construction, allowing implementations and orchestration packages to share one canonical contract.
Index ¶
- type BatchEmbeddingProvider
- type BatchEmbeddingResult
- type Config
- func (c *Config) BaseConfig() Config
- func (c *Config) CapsOverride() *modelinfo.CapsOverride
- func (c *Config) ID() modelsdev.ID
- func (c *Config) ImageOutputEnabled(ctx context.Context) bool
- func (c *Config) SetProviderRebuilder(rebuild RebuildProviderFunc)
- func (c *Config) ToolCallSupport(ctx context.Context) modelinfo.ToolCallSupport
- func (c *Config) TrackUsageEnabled() bool
- type EmbeddingProvider
- type EmbeddingResult
- type Provider
- type RebuildProviderFunc
- type RerankingProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BatchEmbeddingProvider ¶
type BatchEmbeddingProvider interface {
EmbeddingProvider
// CreateBatchEmbedding returns embeddings in the same order as the inputs.
CreateBatchEmbedding(ctx context.Context, texts []string) (*BatchEmbeddingResult, error)
}
BatchEmbeddingProvider is an embedding provider that supports batches.
type BatchEmbeddingResult ¶
type BatchEmbeddingResult struct {
Embeddings [][]float64
InputTokens int64
TotalTokens int64
Cost float64
}
BatchEmbeddingResult contains embeddings and their aggregate usage.
type Config ¶
type Config struct {
ModelConfig latest.ModelConfig
ModelOptions options.ModelOptions
Env environment.Provider
// RebuildProvider preserves the construction context needed to clone a provider.
RebuildProvider RebuildProviderFunc
// BaseURL is the resolved endpoint actually used by the provider, unlike
// ModelConfig.BaseURL, which contains the user-supplied value.
BaseURL string
}
Config is the common configuration embedded by provider clients.
func (*Config) BaseConfig ¶
func (*Config) CapsOverride ¶
func (c *Config) CapsOverride() *modelinfo.CapsOverride
CapsOverride returns explicit attachment capabilities. These overrides take precedence when a custom or aliased provider cannot be resolved in models.dev.
func (*Config) ID ¶
ID returns the provider-qualified identity, preferring the original display model name over a resolved or pinned model name.
func (*Config) ImageOutputEnabled ¶
ImageOutputEnabled resolves the model's image-output capability.
func (*Config) SetProviderRebuilder ¶
func (c *Config) SetProviderRebuilder(rebuild RebuildProviderFunc)
SetProviderRebuilder sets the function used to reconstruct the provider.
func (*Config) ToolCallSupport ¶
func (c *Config) ToolCallSupport(ctx context.Context) modelinfo.ToolCallSupport
ToolCallSupport resolves the model's tool-call capability.
func (*Config) TrackUsageEnabled ¶
TrackUsageEnabled reports whether token-usage tracking is enabled.
type EmbeddingProvider ¶
type EmbeddingProvider interface {
Provider
CreateEmbedding(ctx context.Context, text string) (*EmbeddingResult, error)
}
EmbeddingProvider is a provider that supports embeddings.
type EmbeddingResult ¶
type EmbeddingResult struct {
Embedding []float64
InputTokens int64
TotalTokens int64
Cost float64
}
EmbeddingResult contains an embedding and its usage.
type Provider ¶
type Provider interface {
// ID returns a provider-qualified identity to preserve the model namespace
// when it crosses API boundaries.
ID() modelsdev.ID
// CreateChatCompletionStream creates a streaming chat completion request.
CreateChatCompletionStream(
ctx context.Context,
messages []chat.Message,
tools []tools.Tool,
) (chat.MessageStream, error)
// BaseConfig returns the provider's base configuration.
BaseConfig() Config
}
Provider defines the common interface implemented by model providers.
type RebuildProviderFunc ¶
type RebuildProviderFunc func( ctx context.Context, cfg *latest.ModelConfig, opts ...options.Opt, ) (Provider, error)
RebuildProviderFunc reconstructs a provider with adjusted options.
type RerankingProvider ¶
type RerankingProvider interface {
Provider
// Rerank returns one relevance score per document, in input order.
Rerank(ctx context.Context, query string, documents []types.Document, criteria string) ([]float64, error)
}
RerankingProvider is a provider that can score documents by relevance.