use crate::{Error, Result};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum RerollPolicy {
#[default]
None,
RerollWorstOnce,
}
#[derive(Debug, Clone)]
pub struct GenerateConfig {
pub prompt: String,
pub candidates: u32,
pub seed: u64,
pub reroll: RerollPolicy,
}
impl GenerateConfig {
pub fn new(prompt: impl Into<String>) -> Self {
Self { prompt: prompt.into(), candidates: 4, seed: 0, reroll: RerollPolicy::None }
}
pub fn with_candidates(mut self, n: u32) -> Self {
self.candidates = n;
self
}
pub fn with_seed(mut self, seed: u64) -> Self {
self.seed = seed;
self
}
pub fn with_reroll(mut self, reroll: RerollPolicy) -> Self {
self.reroll = reroll;
self
}
pub(crate) fn validate(&self) -> Result<()> {
if self.prompt.trim().is_empty() {
return Err(Error::Config("prompt must not be empty".into()));
}
if self.candidates == 0 {
return Err(Error::Config("candidates must be >= 1".into()));
}
Ok(())
}
}