models

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 40 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

Index

Constants

View Source
const (
	// DefaultContext is the window assumed when no source states a window for the model.
	DefaultContext = 256_000
	// MinimumContext is the least window a session, a model switch or a job accepts.
	MinimumContext = 64_000
)
View Source
const (
	// Expensive is a model priced past the limits of Model safeguards.
	Expensive = "expensive"
	// Deprecated is a model its provider's listing or the models.dev registry marks as deprecated.
	Deprecated = "deprecated"
	// Switch is a switch of a session's model while the session has many tokens, which the new model reads again uncached.
	Switch = "switch"
)

Kinds of the warnings the host's own guards give, which an answer and the settings name them by

View Source
const (
	// The pick went ahead once confirmed, this time
	AnsweredOnce = "once"
	// The pick went ahead, and the model is not asked about again
	AnsweredAlways = "always"
	// The user kept what they had
	AnsweredNo = "no"
	// Nobody could be asked, or the settings never allow it, so the pick was refused
	AnsweredRefused = "refused"
)

Answers a user gave the guards, as Answered counts them

View Source
const (
	// FromProvider is a price the provider's own listing states.
	FromProvider = "provider_models_api"
	// FromEndpoint is a price the models listing at an address no plugin lists for states. A guard does not trust it.
	FromEndpoint = "endpoint_models_api"
	// FromDev is a price the models.dev registry states.
	FromDev = "models.dev"
	// FromNowhere is the source of a price no source states.
	FromNowhere = "none"
)

The sources a price comes from.

View Source
const IncludedNote = "subscription-included, no provider invoice for usage"

IncludedNote is the note of a cost a subscription covers.

Variables

This section is empty.

Functions

func Abilities

func Abilities(facts provider.Facts) string

Abilities returns what a model can do, as a list a user reads, or "text only" when no source states an ability of note.

func Accepted

func Accepted(cfg *config.Config, route provider.Route) bool

Accepted reports whether the user had the guards stop asking about the route's model: Approved models lists it with its provider, or without a provider.

func ChatIDs

func ChatIDs(rows []provider.Facts) []string

ChatIDs returns the ids of the rows that answer in text and are not hidden, in the listing's order.

func ContextLimit

func ContextLimit(message string) (int, bool)

Context window a provider's error quotes, none for an error about output alone

func CostLabel

func CostLabel(amount *big.Rat) string

Amount as $0.00 for nothing, at four places below a cent and two above

func Dev

func Dev(id string, entry map[string]any) provider.Facts

Dev returns the facts that a models.dev entry states.

func Fetch

func Fetch(ctx context.Context, cfg *config.Config, route provider.Route, modelsURL string) ([]any, bool)

Fetch reads the items of a models reply at the address, or at the models path of the route's base URL, through the profile's network settings. It accepts a bare array and an object that has the items under data or models.

func Find

func Find(rows []provider.Facts, id string) (provider.Facts, bool)

Find returns the row with the id, matched exactly and then without regard to case.

func Free

func Free(price *provider.Price) bool

Free reports whether a price is stated and every rate it states is zero.

func GetJSON

func GetJSON(ctx context.Context, cfg *config.Config, target string, timeout time.Duration, headers map[string]string) (any, error)

JSON a GET of the address answers with, asked through the proxy and authorities of the profile's environment, an error for any status but success

func Identity

func Identity(key string) string

Stable non secret id of a credential, for telling accounts apart

func LMStudioRoot

func LMStudioRoot(base string) string

LMStudioRoot returns the root of an LM Studio server for its own API, with its /api/v1, /api or /v1 path removed.

func Listed

func Listed(item map[string]any) (provider.Facts, bool)

Listed returns the facts that one item of a models reply states, under any field name that a provider's listing is known to use. ok is false for an item without an id.

func Local

func Local(base string) bool

Local reports whether the address is on this machine or its network: loopback, a container's or a .local name, a bare host name, a private, link local or Tailscale address.

func LowerContextLimit

func LowerContextLimit(message string, current int) (int, bool)

Window a provider's error quotes when it is below the one assumed, which then was too big

func OutputBudget

func OutputBudget(message string) (int, bool)

Output tokens a refusal of too many says there may be

func OutputCapError

func OutputCapError(message string) bool

Whether a refusal is of the output asked for being too big, not of the input

func PerMillion

func PerMillion(price string) string

PerMillion returns a price for a million tokens as dollars, empty when the price is no number.

func Request

func Request(ctx context.Context, cfg *config.Config, method, target string, headers map[string]string, body []byte, timeout time.Duration) (map[string]any,
	error)

JSON object one request is answered with, asked through the proxy and authorities of the profile's environment, empty for an empty body. A StatusError for any status but success. Redirects are followed, without the credentials when they lead to another origin

func Routed

func Routed(ctx context.Context, cfg *config.Config, route provider.Route) context.Context

Context whose requests to the route's own host carry the route's headers under their own and its Query parameters, the latter none for a route AWS signs. How the host asks every registrant about a route, so no listing, probe or usage reading of a provider goes without them

func Rows

func Rows(items []any, read func(item map[string]any, facts *provider.Facts)) []provider.Facts

Rows returns the facts of every listed item that has an id. read, when set, adds the facts that only one kind's reply states.

func Scalar

func Scalar(v any) string

Scalar returns the text of a decoded JSON scalar, with a number written out in full. It is empty for anything else.

func StaleUsage

func StaleUsage(reading *provider.AccountUsage) bool

Whether a reading is too old, or from the future, to show as live

func Status

func Status(err error) int

Status of an error a request failed with, 0 when it got no answer

func Tokens

func Tokens(n int64) string

Count of tokens in digits grouped in thousands, empty when not known

Types

type Catalog

type Catalog struct {
	// IDs has every row's id, in the rows' order.
	IDs  []string
	Rows []CatalogRow
	// StandIn is true when the provider could not be asked, and the rows are the models.dev registry's models for the route's kind.
	StandIn bool
	// Unlisted is the reason the provider did not give its own list. It is nil when the provider gave a list now or earlier.
	Unlisted *Unlisted
}

Catalog lists the chat models a route's provider offers, in the provider's own order, with the picker's details for each model.

func (Catalog) Row

func (c Catalog) Row(id string) (CatalogRow, bool)

Row returns the catalog row with the id, matched exactly and then regardless of case.

type CatalogRow

type CatalogRow struct {
	Facts provider.Facts
	Note  string
}

CatalogRow is one model in a catalog: every fact known without asking the provider again, and a short note that sets the model apart, such as free, the provider's default, or deprecated.

type Cost

type Cost struct {
	// USD is nil when the cost is not known.
	USD *big.Rat
	// Parts has the USD of each part the price prices: input, output, cache_read, cache_write and request. It is nil when not known.
	Parts map[string]*big.Rat
	// Status is estimated, included or unknown.
	Status  string
	Source  string
	Label   string
	Version string
	Fetched time.Time
	Notes   []string
}

Cost is what a request cost, or the reason that is not known.

func (Cost) Amount

func (c Cost) Amount() float64

Amount returns the cost in USD. It is 0 when the cost is not known.

type Env

type Env struct {
	Host   *Models
	Config *config.Config
	Route  provider.Route
	// Refresh asks the registrant to read the provider again now, regardless of what is cached.
	Refresh bool
}

Env is what a registrant is asked about: the route, the settings of its profile, and the host that reaches everything else known.

func (*Env) Cache

func (e *Env) Cache(name string) string

Cache returns the path of the profile's cache file with the name.

type Floor

type Floor struct {
	FirstEvent time.Duration
	Silence    time.Duration
}

Floor is the minimum time a transport waits for a model on a route: for a reply's first event, and between two events. A part is 0 when no successful reply was observed, and the transport then uses its kind-wide default.

type Former

type Former interface {
	Lister
	Format() provider.APIMode
}

Former is a Lister that answers for the routes of one request format before the Listers of their kinds, such as a program that serves the models of its own sign-in regardless of the provider's kind. It is not asked about a route of another format.

type Guard

type Guard interface {
	Guard(ctx context.Context, env *Env, pick Pick) []Warning
}

Registrant that says what is wrong with a model picked before the pick takes effect, nothing for a pick it has nothing against. A registrant that only guards answers Models with nothing

type Guarded

type Guarded struct {
	Pick     Pick
	Warnings []Warning
	// Made of the profile, the pick and the kinds warned of: a confirmation that carries it confirms this very pick alone. Empty when
	// nothing was said
	Token string
}

What the guards say of one pick, and the token a confirmation of it carries

func (Guarded) Confirmed

func (g Guarded) Confirmed(token string) bool

Whether the token confirms the pick: given, and made for this very pick and its warnings

func (Guarded) Kinds

func (g Guarded) Kinds() []string

The kinds warned of, in the order said

func (Guarded) Lasting

func (g Guarded) Lasting() bool

Whether a user may have the guards stop asking about the model: some warning lasts, and none is refused whatever the answer

func (Guarded) Never

func (g Guarded) Never() []Warning

Warnings the settings never allow, which refuse the pick whoever answers

func (Guarded) Picked

func (g Guarded) Picked() string

The pick as a user reads it: the model, and the provider it runs on

func (Guarded) Refusal

func (g Guarded) Refusal(warnings []Warning, unattended bool) string

Why the pick does not take effect where nobody can confirm it, or where the settings never allow it, as one sentence or more a person reads. The warnings said after it

func (Guarded) Stopping

func (g Guarded) Stopping() []Warning

Warnings that stop a run nobody can ask: every one but those the settings let such a run go ahead on

func (Guarded) Text

func (g Guarded) Text() string

Words of every warning, one after another, each under its heading when there are several

func (Guarded) Title

func (g Guarded) Title() string

Heading of the confirmation: the warning's own when there is one, otherwise one for them all

type Lister

type Lister interface {
	List(ctx context.Context, env *Env) (rows []provider.Facts, ok bool)
}

Lister is a registrant that reads the provider's own listing: every model the route's provider lists, with every fact the listing states. ok is false when the registrant does not answer for the route.

type Listing

type Listing struct {
	Provider string
	URL      string
	Public   bool
	Read     func(item map[string]any, facts *provider.Facts)
}

Listing is the Lister for a kind with an OpenAI-style models reply, at URL or at the models path of the route's base URL. A public listing is read without the route's key. Read, when set, takes the facts that only this kind's reply states from one listed item.

func (Listing) List

func (l Listing) List(ctx context.Context, env *Env) ([]provider.Facts, bool)

List reads the listing for a route on the Listing's kind.

type Models

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

Models is the host's knowledge of the models of every provider: their listings and facts, the models.dev registry, the windows and prices providers state, what replies and refusals taught, what requests cost and what accounts may still spend. Each profile keeps its own caches in its folder.

func New

func New(cfg *config.Config, providers *provider.Registry) *Models

New returns the host, its settings registered.

func (*Models) Allow

func (m *Models) Allow(cfg *config.Config, g Guarded) error

Allow saves that the user had the guards stop asking about the pick's model, by adding it to Approved models with its provider.

func (*Models) Answered

func (m *Models) Answered(g Guarded, answer string)

Counts an answer to what the guards said, by the kinds they warned of

func (*Models) CachedUsage

func (m *Models) CachedUsage(cfg *config.Config, route provider.Route) *provider.AccountUsage

Reading remembered for the route, nil when none landed

func (*Models) Catalog

func (m *Models) Catalog(ctx context.Context, cfg *config.Config, route provider.Route, refresh bool) Catalog

Catalog returns the route provider's chat models: the listing rows that answer in text and are not hidden, in the provider's order. When the provider can't be asked, the rows are the models.dev registry's chat models for the route's kind, marked as a stand-in. When the kind has no models.dev id either, the catalog is empty and Unlisted gives the reason. refresh reads the provider now.

func (*Models) ContextLength

func (m *Models) ContextLength(ctx context.Context, cfg *config.Config, route provider.Route) int

ContextLength returns the tokens the route's model takes in at once: the window the profile's overrides set, otherwise the window the provider's listing states, then a window a refusal of the provider taught, then the models.dev registry's window, then the window a server on this machine reports, otherwise DefaultContext. A window a refusal taught is also the most the listing's or the registry's window can give. The window found is used for five minutes, or until a window is learned or forgotten.

func (*Models) Cost

func (m *Models) Cost(ctx context.Context, cfg *config.Config, route provider.Route, usage provider.Usage) Cost

Cost returns the cost of one request on the route: its tokens at the model's prices, at the serving tier's prices when the tier has its own, and at the higher prices past the price's threshold. A part without a stated price makes the cost unknown.

func (*Models) DefaultModel

func (m *Models) DefaultModel(cfg *config.Config, instance provider.Instance) string

DefaultModel returns the provider's default model, the rule every screen and every route follows: the provider's default model setting, otherwise the model the selection rules pick from its newest cached listing, otherwise from the models.dev registry's models for its kind. Nothing is fetched, so it is empty for a provider that was never listed and that models.dev does not describe. RouteDefault reads the listing when no listing is cached.

func (*Models) Endpoint

func (m *Models) Endpoint(ctx context.Context, cfg *config.Config, route provider.Route) ([]provider.Facts, bool)

Endpoint reads the models listing at the route's address as an OpenAI-style server answers it, at the base and its v1 twin, and maps every row to facts. On a server on this machine, LM Studio's own listing and the windows llama.cpp allocated are read as well. It is the listing of a route whose kind no plugin lists for, and a plugin for a kind that serves such a listing can return it from its List. Every address it logs is shown as the settings write it.

func (*Models) Facts

func (m *Models) Facts(ctx context.Context, cfg *config.Config, route provider.Route) provider.Facts

Facts returns everything known about the route's model. Each fact comes from the first source that states it: the profile's overrides for the model and then for every model of its provider, the provider's listing, what the provider's replies and refusals taught on this profile, the models.dev registry (and its row for the model's canonical id), then a server on this machine or at an address no kind claims that reports on its models. A window a refusal stated is the model's limit unless an override sets a window. The overrides for every provider fill in only for a model that no source knows and that its provider's overrides do not mention.

func (*Models) ForgetWindow

func (m *Models) ForgetWindow(cfg *config.Config, route provider.Route)

ForgetWindow forgets the window learned for the route's model and the facts a server on this machine reported, so the next request finds the window again.

func (*Models) Guards

func (m *Models) Guards(ctx context.Context, cfg *config.Config, pick Pick) Guarded

What every guard says of the pick on the profile of the settings, in the order they were registered. What a person had stop for the model left out. A guard that panics says nothing, with a line in the log, so a pick never breaks on one

func (*Models) HasUsage

func (m *Models) HasUsage(route provider.Route) bool

Whether the route's kind can say what its accounts may still spend

func (*Models) HelperModel

func (m *Models) HelperModel(ctx context.Context, cfg *config.Config, route provider.Route, set string) string

HelperModel returns the side jobs' model at the route's provider: the model in the job's setting, otherwise the cheapest priced chat model that calls tools and accepts at least MinimumContext tokens, otherwise the route's own model, which is the session's main model when the side job runs on the session's provider. It is empty when no such model is known.

func (*Models) Kind

func (m *Models) Kind(base string) string

Kind returns the kind of provider an address belongs to: the kind claiming its host, otherwise the kind whose base URL has that host. It is empty when no kind claims the address.

func (*Models) Largest

func (m *Models) Largest(ctx context.Context, cfg *config.Config, route provider.Route) int

Largest returns the window the route's provider accepts for the model when a request asks for a window above ContextLength. It is 0 when no source states a larger window.

func (*Models) Learn

func (m *Models) Learn(cfg *config.Config, route provider.Route, change func(learned *provider.Facts))

Learn records facts that a reply or a refusal of the route's provider taught about the route's model. change gets the facts learned so far and edits them. The facts are saved for the provider's address and account, so another account learns for itself.

func (*Models) LearnRefusal

func (m *Models) LearnRefusal(cfg *config.Config, route provider.Route, field, remedy string)

LearnRefusal records that the route's provider refused a request field for the route's model, and the remedy the refusal gave, such as the value it takes or "omit". Facts.Refused reads it back.

func (*Models) LearnWindow

func (m *Models) LearnWindow(cfg *config.Config, route provider.Route, window int)

LearnWindow records the context window that the route's provider stated in a refusal of a request that was too long. From then on the window is the limit for ContextLength, unless an override sets a window.

func (*Models) Learned

func (m *Models) Learned(cfg *config.Config, route provider.Route) provider.Facts

Learned returns the facts that the provider's replies and refusals taught about the route's model on this profile.

func (*Models) Listing

func (m *Models) Listing(ctx context.Context, cfg *config.Config, route provider.Route, refresh bool) ([]provider.Facts, bool)

Listing returns every model the route's provider lists with the facts its listing states, and whether a listing was read now or earlier. A fresh cached copy is returned directly. An old copy is returned while a new read runs in the background, and a copy older than a week is replaced by a new read and stays in use when that read fails. refresh reads the provider now. When no plugin lists the route's kind, the models path at its base URL is read.

func (*Models) Observe

func (m *Models) Observe(cfg *config.Config, route provider.Route, firstEvent, silence time.Duration)

Observe records one successful reply's pace for the route's model: the time to its first event and the longest silence between two events.

func (*Models) OfKind

func (m *Models) OfKind(ctx context.Context, cfg *config.Config, route provider.Route, kind string) []provider.Facts

OfKind returns the route provider's models of one kind, such as speech, transcription, image or embedding, with every known fact, in the provider's order. Without a listing they are the models.dev registry's models of that kind.

func (*Models) OllamaShow

func (m *Models) OllamaShow(ctx context.Context, cfg *config.Config, route provider.Route) (provider.Facts, bool)

OllamaShow returns the facts a server that answers Ollama's show request states for the route's model: its window, and whether it calls tools, thinks and sees images. A plugin for a provider that serves Ollama's API reads its models through it. ok is false when the server does not answer.

func (*Models) Picked

func (m *Models) Picked(cfg *config.Config) []Picked

Models the settings of the profile pick, each with the route it lands on: every setting that declares it picks a model, one by one in a list of them, and every field of the entries of a table that declares it does. Approved models lists models but uses none of them.

func (*Models) RefreshDev

func (m *Models) RefreshDev(cfg *config.Config) error

RefreshDev fetches the models.dev registry now, asking only for a change when one is held, and keeps it. It returns the reason the registry can't be read. It is nil when the registry answers, or when Fetch details is off.

func (*Models) RefreshUsage

func (m *Models) RefreshUsage(ctx context.Context, cfg *config.Config, routes []provider.Route)

Refreshes the reading of each route in the background, unless one runs for it or was tried in the last two minutes

func (*Models) Refusals

func (m *Models) Refusals(cfg *config.Config, route provider.Route) map[string]string

Refusals returns the request fields the route's provider refused for the route's model on this profile, each with the remedy the refusal gave.

func (*Models) Register

func (m *Models) Register(registrant Registrant)

Register adds a registrant. A registry registered into the host reaches it through Host.

func (*Models) Registered

func (m *Models) Registered(cfg *config.Config, route provider.Route, network bool) []provider.Facts

Registered returns the facts of every model in the registry block of the route's provider, newest first, then by id. The registry is fetched when network allows it and none is held. It is empty when the route's kind has no models.dev id.

func (*Models) RouteDefault

func (m *Models) RouteDefault(ctx context.Context, cfg *config.Config, route provider.Route) string

RouteDefault returns the route provider's default model by the DefaultModel rules, and reads the route's listing when no listing is cached.

func (*Models) Served

func (m *Models) Served(ctx context.Context, cfg *config.Config, route provider.Route) (provider.Facts, bool)

Served returns the facts the server at the route's address states for the route's model, for a server on this machine or at an address that no provider kind claims: Ollama's show reply, otherwise the model's row in the server's models listing, read in the server's own format. ok is false for any other route and when the server does not state any fact.

func (*Models) ServerType

func (m *Models) ServerType(ctx context.Context, cfg *config.Config, base, key string) string

ServerType returns the kind of server at an address that no provider kind claims, found by the endpoints only that kind answers: lm-studio, ollama, llamacpp or vllm. It is empty for a claimed address and when no server answers.

func (*Models) ShownPrice

func (m *Models) ShownPrice(cfg *config.Config, route provider.Route) (provider.Price, bool)

ShownPrice returns the route model's price for showing beside it, at this moment, the same price Cost bills at the standard tier. Nothing is fetched. ok is false when no source states a price.

func (*Models) Spec

func (m *Models) Spec(route provider.Route) provider.Spec

Spec returns the route's kind as its provider has it, its settings resolved, or the kind as its plugin registers it for a route of no provider.

func (*Models) Tallies

func (m *Models) Tallies() (map[string]int, map[[2]string]int)

Warnings the guards gave and the answers they had in this process, by kind, and by kind and answer

func (*Models) TierPrice

func (m *Models) TierPrice(cfg *config.Config, route provider.Route, tier string) (provider.Price, bool)

TierPrice returns the price Cost bills for a request that the tier served on the route, at this moment, for showing beside the tier. Nothing is fetched. The empty tier, and the standard tier's names (default, standard, auto, on_demand), give the standard price.

func (*Models) TimeoutFloor

func (m *Models) TimeoutFloor(cfg *config.Config, route provider.Route) Floor

TimeoutFloor returns the minimum time a transport waits for the route's model, from the recent successful replies observed on this profile: twice the slowest reply's time, for the first event and for a silence.

func (*Models) Unattended

func (m *Models) Unattended(ctx context.Context, cfg *config.Config, route provider.Route, from string) error

Why a route that settings or a task chose, where nobody is asked, may not be used: a warning the settings never allow, or one a run nobody watches may not go ahead on. nil when it may. Every door that picks a model from settings asks it: subagents, a mixture's acting model and advisers, helper models and the voice mode model

func (*Models) Usable

func (m *Models) Usable(ctx context.Context, cfg *config.Config, route provider.Route) int

Usable returns the tokens a request on the route may fill: the share of the window the provider lets a request use, when its listing states one, otherwise the whole window.

func (*Models) Usage

func (m *Models) Usage(ctx context.Context, cfg *config.Config, route provider.Route) *provider.AccountUsage

What the provider of the route says of the limits of its account, remembered for the route and its account. nil when the kind can't say, no account is signed in or the fetch failed

func (*Models) Validate

func (m *Models) Validate(ctx context.Context, cfg *config.Config, route provider.Route) Verdict

Validate checks the model that a switch to the route requests, without rewriting its id. It refuses an empty id, an id with spaces, which vendor catalogs never use, a model the provider's listing states does not answer in text, or a model missing from the provider's listing. It accepts the model with a note when the models.dev registry's models replace the listing, when no list could be read, or when the listing can omit models. For a model that is not listed, it suggests up to three close matches.

func (*Models) VisionModel

func (m *Models) VisionModel(ctx context.Context, cfg *config.Config, route provider.Route) (string, bool)

VisionModel returns the image side jobs' model at the route's provider: the route's own model when it accepts images, otherwise the cheapest listed chat model that accepts images, otherwise the first such model listed. ok is false when no model on the provider is known to accept images.

func (*Models) Warned

func (m *Models) Warned(ctx context.Context, cfg *config.Config, pick Pick) []Warning

What every guard says of the pick, what a person had stop for the model among it: what the profile uses that a guard warns of, as the audit and the doctor read it

func (*Models) WindowSet

func (m *Models) WindowSet(cfg *config.Config, route provider.Route) (int, bool)

WindowSet returns the context window the profile's overrides set for the route's model, otherwise for every model on its provider. ok is false when the overrides do not set a window.

type Pace

type Pace struct {
	At         time.Time     `json:"at"`
	FirstEvent time.Duration `json:"first_event"`
	Silence    time.Duration `json:"silence"`
}

Pace records one successful reply's pace: the time from sending the request to the reply's first event, and the longest silence between two of its events.

type Pick

type Pick struct {
	// Route the pick lands on: the provider of the profile, its kind, the model and its address
	Route provider.Route
	// Tokens the session the pick is for holds as its last request was measured; 0 for a pick of no session, or of one that holds none
	Held int
	// Model the session ran on before the pick, empty for none
	From string
}

One model picked, as the guards are asked about it before it takes effect

type Picked

type Picked struct {
	// Where it is set, as a user finds it: the setting and its section, with the entry of a table
	Where string
	// Key of the setting, with the name of the entry of a table after it
	Key string
	// Route of the model on the provider of the profile it names, the provider empty when the setting names none
	Route provider.Route
}

A model a setting of the profile picks, as the audit and the doctor weigh what the profile uses

type Reads

type Reads[T any] struct {
	// contains filtered or unexported fields
}

What slow reads gave, such as a provider's listing asked over the network, kept by key for as long as each read says: one read of a key at a time, the callers that ask while it runs waiting for its answer rather than asking again

func (*Reads[T]) Get

func (r *Reads[T]) Get(ctx context.Context, key string, fresh bool, read func(ctx context.Context) (T, time.Duration)) T

Value of the key: what a read gave while it stands, otherwise what the read under way gives, otherwise what read gives now, kept as long as read says. Fresh reads now whatever stands, though a read under way is still waited for rather than made twice. A read runs in a context of its own that the caller ending does not end, so whoever waits for it gets its answer. A caller that ends while it waits takes what stood

func (*Reads[T]) Keep

func (r *Reads[T]) Keep(key string, value T, keep time.Duration)

Keeps a value read some other way for the key, standing as long as keep says, such as a listing read for the list of models that answers for its details too

type Registrant

type Registrant any

Registrant is what a plugin registers with the host: a Lister that reads a provider's listing, a Guard that judges a pick, or both. A registry registered into the host's own hands its registrants over.

type Registry

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

Registry holds the registrants of the host.

func (*Registry) Host

func (r *Registry) Host() *Models

Host returns the host the registry belongs to, through which plugins reach the listings, facts and prices of models.

func (*Registry) Register

func (r *Registry) Register(registrant Registrant)

Register adds a registrant to the host's one list. A registry registered into another hands over its registrants once, then registers into the host and answers as the host does, so no list is nested in another.

type StatusError

type StatusError struct {
	Status int
	URL    string
}

Non success status of a request

func (*StatusError) Error

func (e *StatusError) Error() string

type Unlisted

type Unlisted struct {
	URL    string
	Status int
	Err    error
	Shape  bool
	// None is true when no plugin lists the models of the route's kind and the route has no address to ask.
	None bool
}

Why a provider gave no list of models of its own, as the requests of its listing met it: the address asked last, and the error status it answered with, the failure to reach it or an answer that holds no list. An answer with no models when none of those

func (Unlisted) Reason

func (u Unlisted) Reason(name string) string

Why the provider with the name has no models of its own to pick, then what to do, in sentences a user reads

func (Unlisted) Refused

func (u Unlisted) Refused() bool

Refused reports whether the provider turned the listing's key away or could not be reached at all.

type Verdict

type Verdict struct {
	Accepted bool
	Message  string
}

Verdict is the outcome of checking the model a switch requests: whether the switch goes ahead, and the message the user gets about the model.

type Warning

type Warning struct {
	// Guard that says it: one of the host's kinds, or a word of the plugin that brings the guard
	Kind string
	// Heading of the confirmation, such as Expensive model
	Title string
	// What is wrong with the pick, whole sentences, the prices and sizes in them
	Text string
	// Lasting is true when the user may stop being asked about the model, which adds it to Approved models.
	Lasting bool
	// The settings never allow it: refused whoever answers
	Never bool
	// A run nobody can ask goes ahead on it, as the settings allow
	Unasked bool
}

What a guard says of a pick, which a user confirms before the pick takes effect

func Costly

func Costly(model string, price provider.Price, priced bool, source string, input, output float64) (Warning, bool)

Costly returns the warning of a model whose known price is strictly past either limit, in dollars for a million tokens. A price at the limit is not past it, and a price that is not known never warns.

func Retiring

func Retiring(model string, facts provider.Facts) (Warning, bool)

Retiring returns the warning of a model whose facts mark it as deprecated. It does not warn for a model no source marks.

func Switching

func Switching(held, threshold int, from, to string) (Warning, bool)

Switching returns the warning of a switch of a session's model to another while the session has at least the threshold of tokens, which the new model reads again uncached. It does not warn for an unmeasured session, a threshold of 0, an empty model, or the model the session already runs on.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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