modelregistry

package
v0.17.21 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package modelregistry provides a client for fetching per-provider model lists from a static JSON model registry server with in-memory caching.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearCache

func ClearCache()

ClearCache removes all cached entries.

func IsEnabled

func IsEnabled() bool

IsEnabled returns true if the registry URL is configured.

func SetBaseURL

func SetBaseURL(url string)

SetBaseURL sets the registry base URL (useful for testing).

func SetHTTPTimeout

func SetHTTPTimeout(d time.Duration)

SetHTTPTimeout sets the HTTP client timeout (useful for testing).

func SetNegativeTTL

func SetNegativeTTL(d time.Duration)

SetNegativeTTL sets the negative cache TTL for 404 responses (useful for testing).

func SetTTL

func SetTTL(d time.Duration)

SetTTL sets the cache TTL (useful for testing).

Types

type ModelInfo

type ModelInfo struct {
	ID               string   `json:"id"`
	Name             string   `json:"name,omitempty"`
	Description      string   `json:"description,omitempty"`
	Provider         string   `json:"provider,omitempty"`
	Size             string   `json:"size,omitempty"`
	Cost             float64  `json:"cost,omitempty"`
	InputCost        float64  `json:"input_cost,omitempty"`
	OutputCost       float64  `json:"output_cost,omitempty"`
	CachedInputCost  float64  `json:"cached_input_cost,omitempty"`
	ContextLength    int      `json:"context_length,omitempty"`
	Tags             []string `json:"tags,omitempty"`
	EligibleRoles    []string `json:"eligible_roles,omitempty"`
	RecommendedRoles []string `json:"recommended_roles,omitempty"`
	Warnings         []string `json:"warnings,omitempty"`
	VisionProbe      *bool    `json:"vision_probe,omitempty"`
}

ModelInfo mirrors api.ModelInfo for registry JSON responses. NOTE: Intentionally duplicated to avoid import cycles between modelregistry and agent_api. Keep in sync with pkg/agent_api/models.go ModelInfo.

type RawModel

type RawModel struct {
	ID               string   `json:"id"`
	Name             string   `json:"name,omitempty"`
	Description      string   `json:"description,omitempty"`
	Provider         string   `json:"provider,omitempty"`
	Size             string   `json:"size,omitempty"`
	Cost             float64  `json:"cost,omitempty"`
	InputCost        float64  `json:"input_cost,omitempty"`
	OutputCost       float64  `json:"output_cost,omitempty"`
	CachedInputCost  float64  `json:"cached_input_cost,omitempty"`
	ContextLength    int      `json:"context_length,omitempty"`
	Tags             []string `json:"tags,omitempty"`
	EligibleRoles    []string `json:"eligible_roles,omitempty"`
	RecommendedRoles []string `json:"recommended_roles,omitempty"`
	Warnings         []string `json:"warnings,omitempty"`
	VisionProbe      *bool    `json:"vision_probe,omitempty"`
}

RawModel is a provider-agnostic model representation used for cache storage and inter-package transfer without creating import cycles.

func FetchModels

func FetchModels(ctx context.Context, providerID string) ([]RawModel, error)

FetchModels returns raw model data for a provider from the registry.

Return values:

  • (models, nil): models from registry or cache
  • (nil, nil): registry disabled, provider not found (404/negative cache), or temporary error triggers fallback
  • (nil, err): hard error (invalid provider ID, network failure other than 404)

Caching behavior:

  • Successful responses are cached for the configured TTL (default 5 minutes)
  • 404 responses are cached in a negative cache for negativeTTL (default 30 seconds) to avoid repeated requests
  • Singleflight deduplicates concurrent requests for the same provider
  • Use ClearCache() to manually invalidate all cached entries

Jump to

Keyboard shortcuts

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