base

package
v1.95.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const NoDesktopTokenErrorMessage = "failed to get Docker Desktop token for Gateway. Is Docker Desktop running and are you signed in?"

Variables

This section is empty.

Functions

func GatewayAuthToken added in v1.94.0

func GatewayAuthToken(ctx context.Context, env environment.Provider, gateway string) (string, error)

GatewayAuthToken returns a fresh Docker Desktop auth token when gateway targets a trusted Docker domain, or "" for other gateways. Gateway clients call it on every request because Desktop tokens are short-lived.

func GatewayHTTPOptions added in v1.94.0

func GatewayHTTPOptions(gatewayURL *url.URL, defaultBaseURL string, cfg *latest.ModelConfig, generatingTitle bool) []httpclient.Opt

GatewayHTTPOptions builds the httpclient options shared by all gateway-mode provider clients: the proxied base URL (the provider's public endpoint unless the model overrides base_url), provider/model identity, the gateway's query parameters, and the title-generation marker.

func VerifyDockerGatewayAuth added in v1.94.0

func VerifyDockerGatewayAuth(ctx context.Context, env environment.Provider, gateway string) error

VerifyDockerGatewayAuth fails fast when gateway targets a trusted Docker domain but Docker Desktop's auth token is unavailable. Provider clients call it at construction time so a missing sign-in surfaces before the first request. Non-Docker gateways need no Desktop token and always pass.

Types

type BatchEmbeddingResult

type BatchEmbeddingResult struct {
	Embeddings  [][]float64
	InputTokens int64
	TotalTokens int64
	Cost        float64
}

BatchEmbeddingResult contains multiple embeddings and usage information

type Config

type Config struct {
	ModelConfig  latest.ModelConfig
	ModelOptions options.ModelOptions
	Env          environment.Provider
	// Models stores the full models map for providers that need it (e.g., routers).
	// This enables proper cloning of providers that reference other models.
	Models map[string]latest.ModelConfig
	// ProviderRegistry stores the registry that created this provider. It is kept
	// as any to avoid a package cycle; pkg/model/provider type-asserts it when
	// cloning providers with adjusted options.
	ProviderRegistry any
	// BaseURL is the resolved HTTP base URL the client talks to, when
	// the provider is reachable over a configurable HTTP endpoint.
	// Distinct from [latest.ModelConfig.BaseURL] (the user-typed input):
	// providers fill BaseURL with the URL they actually use after auto
	// discovery / fallback (e.g. Docker Model Runner picking between
	// MODEL_RUNNER_HOST, the desktop socket, and a localhost fallback).
	// Surfaced through [Config.BaseConfig] so generic, runtime-free
	// consumers like hooks can address the endpoint without duplicating
	// resolution logic. Empty for providers that don't expose a stable
	// per-instance URL.
	BaseURL string
}

Config is a common base configuration shared by all provider clients. It can be embedded in provider-specific Client structs to avoid code duplication.

func (*Config) BaseConfig

func (c *Config) BaseConfig() Config

func (*Config) CapsOverride added in v1.89.0

func (c *Config) CapsOverride() *modelinfo.CapsOverride

CapsOverride returns the model's explicit attachment-capability override derived from its config, or nil when the config declares none (the common case, in which capabilities are detected from models.dev). Provider clients pass the result to modelinfo.ResolveCaps so a user-declared override wins over a models.dev lookup that would otherwise miss for custom/aliased providers and degrade attachments to text-only (issue #2741).

func (*Config) ID

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

ID returns the provider and model identity as a modelsdev.ID so callers cannot accidentally pass a bare model string where a provider-qualified identity is required. The model component uses DisplayModel (the original user-configured name) when available, falling back to Model (the resolved/pinned name).

func (*Config) SetProviderRegistry added in v1.84.0

func (c *Config) SetProviderRegistry(registry any)

func (*Config) TrackUsageEnabled added in v1.94.0

func (c *Config) TrackUsageEnabled() bool

TrackUsageEnabled reports whether token-usage tracking is enabled for this model. Tracking defaults to on and is disabled only when the config explicitly sets track_usage: false.

type EmbeddingResult

type EmbeddingResult struct {
	Embedding   []float64
	InputTokens int64
	TotalTokens int64
	Cost        float64
}

EmbeddingResult contains the embedding and usage information

Jump to

Keyboard shortcuts

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