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 ¶
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.