Adding loading page for '/' server requests

This commit is contained in:
VJHack 2024-09-09 22:06:56 -05:00
parent bfe76d4a17
commit dfe31e0484
4 changed files with 30 additions and 3 deletions

View File

@ -1430,6 +1430,7 @@ llama-server: \
examples/server/theme-snowstorm.css.hpp \
examples/server/index.html.hpp \
examples/server/index-new.html.hpp \
examples/server/loading.html.hpp \
examples/server/index.js.hpp \
examples/server/completion.js.hpp \
examples/server/system-prompts.js.hpp \

View File

@ -25,6 +25,7 @@ set(PUBLIC_ASSETS
theme-snowstorm.css
index.html
index-new.html
loading.html
index.js
completion.js
system-prompts.js

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="5">
</head>
<body>
<div id="loading">
The model is loading. Please wait.<br/>
The user interface will appear soon.
</div>
</body>
</html>

View File

@ -23,6 +23,7 @@
#include "theme-snowstorm.css.hpp"
#include "index.html.hpp"
#include "index-new.html.hpp"
#include "loading.html.hpp"
#include "index.js.hpp"
#include "completion.js.hpp"
#include "system-prompts.js.hpp"
@ -2591,11 +2592,22 @@ int main(int argc, char ** argv) {
return false;
};
auto middleware_server_state = [&res_error, &state](const httplib::Request &, httplib::Response & res) {
auto middleware_server_state = [&res_error, &state](const httplib::Request & req, httplib::Response & res) {
server_state current_state = state.load();
if (current_state == SERVER_STATE_LOADING_MODEL) {
res_error(res, format_error_response("Loading model", ERROR_TYPE_UNAVAILABLE));
return false;
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;
}
}
return true;
};
@ -3162,6 +3174,7 @@ int main(int argc, char ** argv) {
svr->Get("/theme-polarnight.css", handle_static_file(theme_polarnight_css, theme_polarnight_css_len, "text/css; charset=utf-8"));
svr->Get("/theme-snowstorm.css", handle_static_file(theme_snowstorm_css, theme_snowstorm_css_len, "text/css; charset=utf-8"));
svr->Get("/index-new.html", handle_static_file(index_new_html, index_new_html_len, "text/html; charset=utf-8"));
svr->Get("/loading.html", handle_static_file(loading_html, loading_html_len, "text/html; charset=utf-8"));
svr->Get("/system-prompts.js", handle_static_file(system_prompts_js, system_prompts_js_len, "text/javascript; charset=utf-8"));
svr->Get("/prompt-formats.js", handle_static_file(prompt_formats_js, prompt_formats_js_len, "text/javascript; charset=utf-8"));