Skip to main content

ModelInterceptor

Trait ModelInterceptor 

Source
pub trait ModelInterceptor: Send + Sync {
    // Provided methods
    fn on_request(&self, _request: &mut ModelRequestView) { ... }
    fn on_message(&self, _message: &mut ModelMessage) { ... }
}
Expand description

Shapes what goes to the provider and what comes back.

Both methods default to doing nothing, so an implementation that cares about one moment does not have to acknowledge the other.

Provided Methods§

Source

fn on_request(&self, _request: &mut ModelRequestView)

Called once per model call, immediately before the request is sent.

Everything is mutable: messages, tools, sampling parameters, prompt blocks. This is the last point at which the engine’s idea of the request and the provider’s can still be made to differ.

Source

fn on_message(&self, _message: &mut ModelMessage)

Called once per complete message the model produced, after the stream that carried it has finished and before the session records it.

Whole messages only — see the module docs on why there is no per-chunk equivalent.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§