Skip to main content

apply

Function apply 

Source
pub fn apply(
    body: &mut Value,
    ctx: &ModelContext,
    layers: &SamplingLayers,
    budget_chars: Option<usize>,
) -> Result<TruncationReport, TruncationError>
Expand description

Apply every request-shaping transform, in order, in place.

This is the whole pipeline as one call. See the module docs for the stage order and why it is fixed.

budget_chars is the history-truncation budget in characters. ModelContext::context_budget_chars is the answer for callers with no live serving context to measure; the proxy passes its own, computed from the running server’s context size and a learned chars-per-token ratio. None skips stage 3 entirely and reports zeroes — the request is shaped but never measured, which is what an unresolvable model gets.

Unknown fields, top-level and per-message alike, are preserved.

§Errors

TruncationError when the conversation cannot be made to fit budget_chars. body is left shaped and trimmed; callers reject the request rather than forward it.