modeldata

package
v0.1.52 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 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 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 attaches resolved metadata from the model list. Models not found in the list are left unchanged.

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)
}

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