pub struct PromptOptimizer {
pub variants: Vec<PromptVariant>,
pub strategy: OptimizationStrategy,
pub total_trials: u64,
/* private fields */
}Expand description
Tracks prompt variants and selects the best using bandit algorithms.
Fields§
§variants: Vec<PromptVariant>All registered variants.
strategy: OptimizationStrategySelection strategy.
total_trials: u64Total number of selection trials performed.
Implementations§
Source§impl PromptOptimizer
impl PromptOptimizer
Sourcepub fn new(strategy: OptimizationStrategy) -> Self
pub fn new(strategy: OptimizationStrategy) -> Self
Create a new optimizer with the given strategy.
Sourcepub fn add_variant(&mut self, template: &str) -> String
pub fn add_variant(&mut self, template: &str) -> String
Add a variant and return its generated ID.
Sourcepub fn select(&mut self, rng_seed: u64) -> Option<&PromptVariant>
pub fn select(&mut self, rng_seed: u64) -> Option<&PromptVariant>
Select the next variant to evaluate using the configured strategy.
rng_seed is used for stochastic strategies (EpsilonGreedy, ThompsonSampling).
Returns None if no variants are registered.
Sourcepub fn record_feedback(
&mut self,
variant_id: &str,
score: f64,
cost: f64,
tokens_out: u64,
)
pub fn record_feedback( &mut self, variant_id: &str, score: f64, cost: f64, tokens_out: u64, )
Record feedback for a variant after evaluation.
Sourcepub fn best_variant(&self) -> Option<&PromptVariant>
pub fn best_variant(&self) -> Option<&PromptVariant>
Return the variant with the highest performance score.
Sourcepub fn convergence_ratio(&self) -> f64
pub fn convergence_ratio(&self) -> f64
Convergence ratio: best_score / 1.0 (max possible).
Auto Trait Implementations§
impl Freeze for PromptOptimizer
impl RefUnwindSafe for PromptOptimizer
impl Send for PromptOptimizer
impl Sync for PromptOptimizer
impl Unpin for PromptOptimizer
impl UnsafeUnpin for PromptOptimizer
impl UnwindSafe for PromptOptimizer
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