File tree Expand file tree Collapse file tree 1 file changed +22
-14
lines changed Expand file tree Collapse file tree 1 file changed +22
-14
lines changed Original file line number Diff line number Diff line change @@ -123,20 +123,26 @@ fn validation_worker(
123
123
}
124
124
125
125
// Get the number of tokens in the input
126
- let inputs = tokenizer. encode ( request. inputs . clone ( ) , false ) . unwrap ( ) ;
127
- let input_length = inputs. len ( ) ;
128
-
129
- if input_length > max_input_length {
130
- response_tx
131
- . send ( Err ( ValidationError :: InputLength (
132
- input_length,
133
- max_input_length,
134
- ) ) )
135
- . unwrap_or ( ( ) ) ;
136
- continue ;
137
- }
138
-
139
- response_tx. send ( Ok ( ( input_length, request) ) ) . unwrap_or ( ( ) ) ;
126
+ match tokenizer. encode ( request. inputs . clone ( ) , false ) {
127
+ Ok ( inputs) => {
128
+ let input_length = inputs. len ( ) ;
129
+
130
+ if input_length > max_input_length {
131
+ response_tx
132
+ . send ( Err ( ValidationError :: InputLength (
133
+ input_length,
134
+ max_input_length,
135
+ ) ) )
136
+ . unwrap_or ( ( ) ) ;
137
+ continue ;
138
+ }
139
+
140
+ response_tx. send ( Ok ( ( input_length, request) ) ) . unwrap_or ( ( ) ) ;
141
+ }
142
+ Err ( err) => response_tx
143
+ . send ( Err ( ValidationError :: Tokenizer ( err. to_string ( ) ) ) )
144
+ . unwrap_or ( ( ) ) ,
145
+ } ;
140
146
}
141
147
}
142
148
@@ -157,6 +163,8 @@ pub enum ValidationError {
157
163
MaxNewTokens ,
158
164
#[ error( "inputs must have less than {1} tokens. Given: {0}" ) ]
159
165
InputLength ( usize , usize ) ,
166
+ #[ error( "tokenizer error {0}" ) ]
167
+ Tokenizer ( String ) ,
160
168
}
161
169
162
170
impl From < ValidationError > for ( StatusCode , Json < ErrorResponse > ) {
You can’t perform that action at this time.
0 commit comments