contracts

package
v1.142.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

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 (c *Config) BaseConfig() Config

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

func (c *Config) ID() modelsdev.ID

ID returns the provider-qualified identity, preferring the original display model name over a resolved or pinned model name.

func (*Config) ImageOutputEnabled

func (c *Config) ImageOutputEnabled(ctx context.Context) bool

ImageOutputEnabled resolves the model's image-output capability.

func (*Config) NativeToolSearchEnabled added in v1.142.0

func (c *Config) NativeToolSearchEnabled() bool

NativeToolSearchEnabled reports whether provider_opts.native_tool_search opts this model into provider-hosted tool search. Strictly opt-in and gated to verified endpoints (see modelinfo.SupportsHostedToolSearch); only then do tools.Tool.InCatalog tools reach the provider through tool search. A user-supplied base_url means an OpenAI-compatible server, not api.openai.com, and is excluded like elsewhere in the openai provider; the resolved Config.BaseURL is deliberately not consulted so tests can point the SDK at a local server. An explicit api_type of openai_chatcompletions routes off the Responses API, which alone serves tool_search.

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

func (c *Config) TrackUsageEnabled() bool

TrackUsageEnabled reports whether token-usage tracking is enabled.

type ConversationCompactor added in v1.142.0

type ConversationCompactor interface {
	Provider
	// CompactConversation compacts messages, the fully assembled prompt the
	// conversation model would receive (system messages included), with the
	// same request tools. instructions is optional user steering for the
	// summary. Returning a result with an empty Summary means nothing was
	// compacted and the caller leaves the transcript untouched.
	CompactConversation(ctx context.Context, messages []chat.Message, requestTools []tools.Tool, instructions string) (*chat.CompactionResult, error)
}

ConversationCompactor is a provider that can compact a conversation server-side, returning a readable summary plus an opaque block it can later replay in place of the compacted history.

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.

Jump to

Keyboard shortcuts

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