modelreg

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package modelreg resolves model token limits from live registries, provider catalogues, static metadata, and finally a safe default.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProviderHTTPStatus

func ProviderHTTPStatus(err error) (int, bool)

ProviderHTTPStatus exposes upstream provider/catalogue HTTP failures to service boundaries without leaking transport implementation details.

Types

type Limits

type Limits struct {
	ContextWindow   int
	MaxOutputTokens int
}

Limits are a model's resolved token limits (0 = unknown).

type Option

type Option func(*Registry)

Option configures a Registry.

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient overrides the HTTP client (used in tests).

func WithLogger

func WithLogger(l *slog.Logger) Option

WithLogger sets the logger.

func WithURLs

func WithURLs(openRouter, modelsDev string) Option

WithURLs overrides the registry endpoints (used in tests).

type ProviderModel

type ProviderModel struct {
	ID              string `json:"id"`
	Name            string `json:"name"`
	ContextWindow   int    `json:"contextWindow,omitempty"`
	MaxOutputTokens int    `json:"maxOutputTokens,omitempty"`
}

ProviderModel is a chat model advertised by a provider's API.

type Registry

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

Registry resolves model limits. It is safe for concurrent use.

func New

func New(opts ...Option) *Registry

New builds a registry.

func (*Registry) ContextWindow

func (r *Registry) ContextWindow(ctx context.Context, modelID, providerID string) int

ContextWindow resolves a model's context window from the registries, or the safe default when unknown. Never returns 0.

func (*Registry) FetchModels

func (r *Registry) FetchModels(ctx context.Context, kind, baseURL, apiKey string) ([]ProviderModel, error)

FetchModels lists a provider's chat models from its API, cached per provider+baseURL. kind selects the wire format; baseURL falls back to the vendor default for built-in kinds.

func (*Registry) Lookup

func (r *Registry) Lookup(ctx context.Context, modelID, providerID string) (Limits, bool)

Lookup resolves a model's limits across the registries (cached), preferring a previously memoized result.

Jump to

Keyboard shortcuts

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