-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
62 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug, PartialEq)] | ||
pub enum Error { | ||
#[error("The vocabulary does not allow us to build a sequence that matches the input")] | ||
IndexError, | ||
#[error("Unable to create tokenizer for {model}")] | ||
UnableToCreateTokenizer { model: String }, | ||
#[error("Unable to locate EOS token for {model}")] | ||
UnableToLocateEosTokenId { model: String }, | ||
#[error("Tokenizer is not supported by token processor")] | ||
UnsupportedByTokenProcessor, | ||
#[error("Decoder unpacking failed for token processor")] | ||
DecoderUnpackingFailed, | ||
#[error("Token processing failed for byte level processor")] | ||
ByteProcessorFailed, | ||
#[error("Token processing failed for byte fallback level processor")] | ||
ByteFallbackProcessorFailed, | ||
} | ||
|
||
#[cfg(feature = "python-bindings")] | ||
impl From<Error> for pyo3::PyErr { | ||
fn from(e: Error) -> Self { | ||
use pyo3::{exceptions::PyValueError, PyErr}; | ||
PyErr::new::<PyValueError, _>(e.to_string()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,14 @@ | ||
pub mod error; | ||
pub mod index; | ||
pub mod json_schema; | ||
pub mod prelude; | ||
pub mod primitives; | ||
pub mod regex; | ||
pub mod vocabulary; | ||
|
||
#[cfg(feature = "python-bindings")] | ||
mod python_bindings; | ||
|
||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug, PartialEq)] | ||
pub enum Error { | ||
#[error("The vocabulary does not allow us to build a sequence that matches the input")] | ||
IndexError, | ||
} | ||
use error::Error; | ||
|
||
#[derive(Error, Debug)] | ||
#[error("Tokenizer error")] | ||
pub struct TokenizerError(tokenizers::Error); | ||
|
||
impl PartialEq for TokenizerError { | ||
fn eq(&self, other: &Self) -> bool { | ||
self.0.to_string() == other.0.to_string() | ||
} | ||
} | ||
|
||
#[derive(Error, Debug, PartialEq)] | ||
pub enum VocabularyError { | ||
#[error("Unable to create tokenizer for {model}, source {source}")] | ||
UnableToCreateTokenizer { | ||
model: String, | ||
source: TokenizerError, | ||
}, | ||
#[error("Unable to locate EOS token for {model}")] | ||
UnableToLocateEosTokenId { model: String }, | ||
#[error("Unable to process token")] | ||
TokenProcessorError(#[from] TokenProcessorError), | ||
} | ||
|
||
#[derive(Error, Debug, PartialEq)] | ||
pub enum TokenProcessorError { | ||
#[error("Tokenizer is not supported")] | ||
UnsupportedTokenizer, | ||
#[error("Decoder unpacking failed")] | ||
DecoderUnpackingFailed, | ||
#[error("Token processing failed for byte level processor")] | ||
ByteProcessorFailed, | ||
#[error("Token processing failed for byte fallback level processor")] | ||
ByteFallbackProcessorFailed, | ||
} | ||
pub type Result<T, E = Error> = std::result::Result<T, E>; | ||
|
||
#[cfg(feature = "python-bindings")] | ||
impl From<Error> for pyo3::PyErr { | ||
fn from(e: Error) -> Self { | ||
use pyo3::{exceptions::PyValueError, PyErr}; | ||
PyErr::new::<PyValueError, _>(e.to_string()) | ||
} | ||
} | ||
mod python_bindings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters