contextlimits

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 6 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 contextlimits caches activity-side provider model lookups.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache coalesces model lookups and retains successful metadata for the client lifetime. Other failures retain fallback for negativeTTL; caller cancellations are never cached. Its zero value is ready for use; do not copy after first use.

func (*Cache) Lookup

func (c *Cache) Lookup(ctx context.Context, key string, fallback Result, load func(context.Context) (Result, bool)) Result

Lookup coalesces load per key with a bounded caller-derived deadline. load reports success separately from whether fallback limits are known. Waiters can cancel independently and receive fallback while another lookup is pending.

type Result

type Result struct {
	// Limits is the cached token-limit snapshot.
	Limits model.ContextLimits
	// InputLimit is the raw input-only allowance returned by a Models API.
	// Zero means Limits already describes a shared window, such as table fallback.
	InputLimit int
	// Model is the resolved provider model ID.
	Model string
	// Known reports whether the context window is known.
	Known bool
}

Result retains both a provider's limits and its resolved model ID.

func (Result) ForRequest

func (r Result) ForRequest(req *model.Request) (model.ContextLimits, bool)

ForRequest maps cached input-only metadata to a shared window for this request. Subtracting OutputReserve from the returned window preserves InputLimit. Table fallback windows are already shared and remain unchanged.

Jump to

Keyboard shortcuts

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