@@ -3482,6 +3482,11 @@ int main(int argc, char ** argv) {
34823482 json data = json::parse (req.body );
34833483
34843484 // validate input
3485+ if (data.contains (" prompt" ) && !data.at (" prompt" ).is_string ()) {
3486+ // prompt is optional
3487+ res_error (res, format_error_response (" \" prompt\" must be a string" , ERROR_TYPE_INVALID_REQUEST));
3488+ }
3489+
34853490 if (!data.contains (" input_prefix" )) {
34863491 res_error (res, format_error_response (" \" input_prefix\" is required" , ERROR_TYPE_INVALID_REQUEST));
34873492 }
@@ -3491,9 +3496,11 @@ int main(int argc, char ** argv) {
34913496 }
34923497
34933498 if (data.contains (" input_extra" ) && !data.at (" input_extra" ).is_array ()) {
3499+ // input_extra is optional
34943500 res_error (res, format_error_response (" \" input_extra\" must be an array of {\" filename\" : string, \" text\" : string}" , ERROR_TYPE_INVALID_REQUEST));
34953501 return ;
34963502 }
3503+
34973504 json input_extra = json_value (data, " input_extra" , json::array ());
34983505 for (const auto & chunk : input_extra) {
34993506 // { "text": string, "filename": string }
@@ -3509,6 +3516,21 @@ int main(int argc, char ** argv) {
35093516 }
35103517 data[" input_extra" ] = input_extra; // default to empty array if it's not exist
35113518
3519+ std::string prompt = json_value (data, " prompt" , std::string ());
3520+ std::vector<llama_tokens> tokenized_prompts = tokenize_input_prompts (ctx_server.ctx , prompt, true , true );
3521+ SRV_DBG (" creating infill tasks, n_prompts = %d\n " , (int ) tokenized_prompts.size ());
3522+ auto tokens = format_infill (
3523+ ctx_server.ctx ,
3524+ data.at (" input_prefix" ),
3525+ data.at (" input_suffix" ),
3526+ data.at (" input_extra" ),
3527+ ctx_server.params_base .n_batch ,
3528+ ctx_server.params_base .n_predict ,
3529+ ctx_server.slots [0 ].n_ctx , // TODO: there should be a better way
3530+ ctx_server.params_base .spm_infill ,
3531+ tokenized_prompts[0 ]
3532+ );
3533+
35123534 return handle_completions_generic (SERVER_TASK_TYPE_INFILL, data, res);
35133535 };
35143536
0 commit comments