Skip to main content

eredu_text/
error.rs

1/// Errors produced while constructing tokenizers or rendering chat templates.
2#[derive(Debug, thiserror::Error)]
3pub enum Error {
4    /// Tokenizer metadata is malformed or inconsistent.
5    #[error("invalid tokenizer metadata: {0}")]
6    InvalidTokenizer(String),
7
8    /// Reading tokenizer or template data failed.
9    #[error(transparent)]
10    Io(#[from] std::io::Error),
11
12    /// Chat-template metadata is malformed.
13    #[error("invalid chat_template: {0}")]
14    InvalidChatTemplate(String),
15
16    /// A named template collection has no selectable default.
17    #[error(
18        "chat_template collection has no default template; available templates: {available:?}"
19    )]
20    AmbiguousChatTemplate {
21        /// Names of the templates present in the collection.
22        available: Vec<String>,
23    },
24
25    /// MiniJinja could not compile or render the template.
26    #[error(transparent)]
27    RenderTemplate(#[from] minijinja::Error),
28
29    /// continue_final_message is set but the final message does not appear in the chat after   
30    /// applying the chat template! This can happen if the chat template deletes portions of
31    /// the final message. Please verify the chat template and final message in your chat to
32    /// ensure they are compatible.
33    #[error(
34        "continue_final_message is set but the final message does not appear in the chat after applying the chat template!"
35    )]
36    FinalMsgNotInChat,
37
38    /// The Hugging Face tokenizer could not encode input or be constructed.
39    #[error(transparent)]
40    Encode(#[from] tokenizers::tokenizer::Error),
41
42    /// JSON serialization of template inputs failed.
43    #[error(transparent)]
44    Serialize(#[from] serde_json::Error),
45}