use std::fmt;
#[derive(Debug, Clone)]
pub enum RagrigError {
ContextSizeExceeded {
current: usize,
max: usize,
},
}
impl fmt::Display for RagrigError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::ContextSizeExceeded { current, max } => {
write!(
f,
"prompt size {} tokens exceeds model context window of {} tokens",
current, max
)
}
}
}
}
impl std::error::Error for RagrigError {}
impl RagrigError {
pub fn current_size(&self) -> usize {
match self {
Self::ContextSizeExceeded { current, .. } => *current,
}
}
pub fn max_size(&self) -> usize {
match self {
Self::ContextSizeExceeded { max, .. } => *max,
}
}
}