Help us shape the future of Go! Take the 2026 Go Developer Survey

models

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package models contains the generated model catalog and its persisted refresh overlay.

Package models contains the generated model catalog and runtime refresh layer.

Index

Constants

View Source
const ModelsDevURL = "https://models.dev/api.json"

Variables

This section is empty.

Functions

func OrbUserAgent

func OrbUserAgent(version string) string

OrbUserAgent formats the catalog-refresh User-Agent, mirroring upstream getPiUserAgent (pi-user-agent.ts) with Orb's public identity.

func RefreshCodex added in v0.11.0

func RefreshCodex(ctx context.Context, options RefreshOptions, token, accountID string) error

RefreshCodex replaces the stored openai-codex models with the list the ChatGPT account offers. Known models keep their catalog metadata; new ones inherit it from the highest-priority known model, taking name, cost and output limit from the same-id OpenAI API model when models.dev has one. The entry's freshness fields stay untouched, so the models.dev gate is unaffected; without an entry (no models.dev refresh yet) nothing is written.

Types

type Catalog

type Catalog struct {
	// contains filtered or unexported fields
}

Catalog is an immutable-by-convention provider/model lookup.

func Builtin

func Builtin() (*Catalog, error)

Builtin loads the catalog generated from the committed models.dev snapshot. The decoded catalog is cached for the process lifetime: the embedded JSON is immutable and every accessor returns detached values, so callers share one instance instead of re-decoding ~518KB per startup surface. The JSON ships gzip-compressed in generated.go and gunzips here on first use.

func Decode

func Decode(data []byte) (*Catalog, error)

Decode loads the normalized provider-keyed catalog shape.

func LoadStore

func LoadStore(path string) (*Catalog, error)

LoadStore restores the provider-scoped models-store.json overlay. Entries for providers bundled in the builtin catalog lose to a newer builtin: the overlay only applies when its lastModified is newer than the bundled catalog build time (upstream remote-catalog-provider.ts remoteModels).

func LoadStoreDocument added in v0.8.0

func LoadStoreDocument(document document.Document) (*Catalog, error)

func Refresh

func Refresh(ctx context.Context, options RefreshOptions) (*Catalog, error)

Refresh fetches models.dev and replaces only fetched providers in the persisted dynamic overlay. A completed refresh within the last 4 hours skips the network and returns the stored overlay (upstream remote-catalog-provider.ts gates on checkedAt plus lastModified presence).

func (*Catalog) BaseModels added in v0.16.0

func (catalog *Catalog) BaseModels(overlay *Catalog) []ai.Model

BaseModels is MergedModels for callers that do not modify the models or anything they point to: without an overlay, they all share one sorted copy, so each model registry need not clone and sort the catalog again.

func (*Catalog) Find

func (catalog *Catalog) Find(provider, id string) (ai.Model, bool)

Find returns a detached model value.

func (*Catalog) MarshalJSON

func (catalog *Catalog) MarshalJSON() ([]byte, error)

func (*Catalog) Merge

func (catalog *Catalog) Merge(overlay *Catalog) *Catalog

Merge overlays models by provider and id.

func (*Catalog) MergedModels added in v0.4.13

func (catalog *Catalog) MergedModels(overlay *Catalog) []ai.Model

MergedModels returns what Merge(overlay).Models() returns without materializing the intermediate merged catalog: each model is cloned exactly once into the sorted result.

func (*Catalog) Models

func (catalog *Catalog) Models(provider ...string) []ai.Model

Models returns detached model values sorted by provider and model id.

type RefreshOptions

type RefreshOptions struct {
	StoreDocument document.Document
	URL           string
	StorePath     string
	Client        *http.Client
	Now           func() time.Time
	// UserAgent identifies the client on the catalog request (upstream sends a
	// pi User-Agent from remote-catalog-provider.ts).
	UserAgent string
	// Force bypasses the checkedAt refresh gate.
	Force bool
}

Directories

Path Synopsis
cmd
genmodels command
internal
cataloggen
Package cataloggen normalizes the models.dev api.json shape into pi models.
Package cataloggen normalizes the models.dev api.json shape into pi models.

Jump to

Keyboard shortcuts

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