pub struct CostOptimizer { /* private fields */ }Expand description
Analyses cost patterns and generates (or applies) optimisation suggestions.
Implementations§
Source§impl CostOptimizer
impl CostOptimizer
Sourcepub fn new(config: CostOptimizerConfig) -> Result<Arc<Self>, CostOptimizerError>
pub fn new(config: CostOptimizerConfig) -> Result<Arc<Self>, CostOptimizerError>
Create a new optimizer with the given configuration.
§Errors
Returns CostOptimizerError::InvalidConfig if window_size is zero
or cache_candidate_threshold is outside [0, 1].
Sourcepub fn record(
&self,
prompt: &str,
model: &str,
response: &str,
) -> Result<(), CostOptimizerError>
pub fn record( &self, prompt: &str, model: &str, response: &str, ) -> Result<(), CostOptimizerError>
Record a completed inference call.
Sourcepub fn suggestions(
&self,
) -> Result<Vec<OptimizationSuggestion>, CostOptimizerError>
pub fn suggestions( &self, ) -> Result<Vec<OptimizationSuggestion>, CostOptimizerError>
Return a list of optimisation suggestions based on observed patterns.
Sourcepub fn auto_apply(&self) -> Result<Vec<AutoApplyAction>, CostOptimizerError>
pub fn auto_apply(&self) -> Result<Vec<AutoApplyAction>, CostOptimizerError>
Apply all pending suggestions (only when auto_optimize = true).
Returns the list of actions taken.
Sourcepub fn model_override(&self, prompt: &str) -> Option<String>
pub fn model_override(&self, prompt: &str) -> Option<String>
Return the model override for an intent (applied by auto-optimizer), if any.
Sourcepub fn total_cost_usd(&self) -> Result<f64, CostOptimizerError>
pub fn total_cost_usd(&self) -> Result<f64, CostOptimizerError>
Return total cost recorded across all observations.
Sourcepub fn intent_count(&self) -> Result<usize, CostOptimizerError>
pub fn intent_count(&self) -> Result<usize, CostOptimizerError>
Number of distinct intents tracked.
Auto Trait Implementations§
impl !Freeze for CostOptimizer
impl RefUnwindSafe for CostOptimizer
impl Send for CostOptimizer
impl Sync for CostOptimizer
impl Unpin for CostOptimizer
impl UnsafeUnpin for CostOptimizer
impl UnwindSafe for CostOptimizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request