Skip to content

Commit d4b9ec0

Browse files
committed
handle empty input case
1 parent 9a56680 commit d4b9ec0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

examples/server/server.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3664,12 +3664,20 @@ int main(int argc, char ** argv) {
36643664
return;
36653665
}
36663666

3667+
std::vector<llama_tokens> tokenized_prompts = tokenize_input_prompts(ctx_server.ctx, prompt, true, true);
3668+
for (const auto & tokens : tokenized_prompts) {
3669+
// this check is necessary for models that do not add BOS token to the input
3670+
if (tokens.empty()) {
3671+
res_error(res, format_error_response("Input content cannot be empty", ERROR_TYPE_INVALID_REQUEST));
3672+
return;
3673+
}
3674+
}
3675+
36673676
// create and queue the task
36683677
json responses = json::array();
36693678
bool error = false;
36703679
{
36713680
std::vector<server_task> tasks;
3672-
std::vector<llama_tokens> tokenized_prompts = tokenize_input_prompts(ctx_server.ctx, prompt, /* add_special */ false, true);
36733681
for (size_t i = 0; i < tokenized_prompts.size(); i++) {
36743682
server_task task = server_task(SERVER_TASK_TYPE_EMBEDDING);
36753683
task.id = ctx_server.queue_tasks.get_new_id();

0 commit comments

Comments
 (0)