@@ -4431,7 +4431,7 @@ static void log_server_request(const httplib::Request & req, const httplib::Resp
44314431 SRV_DBG (" response: %s\n " , res.body .c_str ());
44324432}
44334433
4434- static void res_error (httplib::Response & res, const json & error_data) {
4434+ static void res_err (httplib::Response & res, const json & error_data) {
44354435 json final_response {{" error" , error_data}};
44364436 res.set_content (safe_json_to_str (final_response), MIMETYPE_JSON);
44374437 res.status = json_value (error_data, " code" , 500 );
@@ -4524,17 +4524,17 @@ int main(int argc, char ** argv) {
45244524 try {
45254525 json formatted_error = format_error_response (message, ERROR_TYPE_SERVER);
45264526 LOG_WRN (" got exception: %s\n " , formatted_error.dump ().c_str ());
4527- res_error (res, formatted_error);
4527+ res_err (res, formatted_error);
45284528 } catch (const std::exception & e) {
45294529 LOG_ERR (" got another exception: %s | while hanlding exception: %s\n " , e.what (), message.c_str ());
45304530 }
45314531 });
45324532
45334533 svr->set_error_handler ([](const httplib::Request &, httplib::Response & res) {
45344534 if (res.status == 404 ) {
4535- res_error (res, format_error_response (" File Not Found" , ERROR_TYPE_NOT_FOUND));
4535+ res_err (res, format_error_response (" File Not Found" , ERROR_TYPE_NOT_FOUND));
45364536 }
4537- // for other error codes, we skip processing here because it's already done by res_error ()
4537+ // for other error codes, we skip processing here because it's already done by res_err ()
45384538 });
45394539
45404540 // set timeouts and change hostname and port
@@ -4591,7 +4591,7 @@ int main(int argc, char ** argv) {
45914591 }
45924592
45934593 // API key is invalid or not provided
4594- res_error (res, format_error_response (" Invalid API Key" , ERROR_TYPE_AUTHENTICATION));
4594+ res_err (res, format_error_response (" Invalid API Key" , ERROR_TYPE_AUTHENTICATION));
45954595
45964596 LOG_WRN (" Unauthorized: Invalid API Key\n " );
45974597
@@ -4609,7 +4609,7 @@ int main(int argc, char ** argv) {
46094609 // allow the models endpoint to be accessed during loading
46104610 return true ;
46114611 } else {
4612- res_error (res, format_error_response (" Loading model" , ERROR_TYPE_UNAVAILABLE));
4612+ res_err (res, format_error_response (" Loading model" , ERROR_TYPE_UNAVAILABLE));
46134613 }
46144614 return false ;
46154615 }
@@ -4648,7 +4648,7 @@ int main(int argc, char ** argv) {
46484648
46494649 const auto handle_slots = [&](const httplib::Request & req, httplib::Response & res) {
46504650 if (!params.endpoint_slots ) {
4651- res_error (res, format_error_response (" This server does not support slots endpoint. Start it with `--slots`" , ERROR_TYPE_NOT_SUPPORTED));
4651+ res_err (res, format_error_response (" This server does not support slots endpoint. Start it with `--slots`" , ERROR_TYPE_NOT_SUPPORTED));
46524652 return ;
46534653 }
46544654
@@ -4666,7 +4666,7 @@ int main(int argc, char ** argv) {
46664666 ctx_server.queue_results .remove_waiting_task_id (task_id);
46674667
46684668 if (result->is_error ()) {
4669- res_error (res, result->to_json ());
4669+ res_err (res, result->to_json ());
46704670 return ;
46714671 }
46724672
@@ -4677,7 +4677,7 @@ int main(int argc, char ** argv) {
46774677 // optionally return "fail_on_no_slot" error
46784678 if (req.has_param (" fail_on_no_slot" )) {
46794679 if (res_task->n_idle_slots == 0 ) {
4680- res_error (res, format_error_response (" no slot available" , ERROR_TYPE_UNAVAILABLE));
4680+ res_err (res, format_error_response (" no slot available" , ERROR_TYPE_UNAVAILABLE));
46814681 return ;
46824682 }
46834683 }
@@ -4687,7 +4687,7 @@ int main(int argc, char ** argv) {
46874687
46884688 const auto handle_metrics = [&](const httplib::Request &, httplib::Response & res) {
46894689 if (!params.endpoint_metrics ) {
4690- res_error (res, format_error_response (" This server does not support metrics endpoint. Start it with `--metrics`" , ERROR_TYPE_NOT_SUPPORTED));
4690+ res_err (res, format_error_response (" This server does not support metrics endpoint. Start it with `--metrics`" , ERROR_TYPE_NOT_SUPPORTED));
46914691 return ;
46924692 }
46934693
@@ -4705,7 +4705,7 @@ int main(int argc, char ** argv) {
47054705 ctx_server.queue_results .remove_waiting_task_id (task_id);
47064706
47074707 if (result->is_error ()) {
4708- res_error (res, result->to_json ());
4708+ res_err (res, result->to_json ());
47094709 return ;
47104710 }
47114711
@@ -4790,7 +4790,7 @@ int main(int argc, char ** argv) {
47904790 json request_data = json::parse (req.body );
47914791 std::string filename = request_data.at (" filename" );
47924792 if (!fs_validate_filename (filename)) {
4793- res_error (res, format_error_response (" Invalid filename" , ERROR_TYPE_INVALID_REQUEST));
4793+ res_err (res, format_error_response (" Invalid filename" , ERROR_TYPE_INVALID_REQUEST));
47944794 return ;
47954795 }
47964796 std::string filepath = params.slot_save_path + filename;
@@ -4811,7 +4811,7 @@ int main(int argc, char ** argv) {
48114811 ctx_server.queue_results .remove_waiting_task_id (task_id);
48124812
48134813 if (result->is_error ()) {
4814- res_error (res, result->to_json ());
4814+ res_err (res, result->to_json ());
48154815 return ;
48164816 }
48174817
@@ -4822,7 +4822,7 @@ int main(int argc, char ** argv) {
48224822 json request_data = json::parse (req.body );
48234823 std::string filename = request_data.at (" filename" );
48244824 if (!fs_validate_filename (filename)) {
4825- res_error (res, format_error_response (" Invalid filename" , ERROR_TYPE_INVALID_REQUEST));
4825+ res_err (res, format_error_response (" Invalid filename" , ERROR_TYPE_INVALID_REQUEST));
48264826 return ;
48274827 }
48284828 std::string filepath = params.slot_save_path + filename;
@@ -4843,7 +4843,7 @@ int main(int argc, char ** argv) {
48434843 ctx_server.queue_results .remove_waiting_task_id (task_id);
48444844
48454845 if (result->is_error ()) {
4846- res_error (res, result->to_json ());
4846+ res_err (res, result->to_json ());
48474847 return ;
48484848 }
48494849
@@ -4866,7 +4866,7 @@ int main(int argc, char ** argv) {
48664866 ctx_server.queue_results .remove_waiting_task_id (task_id);
48674867
48684868 if (result->is_error ()) {
4869- res_error (res, result->to_json ());
4869+ res_err (res, result->to_json ());
48704870 return ;
48714871 }
48724872
@@ -4876,7 +4876,7 @@ int main(int argc, char ** argv) {
48764876
48774877 const auto handle_slots_action = [¶ms, &handle_slots_save, &handle_slots_restore, &handle_slots_erase](const httplib::Request & req, httplib::Response & res) {
48784878 if (params.slot_save_path .empty ()) {
4879- res_error (res, format_error_response (" This server does not support slots action. Start it with `--slot-save-path`" , ERROR_TYPE_NOT_SUPPORTED));
4879+ res_err (res, format_error_response (" This server does not support slots action. Start it with `--slot-save-path`" , ERROR_TYPE_NOT_SUPPORTED));
48804880 return ;
48814881 }
48824882
@@ -4886,7 +4886,7 @@ int main(int argc, char ** argv) {
48864886 try {
48874887 id_slot = std::stoi (id_slot_str);
48884888 } catch (const std::exception &) {
4889- res_error (res, format_error_response (" Invalid slot ID" , ERROR_TYPE_INVALID_REQUEST));
4889+ res_err (res, format_error_response (" Invalid slot ID" , ERROR_TYPE_INVALID_REQUEST));
48904890 return ;
48914891 }
48924892
@@ -4899,7 +4899,7 @@ int main(int argc, char ** argv) {
48994899 } else if (action == " erase" ) {
49004900 handle_slots_erase (req, res, id_slot);
49014901 } else {
4902- res_error (res, format_error_response (" Invalid action" , ERROR_TYPE_INVALID_REQUEST));
4902+ res_err (res, format_error_response (" Invalid action" , ERROR_TYPE_INVALID_REQUEST));
49034903 }
49044904 };
49054905
@@ -4947,7 +4947,7 @@ int main(int argc, char ** argv) {
49474947
49484948 const auto handle_props_change = [&ctx_server](const httplib::Request & req, httplib::Response & res) {
49494949 if (!ctx_server.params_base .endpoint_props ) {
4950- res_error (res, format_error_response (" This server does not support changing global properties. Start it with `--props`" , ERROR_TYPE_NOT_SUPPORTED));
4950+ res_err (res, format_error_response (" This server does not support changing global properties. Start it with `--props`" , ERROR_TYPE_NOT_SUPPORTED));
49514951 return ;
49524952 }
49534953
@@ -5044,7 +5044,7 @@ int main(int argc, char ** argv) {
50445044
50455045 rd->post_tasks (std::move (tasks));
50465046 } catch (const std::exception & e) {
5047- res_error (res, format_error_response (e.what (), ERROR_TYPE_INVALID_REQUEST));
5047+ res_err (res, format_error_response (e.what (), ERROR_TYPE_INVALID_REQUEST));
50485048 return ;
50495049 }
50505050
@@ -5056,7 +5056,7 @@ int main(int argc, char ** argv) {
50565056 if (all_results.is_terminated ) {
50575057 return ; // connection is closed
50585058 } else if (all_results.error ) {
5059- res_error (res, all_results.error ->to_json ());
5059+ res_err (res, all_results.error ->to_json ());
50605060 return ;
50615061 } else {
50625062 json arr = json::array ();
@@ -5076,7 +5076,7 @@ int main(int argc, char ** argv) {
50765076 if (first_result == nullptr ) {
50775077 return ; // connection is closed
50785078 } else if (first_result->is_error ()) {
5079- res_error (res, first_result->to_json ());
5079+ res_err (res, first_result->to_json ());
50805080 return ;
50815081 } else {
50825082 GGML_ASSERT (
@@ -5183,7 +5183,7 @@ int main(int argc, char ** argv) {
51835183 err += " middle token is missing. " ;
51845184 }
51855185 if (!err.empty ()) {
5186- res_error (res, format_error_response (string_format (" Infill is not supported by this model: %s" , err.c_str ()), ERROR_TYPE_NOT_SUPPORTED));
5186+ res_err (res, format_error_response (string_format (" Infill is not supported by this model: %s" , err.c_str ()), ERROR_TYPE_NOT_SUPPORTED));
51875187 return ;
51885188 }
51895189
@@ -5192,33 +5192,33 @@ int main(int argc, char ** argv) {
51925192 // validate input
51935193 if (data.contains (" prompt" ) && !data.at (" prompt" ).is_string ()) {
51945194 // prompt is optional
5195- res_error (res, format_error_response (" \" prompt\" must be a string" , ERROR_TYPE_INVALID_REQUEST));
5195+ res_err (res, format_error_response (" \" prompt\" must be a string" , ERROR_TYPE_INVALID_REQUEST));
51965196 }
51975197
51985198 if (!data.contains (" input_prefix" )) {
5199- res_error (res, format_error_response (" \" input_prefix\" is required" , ERROR_TYPE_INVALID_REQUEST));
5199+ res_err (res, format_error_response (" \" input_prefix\" is required" , ERROR_TYPE_INVALID_REQUEST));
52005200 }
52015201
52025202 if (!data.contains (" input_suffix" )) {
5203- res_error (res, format_error_response (" \" input_suffix\" is required" , ERROR_TYPE_INVALID_REQUEST));
5203+ res_err (res, format_error_response (" \" input_suffix\" is required" , ERROR_TYPE_INVALID_REQUEST));
52045204 }
52055205
52065206 if (data.contains (" input_extra" ) && !data.at (" input_extra" ).is_array ()) {
52075207 // input_extra is optional
5208- res_error (res, format_error_response (" \" input_extra\" must be an array of {\" filename\" : string, \" text\" : string}" , ERROR_TYPE_INVALID_REQUEST));
5208+ res_err (res, format_error_response (" \" input_extra\" must be an array of {\" filename\" : string, \" text\" : string}" , ERROR_TYPE_INVALID_REQUEST));
52095209 return ;
52105210 }
52115211
52125212 json input_extra = json_value (data, " input_extra" , json::array ());
52135213 for (const auto & chunk : input_extra) {
52145214 // { "text": string, "filename": string }
52155215 if (!chunk.contains (" text" ) || !chunk.at (" text" ).is_string ()) {
5216- res_error (res, format_error_response (" extra_context chunk must contain a \" text\" field with a string value" , ERROR_TYPE_INVALID_REQUEST));
5216+ res_err (res, format_error_response (" extra_context chunk must contain a \" text\" field with a string value" , ERROR_TYPE_INVALID_REQUEST));
52175217 return ;
52185218 }
52195219 // filename is optional
52205220 if (chunk.contains (" filename" ) && !chunk.at (" filename" ).is_string ()) {
5221- res_error (res, format_error_response (" extra_context chunk's \" filename\" field must be a string" , ERROR_TYPE_INVALID_REQUEST));
5221+ res_err (res, format_error_response (" extra_context chunk's \" filename\" field must be a string" , ERROR_TYPE_INVALID_REQUEST));
52225222 return ;
52235223 }
52245224 }
@@ -5380,12 +5380,12 @@ int main(int argc, char ** argv) {
53805380
53815381 const auto handle_embeddings_impl = [&ctx_server](const httplib::Request & req, httplib::Response & res, oaicompat_type oaicompat) {
53825382 if (!ctx_server.params_base .embedding ) {
5383- res_error (res, format_error_response (" This server does not support embeddings. Start it with `--embeddings`" , ERROR_TYPE_NOT_SUPPORTED));
5383+ res_err (res, format_error_response (" This server does not support embeddings. Start it with `--embeddings`" , ERROR_TYPE_NOT_SUPPORTED));
53845384 return ;
53855385 }
53865386
53875387 if (oaicompat != OAICOMPAT_TYPE_NONE && llama_pooling_type (ctx_server.ctx ) == LLAMA_POOLING_TYPE_NONE) {
5388- res_error (res, format_error_response (" Pooling type 'none' is not OAI compatible. Please use a different pooling type" , ERROR_TYPE_INVALID_REQUEST));
5388+ res_err (res, format_error_response (" Pooling type 'none' is not OAI compatible. Please use a different pooling type" , ERROR_TYPE_INVALID_REQUEST));
53895389 return ;
53905390 }
53915391
@@ -5399,7 +5399,7 @@ int main(int argc, char ** argv) {
53995399 oaicompat = OAICOMPAT_TYPE_NONE; // "content" field is not OAI compatible
54005400 prompt = body.at (" content" );
54015401 } else {
5402- res_error (res, format_error_response (" \" input\" or \" content\" must be provided" , ERROR_TYPE_INVALID_REQUEST));
5402+ res_err (res, format_error_response (" \" input\" or \" content\" must be provided" , ERROR_TYPE_INVALID_REQUEST));
54035403 return ;
54045404 }
54055405
@@ -5409,7 +5409,7 @@ int main(int argc, char ** argv) {
54095409 if (format == " base64" ) {
54105410 use_base64 = true ;
54115411 } else if (format != " float" ) {
5412- res_error (res, format_error_response (" The format to return the embeddings in. Can be either float or base64" , ERROR_TYPE_INVALID_REQUEST));
5412+ res_err (res, format_error_response (" The format to return the embeddings in. Can be either float or base64" , ERROR_TYPE_INVALID_REQUEST));
54135413 return ;
54145414 }
54155415 }
@@ -5418,7 +5418,7 @@ int main(int argc, char ** argv) {
54185418 for (const auto & tokens : tokenized_prompts) {
54195419 // this check is necessary for models that do not add BOS token to the input
54205420 if (tokens.empty ()) {
5421- res_error (res, format_error_response (" Input content cannot be empty" , ERROR_TYPE_INVALID_REQUEST));
5421+ res_err (res, format_error_response (" Input content cannot be empty" , ERROR_TYPE_INVALID_REQUEST));
54225422 return ;
54235423 }
54245424 }
@@ -5459,7 +5459,7 @@ int main(int argc, char ** argv) {
54595459 if (all_results.is_terminated ) {
54605460 return ; // connection is closed
54615461 } else if (all_results.error ) {
5462- res_error (res, all_results.error ->to_json ());
5462+ res_err (res, all_results.error ->to_json ());
54635463 return ;
54645464 } else {
54655465 for (auto & res : all_results.results ) {
@@ -5485,7 +5485,7 @@ int main(int argc, char ** argv) {
54855485
54865486 const auto handle_rerank = [&ctx_server](const httplib::Request & req, httplib::Response & res) {
54875487 if (!ctx_server.params_base .embedding || ctx_server.params_base .pooling_type != LLAMA_POOLING_TYPE_RANK) {
5488- res_error (res, format_error_response (" This server does not support reranking. Start it with `--reranking`" , ERROR_TYPE_NOT_SUPPORTED));
5488+ res_err (res, format_error_response (" This server does not support reranking. Start it with `--reranking`" , ERROR_TYPE_NOT_SUPPORTED));
54895489 return ;
54905490 }
54915491
@@ -5500,18 +5500,18 @@ int main(int argc, char ** argv) {
55005500 if (body.count (" query" ) == 1 ) {
55015501 query = body.at (" query" );
55025502 if (!query.is_string ()) {
5503- res_error (res, format_error_response (" \" query\" must be a string" , ERROR_TYPE_INVALID_REQUEST));
5503+ res_err (res, format_error_response (" \" query\" must be a string" , ERROR_TYPE_INVALID_REQUEST));
55045504 return ;
55055505 }
55065506 } else {
5507- res_error (res, format_error_response (" \" query\" must be provided" , ERROR_TYPE_INVALID_REQUEST));
5507+ res_err (res, format_error_response (" \" query\" must be provided" , ERROR_TYPE_INVALID_REQUEST));
55085508 return ;
55095509 }
55105510
55115511 std::vector<std::string> documents = json_value (body, " documents" ,
55125512 json_value (body, " texts" , std::vector<std::string>()));
55135513 if (documents.empty ()) {
5514- res_error (res, format_error_response (" \" documents\" must be a non-empty string array" , ERROR_TYPE_INVALID_REQUEST));
5514+ res_err (res, format_error_response (" \" documents\" must be a non-empty string array" , ERROR_TYPE_INVALID_REQUEST));
55155515 return ;
55165516 }
55175517
@@ -5541,7 +5541,7 @@ int main(int argc, char ** argv) {
55415541 if (all_results.is_terminated ) {
55425542 return ; // connection is closed
55435543 } else if (all_results.error ) {
5544- res_error (res, all_results.error ->to_json ());
5544+ res_err (res, all_results.error ->to_json ());
55455545 return ;
55465546 } else {
55475547 for (auto & res : all_results.results ) {
@@ -5594,7 +5594,7 @@ int main(int argc, char ** argv) {
55945594 const auto handle_lora_adapters_apply = [&](const httplib::Request & req, httplib::Response & res) {
55955595 const json body = json::parse (req.body );
55965596 if (!body.is_array ()) {
5597- res_error (res, format_error_response (" Request body must be an array" , ERROR_TYPE_INVALID_REQUEST));
5597+ res_err (res, format_error_response (" Request body must be an array" , ERROR_TYPE_INVALID_REQUEST));
55985598 return ;
55995599 }
56005600
@@ -5612,7 +5612,7 @@ int main(int argc, char ** argv) {
56125612 ctx_server.queue_results .remove_waiting_task_id (task_id);
56135613
56145614 if (result->is_error ()) {
5615- res_error (res, result->to_json ());
5615+ res_err (res, result->to_json ());
56165616 return ;
56175617 }
56185618
0 commit comments