From dab4b49f04d1a176fe4510592455fb5424166b56 Mon Sep 17 00:00:00 2001 From: VJHack Date: Tue, 10 Sep 2024 22:20:11 -0500 Subject: [PATCH] set content when model is loading --- examples/server/server.cpp | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/examples/server/server.cpp b/examples/server/server.cpp index e10f8fed5..0b17dd715 100644 --- a/examples/server/server.cpp +++ b/examples/server/server.cpp @@ -2476,7 +2476,6 @@ int main(int argc, char ** argv) { #endif std::atomic state{SERVER_STATE_LOADING_MODEL}; - svr->set_default_headers({{"Server", "llama.cpp"}}); // CORS preflight @@ -2592,22 +2591,11 @@ int main(int argc, char ** argv) { return false; }; - auto middleware_server_state = [&res_error, &state](const httplib::Request & req, httplib::Response & res) { + auto middleware_server_state = [&res_error, &state](const httplib::Request &, httplib::Response & res) { server_state current_state = state.load(); if (current_state == SERVER_STATE_LOADING_MODEL) { - httplib::Request & modified_req = (httplib::Request &) req; - const char* path_c = modified_req.path.c_str(); - int path_c_len = strlen(path_c); - char last_five[6]; - strcpy(last_five, path_c + (path_c_len -5)); - - if ((strcmp(path_c, "/") == 0) || (strcmp(last_five, ".html") == 0)) { - modified_req.path = "/loading.html"; - } - else { - res_error(res, format_error_response("Loading model", ERROR_TYPE_UNAVAILABLE)); - return false; - } + res.set_content("The model is loading. Please wait.
The user interface will appear soon.", "text/html; charset=utf-8"); + return false; } return true; };