modelinfo

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package modelinfo resolves a model's context window (max input tokens) DYNAMICALLY, so context-guru's triggers can scale with the model rather than hard-coding thresholds. The window is obtained without maintaining our own model list: the primary source is LiteLLM's community-maintained model_prices_and_context_window.json (fetched once and cached); an optional gateway /model/info probe is tried first for deployments that expose it; a tiny embedded table is the last-resort fallback.

Every lookup fails OPEN: an unknown model returns ok=false and callers fall back to absolute thresholds. Nothing here ever blocks a request — fetches are cached, single-flighted, and time-bounded, and any error just leaves the window unknown.

Index

Constants

View Source
const LiteLLMPricesURL = "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"

LiteLLMPricesURL is the community-maintained map of model -> {max_input_tokens,…}. Overridable (air-gapped mirrors) via NewLiteLLM.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

type Chain []Resolver

Chain tries each resolver in order; the first ok wins.

func (Chain) Window

func (c Chain) Window(ctx context.Context, model string) (int, bool)

type LiteLLM

type LiteLLM struct {
	URL    string
	Client *http.Client
	TTL    time.Duration
	// contains filtered or unexported fields
}

LiteLLM fetches and caches the LiteLLM prices map, serving per-model windows.

func NewLiteLLM

func NewLiteLLM(url string, client *http.Client, ttl time.Duration) *LiteLLM

NewLiteLLM builds a resolver. url="" uses LiteLLMPricesURL; ttl<=0 uses 6h.

func (*LiteLLM) Window

func (l *LiteLLM) Window(ctx context.Context, model string) (int, bool)

Window returns the model's context window from the cached LiteLLM map.

type Resolver

type Resolver interface {
	Window(ctx context.Context, model string) (tokens int, ok bool)
}

Resolver returns a model's context window in tokens. ok=false means "unknown".

type Static

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

Static is a tiny last-resort table keyed by substring. Used only when a dynamic source is unavailable. Deliberately small — it is a floor, not a registry.

func DefaultStatic

func DefaultStatic() Static

DefaultStatic covers the common families with conservative windows.

func (Static) Window

func (s Static) Window(_ context.Context, model string) (int, bool)

Jump to

Keyboard shortcuts

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