fix(router): Handle tokenizer errors
This commit is contained in:
parent
feb7806ca4
commit
d6d5b12e03
|
@ -123,20 +123,26 @@ fn validation_worker(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the number of tokens in the input
|
// Get the number of tokens in the input
|
||||||
let inputs = tokenizer.encode(request.inputs.clone(), false).unwrap();
|
match tokenizer.encode(request.inputs.clone(), false) {
|
||||||
let input_length = inputs.len();
|
Ok(inputs) => {
|
||||||
|
let input_length = inputs.len();
|
||||||
|
|
||||||
if input_length > max_input_length {
|
if input_length > max_input_length {
|
||||||
response_tx
|
response_tx
|
||||||
.send(Err(ValidationError::InputLength(
|
.send(Err(ValidationError::InputLength(
|
||||||
input_length,
|
input_length,
|
||||||
max_input_length,
|
max_input_length,
|
||||||
)))
|
)))
|
||||||
.unwrap_or(());
|
.unwrap_or(());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
response_tx.send(Ok((input_length, request))).unwrap_or(());
|
response_tx.send(Ok((input_length, request))).unwrap_or(());
|
||||||
|
}
|
||||||
|
Err(err) => response_tx
|
||||||
|
.send(Err(ValidationError::Tokenizer(err.to_string())))
|
||||||
|
.unwrap_or(()),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,6 +163,8 @@ pub enum ValidationError {
|
||||||
MaxNewTokens,
|
MaxNewTokens,
|
||||||
#[error("inputs must have less than {1} tokens. Given: {0}")]
|
#[error("inputs must have less than {1} tokens. Given: {0}")]
|
||||||
InputLength(usize, usize),
|
InputLength(usize, usize),
|
||||||
|
#[error("tokenizer error {0}")]
|
||||||
|
Tokenizer(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ValidationError> for (StatusCode, Json<ErrorResponse>) {
|
impl From<ValidationError> for (StatusCode, Json<ErrorResponse>) {
|
||||||
|
|
Loading…
Reference in New Issue