diff --git a/Makefile b/Makefile
index 97ef37c0e..ae2e17c15 100644
--- a/Makefile
+++ b/Makefile
@@ -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 \
diff --git a/examples/server/CMakeLists.txt b/examples/server/CMakeLists.txt
index dbe41f1fd..b62f813c8 100644
--- a/examples/server/CMakeLists.txt
+++ b/examples/server/CMakeLists.txt
@@ -25,6 +25,7 @@ set(PUBLIC_ASSETS
theme-snowstorm.css
index.html
index-new.html
+ loading.html
index.js
completion.js
system-prompts.js
diff --git a/examples/server/public/loading.html b/examples/server/public/loading.html
new file mode 100644
index 000000000..5e0a837a6
--- /dev/null
+++ b/examples/server/public/loading.html
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+ The model is loading. Please wait.
+ The user interface will appear soon.
+
+
+
\ No newline at end of file
diff --git a/examples/server/server.cpp b/examples/server/server.cpp
index 7495821f9..e10f8fed5 100644
--- a/examples/server/server.cpp
+++ b/examples/server/server.cpp
@@ -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"));