use crate::tokenizer::PromptTemplate;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum LengthKind {
Text { added: usize },
Pair { added: usize },
Prompt {
template: PromptTemplate,
prefix: usize,
suffix: usize,
},
Windowed { query_cap: usize },
QueryCap { added: usize },
}
pub(super) fn message(requested: &usize, minimum: &usize, kind: &LengthKind) -> String {
let below = format!("{requested} is below the minimum {minimum}");
match kind {
LengthKind::Text { added } => format!(
"max_length {below} for this tokenizer: its post-processor adds {added} special tokens to every text, and one real token has to fit beside them"
),
LengthKind::Pair { added } => format!(
"max_length {below} for a (query, document) pair with this tokenizer: its post-processor adds {added} special tokens to every pair, and one real token has to fit beside them"
),
LengthKind::Prompt {
template,
prefix,
suffix,
} => format!(
"max_length {below} for the {} prompt template with this tokenizer: its fixed prefix is {prefix} tokens and its suffix {suffix}, and one content token has to fit between them",
template.name()
),
LengthKind::Windowed { query_cap } => format!(
"max_length {below} for a windowed input with query cap {query_cap}: it needs twice the cap, which the reference's own rerank asserts, and room for a document token beside the capped query and two separators"
),
LengthKind::QueryCap { added } => format!(
"query cap {below} for a windowed input with this tokenizer: its post-processor adds {added} special tokens to a query, and one real token has to fit beside them"
),
}
}