Expand description
Context-window budgeting: estimating prompt token cost, deciding whether a request fits, and clamping the completion length to what remains.
Enums§
- Verdict
- The outcome of assessing a prompt against a context window.
Constants§
- BUILTIN_
CONTEXT_ WINDOW - The context window Apple’s built-in model serves: fixed at 4096 tokens per session. The single source for every consumer — the runtime facade’s budget, the apple-foundation scanner’s record hint, and this module’s policy — so the value cannot drift apart.
- COMPLETION_
FLOOR - The minimum number of tokens reserved for the completion when deciding if a prompt fits the window.
Functions§
- assess
- Decide whether a prompt of
prompt_charactersfitswindow, and clamp the completion length to the space that remains. - effective_
window - The effective context window for
record, honoring a per-runtime policy. A built-in model has a fixed window; other runtimes derive it from the record’s declared context length (and, for Ollama, a caller override). - estimated_
tokens - A rough token estimate for
charactersof text (about four characters per token). - prompt_
characters - Count the characters a chat/completion payload will send: the
contentof each message plus a top-levelpromptstring, if present. - stored_
context_ length - The user-set context length stored in the record’s parameter values, if any.