Skip to main content

Middleware

Trait Middleware 

Source
pub trait Middleware: Send + Sync {
    // Provided methods
    fn before_request<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _request: &'life1 CompletionRequest,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn after_response<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _request: &'life1 CompletionRequest,
        _response: &'life2 CompletionResponse,
        _latency: Duration,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn after_stream<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _request: &'life1 CompletionRequest,
        _latency: Duration,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn on_cache_hit<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _request: &'life1 CompletionRequest,
        _response: &'life2 CompletionResponse,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn on_error<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _request: &'life1 CompletionRequest,
        _error: &'life2 SimpleAgentsError,
        _latency: Duration,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn name(&self) -> &str { ... }
}
Expand description

Middleware hooks for request lifecycle events.

Provided Methods§

Source

fn before_request<'life0, 'life1, 'async_trait>( &'life0 self, _request: &'life1 CompletionRequest, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called before a request is executed.

Source

fn after_response<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _request: &'life1 CompletionRequest, _response: &'life2 CompletionResponse, _latency: Duration, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called after a response is received.

Source

fn after_stream<'life0, 'life1, 'async_trait>( &'life0 self, _request: &'life1 CompletionRequest, _latency: Duration, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when a streaming request completes successfully.

Source

fn on_cache_hit<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _request: &'life1 CompletionRequest, _response: &'life2 CompletionResponse, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called when a response is served from cache.

Source

fn on_error<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _request: &'life1 CompletionRequest, _error: &'life2 SimpleAgentsError, _latency: Duration, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called when a request fails.

Source

fn name(&self) -> &str

Middleware name for diagnostics.

Implementations on Foreign Types§

Source§

impl Middleware for ()

Source§

fn before_request<'life0, 'life1, 'async_trait>( &'life0 self, _request: &'life1 CompletionRequest, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Implementors§