Skip to content

Commit 82d8560

Browse files
vrdn-23alvarobartt
andauthored
Fix error code for empty requests (#727)
Co-authored-by: Alvaro Bartolome <[email protected]>
1 parent d22a2c2 commit 82d8560

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

core/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ pub enum TextEmbeddingsError {
1313
Tokenizer(#[from] tokenizers::Error),
1414
#[error("Input validation error: {0}")]
1515
Validation(String),
16+
#[error("Input validation error: {0}")]
17+
Empty(String),
1618
#[error("Model is overloaded")]
1719
Overloaded(#[from] TryAcquireError),
1820
#[error("Backend error: {0}")]

core/src/tokenization.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Tokenization {
7272
) -> Result<ValidEncoding, TextEmbeddingsError> {
7373
// Check if inputs is empty
7474
if inputs.is_empty() {
75-
return Err(TextEmbeddingsError::Validation(
75+
return Err(TextEmbeddingsError::Empty(
7676
"`inputs` cannot be empty".to_string(),
7777
));
7878
}
@@ -107,7 +107,7 @@ impl Tokenization {
107107
) -> Result<(Option<String>, RawEncoding), TextEmbeddingsError> {
108108
// Check if inputs is empty
109109
if inputs.is_empty() {
110-
return Err(TextEmbeddingsError::Validation(
110+
return Err(TextEmbeddingsError::Empty(
111111
"`inputs` cannot be empty".to_string(),
112112
));
113113
}
@@ -138,9 +138,9 @@ impl Tokenization {
138138
ids: Vec<u32>,
139139
skip_special_tokens: bool,
140140
) -> Result<String, TextEmbeddingsError> {
141-
// Check if inputs is empty
141+
// Check if input_ids is empty
142142
if ids.is_empty() {
143-
return Err(TextEmbeddingsError::Validation(
143+
return Err(TextEmbeddingsError::Empty(
144144
"`input_ids` cannot be empty".to_string(),
145145
));
146146
}

router/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ impl From<TextEmbeddingsError> for ErrorResponse {
552552
let error_type = match err {
553553
TextEmbeddingsError::Tokenizer(_) => ErrorType::Tokenizer,
554554
TextEmbeddingsError::Validation(_) => ErrorType::Validation,
555+
TextEmbeddingsError::Empty(_) => ErrorType::Empty,
555556
TextEmbeddingsError::Overloaded(_) => ErrorType::Overloaded,
556557
TextEmbeddingsError::Backend(_) => ErrorType::Backend,
557558
};

0 commit comments

Comments
 (0)