pub trait Plugin: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn version(&self) -> &str;
fn on_request(&self, req: &mut PromptRequest) -> Result<(), PluginError>;
fn on_response(&self, resp: &mut Vec<String>) -> Result<(), PluginError>;
}Expand description
Core trait for request/response plugins.
Implement this trait and register it with a PluginV2Registry to
intercept requests before inference and responses after inference.
Required Methods§
Sourcefn on_request(&self, req: &mut PromptRequest) -> Result<(), PluginError>
fn on_request(&self, req: &mut PromptRequest) -> Result<(), PluginError>
Inspect and/or mutate the request before it reaches inference.
Return Err(PluginError::RequestRejected { .. }) to abort the request.
Sourcefn on_response(&self, resp: &mut Vec<String>) -> Result<(), PluginError>
fn on_response(&self, resp: &mut Vec<String>) -> Result<(), PluginError>
Inspect and/or mutate the response tokens after inference.
Return Err(PluginError::ResponseModified) or Err(PluginError::Fatal)
to signal post-processing issues (pipeline may log and continue).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".