use crate::{sys, Tokenizer};
#[derive(Clone, Debug)]
pub struct GenerationStepResult {
pub step: usize,
pub batch_id: usize,
pub hypothesis_id: usize,
pub text: String,
pub score: Option<f32>,
pub is_last: bool,
}
impl GenerationStepResult {
pub(crate) fn from_ffi<T: Tokenizer>(
r: sys::GenerationStepResult,
tokenizer: &T,
) -> anyhow::Result<Self> {
let text = tokenizer.decode(vec![r.token])?;
Ok(Self {
step: r.step,
batch_id: r.batch_id,
hypothesis_id: r.hypothesis_id,
text,
score: if r.has_score { Some(r.score) } else { None },
is_last: r.is_last,
})
}
}