modeldata

package
v0.1.81 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package modeldata provides fetching, parsing, and merging of the external AI model metadata registry (models.json) for enriching GoModel's model data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InferModesFromID added in v0.1.77

func InferModesFromID(modelID string) []string

InferModesFromID guesses a model's modes from its ID alone. It is a last-resort fallback for models absent from the remote model registry — typically local models served by llama.cpp, LM Studio, Ollama, or vLLM, whose IDs (often GGUF file names or user-chosen aliases) the registry can never enumerate. Without a mode, such a model is never categorized as an embedding model anywhere in the gateway even though calling it works fine.

The heuristic is deliberately conservative: it only claims the modes it is confident about and returns nil otherwise, so unknown models keep the "no metadata" state rather than being mislabeled. Real registry entries and operator-declared metadata always take precedence over this inference.

func MergeMetadata

func MergeMetadata(base, override *core.ModelMetadata) *core.ModelMetadata

MergeMetadata merges override onto base field-wise. Non-zero override fields win; zero override fields preserve the base value. Capabilities and Rankings are merged key-by-key (override keys replace base keys). Returns a new *ModelMetadata; inputs are not mutated and the returned value never shares slice, map, or pointer backing storage with base or override.

This supports config-driven overrides layered on top of remote-registry enrichment: operators can specify just the fields they care about (e.g. context_window for a local Ollama model) without clobbering unrelated fields.

func Resolve

func Resolve(list *ModelList, providerType string, modelID string) *core.ModelMetadata

Resolve performs the three-layer merge to produce ModelMetadata for a given provider type and model ID. It looks up provider_models[providerType/modelID] first, then falls back to models[modelID]. Provider-model fields override base model fields where set. Returns nil if no match is found in the registry.

Types

type AuthConfig

type AuthConfig struct {
	Type      string  `json:"type"`
	HeaderKey *string `json:"header_key"`
	EnvVar    *string `json:"env_var"`
}

AuthConfig describes provider authentication configuration.

type EnrichStats

type EnrichStats struct {
	Enriched int
	Total    int
}

EnrichStats summarizes one metadata enrichment pass.

func Enrich

func Enrich(accessor ModelInfoAccessor, list *ModelList) EnrichStats

Enrich iterates all models accessible via the accessor and merges resolved catalog metadata into each one. Models the catalog does not know are left unchanged.

The catalog is the base and the provider's own report the override, field by field: a running provider describes its actual deployment (a local server's real context window, an API's live capability flags) better than a static registry can, while the catalog still supplies everything the provider never reports — display names, pricing, rankings.

type FetchResult added in v0.1.81

type FetchResult struct {
	List *ModelList
	Raw  []byte
	// ETag is the validator to send on the next conditional fetch. Empty when
	// the server did not return one.
	ETag string
	// NotModified is true when the server answered 304 for the presented ETag;
	// List and Raw are nil and the caller keeps its current data.
	NotModified bool
}

FetchResult carries the outcome of one conditional model list fetch.

func FetchIfChanged added in v0.1.81

func FetchIfChanged(ctx context.Context, url, etag string) (FetchResult, error)

FetchIfChanged downloads and parses the model list unless the server reports it unchanged. When etag is non-empty it is sent as If-None-Match; a 304 response returns NotModified=true with the etag carried forward, skipping the download and reparse entirely. Servers without ETag support keep answering 200, so callers transparently degrade to unconditional fetching. Returns a zero FetchResult and nil error if the URL is empty (feature disabled).

type Modalities

type Modalities struct {
	Input  []string `json:"input"`
	Output []string `json:"output"`
}

Modalities describes input/output modality support.

type ModelEntry

type ModelEntry struct {
	DisplayName           string                   `json:"display_name"`
	Description           *string                  `json:"description"`
	OwnedBy               *string                  `json:"owned_by"`
	Family                *string                  `json:"family"`
	ReleaseDate           *string                  `json:"release_date"`
	DeprecationDate       *string                  `json:"deprecation_date"`
	Tags                  []string                 `json:"tags"`
	Modes                 []string                 `json:"modes"`
	SourceURL             *string                  `json:"source_url"`
	Modalities            *Modalities              `json:"modalities"`
	Capabilities          map[string]bool          `json:"capabilities"`
	ContextWindow         *int                     `json:"context_window"`
	MaxOutputTokens       *int                     `json:"max_output_tokens"`
	MaxImagesPerRequest   *int                     `json:"max_images_per_request"`
	MaxVideosPerRequest   *int                     `json:"max_videos_per_request"`
	MaxAudioPerRequest    *int                     `json:"max_audio_per_request"`
	MaxAudioLengthSeconds *int                     `json:"max_audio_length_seconds"`
	MaxVideoLengthSeconds *int                     `json:"max_video_length_seconds"`
	MaxPDFSizeMB          *int                     `json:"max_pdf_size_mb"`
	OutputVectorSize      *int                     `json:"output_vector_size"`
	Parameters            map[string]ParameterSpec `json:"parameters"`
	Rankings              map[string]RankingEntry  `json:"rankings"`
	Pricing               *core.ModelPricing       `json:"pricing"`
	Aliases               []string                 `json:"aliases"`
}

ModelEntry represents a model in the registry.

type ModelInfoAccessor

type ModelInfoAccessor interface {
	// ModelIDs returns all registered model IDs.
	ModelIDs() []string
	// GetProviderType returns the provider type for a model ID.
	GetProviderType(modelID string) string
	// SetMetadata sets the metadata for a model ID.
	SetMetadata(modelID string, meta *core.ModelMetadata)
	// DiscoveredMetadata returns the metadata the provider itself reported for
	// a model, or nil when it reported none. It must keep returning the same
	// value across enrichment passes: Enrich merges onto it rather than onto
	// its own previous result, which is what keeps repeated passes idempotent.
	DiscoveredMetadata(modelID string) *core.ModelMetadata
}

ModelInfoAccessor provides the minimal interface needed by Enrich to access and update model information. This avoids a circular dependency on the providers package.

type ModelList

type ModelList struct {
	Version        int                           `json:"version"`
	UpdatedAt      string                        `json:"updated_at"`
	Providers      map[string]ProviderEntry      `json:"providers"`
	Models         map[string]ModelEntry         `json:"models"`
	ProviderModels map[string]ProviderModelEntry `json:"provider_models"`
	// contains filtered or unexported fields
}

ModelList represents the top-level structure of models.json.

func Fetch

func Fetch(ctx context.Context, url string) (*ModelList, []byte, error)

Fetch downloads and parses the model list from the given URL. Returns the parsed ModelList, the raw JSON bytes (for caching), and any error. Returns nil, nil, nil if the URL is empty (feature disabled). The caller controls timeout via the provided context (e.g. context.WithTimeout).

func Parse

func Parse(raw []byte) (*ModelList, error)

Parse deserializes raw JSON bytes into a ModelList.

type ParameterSpec

type ParameterSpec struct {
	Type    string `json:"type"`
	Min     any    `json:"min"`
	Max     any    `json:"max"`
	Default any    `json:"default"`
	Enum    []any  `json:"enum"`
}

ParameterSpec describes a model parameter's constraints. Values are any because upstream mixes floats, ints, strings, and nulls.

type ProviderEntry

type ProviderEntry struct {
	DisplayName       string      `json:"display_name"`
	Website           *string     `json:"website"`
	DocsURL           *string     `json:"docs_url"`
	PricingURL        *string     `json:"pricing_url"`
	StatusURL         *string     `json:"status_url"`
	APIType           string      `json:"api_type"`
	DefaultBaseURL    *string     `json:"default_base_url"`
	SupportedModes    []string    `json:"supported_modes"`
	Auth              *AuthConfig `json:"auth"`
	BaseURLEnv        *string     `json:"base_url_env"`
	DefaultRateLimits *RateLimits `json:"default_rate_limits"`
}

ProviderEntry represents a provider in the registry.

type ProviderModelEntry

type ProviderModelEntry struct {
	ModelRef        string  `json:"model_ref"`
	ProviderModelID *string `json:"provider_model_id"`
	// CustomModelID is retained for compatibility with older cached payloads.
	CustomModelID   *string            `json:"custom_model_id"`
	Enabled         bool               `json:"enabled"`
	Pricing         *core.ModelPricing `json:"pricing"`
	ContextWindow   *int               `json:"context_window"`
	MaxOutputTokens *int               `json:"max_output_tokens"`
	Capabilities    map[string]bool    `json:"capabilities"`
	RateLimits      *RateLimits        `json:"rate_limits"`
	Endpoints       []string           `json:"endpoints"`
	Regions         []string           `json:"regions"`
}

ProviderModelEntry represents a provider-specific model override.

type RankingEntry

type RankingEntry struct {
	Score *float64 `json:"score"`
	Elo   *float64 `json:"elo"`
	Rank  *int     `json:"rank"`
	AsOf  *string  `json:"as_of"`
}

RankingEntry holds a model's score in a benchmark or ranking.

type RateLimits

type RateLimits struct {
	RPM *int `json:"rpm"`
	TPM *int `json:"tpm"`
	RPD *int `json:"rpd"`
}

RateLimits holds rate limit information.

Jump to

Keyboard shortcuts

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