]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
server : add loading html page while model is loading (#9468)
authorXuan Son Nguyen <redacted>
Fri, 13 Sep 2024 12:23:11 +0000 (14:23 +0200)
committerGitHub <redacted>
Fri, 13 Sep 2024 12:23:11 +0000 (14:23 +0200)
* Adding loading page for '/' server requests

* set content when model is loading

* removed loading html file

* updated cmakelist

* updated makefile

* cleaned up whitespace

* cleanup for PR removed error

* updated server test to handle 503 HTML

* updated server test to handle 503 HTML

* ca†ch 503 before parsing json

* revert test

* account for both api and web browser requests

* precommit corrections

* eol fix

* revert changes to pre-commit

* removed print statement

* made loading message more descriptive

* also support .html files

---------

Co-authored-by: VJHack <redacted>
Co-authored-by: Vinesh Janarthanan <redacted>
Makefile
examples/server/CMakeLists.txt
examples/server/public/loading.html [new file with mode: 0644]
examples/server/server.cpp

index 8d3fd3ee83f61b2a95a376fc6650d6cd586dd6ba..f41887a4d3d8c5247329a59f505b719ee7f59518 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1440,6 +1440,7 @@ llama-server: \
        examples/server/system-prompts.js.hpp \
        examples/server/prompt-formats.js.hpp \
        examples/server/json-schema-to-grammar.mjs.hpp \
+       examples/server/loading.html.hpp \
        common/json.hpp \
        common/stb_image.h \
        $(OBJ_ALL)
index dbe41f1fd112055eae0cd356767c1b46ef785cf7..580f3a8248cf5715cd761ac9d642be81d97a1c64 100644 (file)
@@ -30,6 +30,7 @@ set(PUBLIC_ASSETS
     system-prompts.js
     prompt-formats.js
     json-schema-to-grammar.mjs
+    loading.html
 )
 
 foreach(asset ${PUBLIC_ASSETS})
diff --git a/examples/server/public/loading.html b/examples/server/public/loading.html
new file mode 100644 (file)
index 0000000..c3fd19a
--- /dev/null
@@ -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>
index 5e4dffadf39c5ca7faff0f456bbefa46fe019e88..73cd6aae75e97c14da30d74d097528994dcae75a 100644 (file)
@@ -28,6 +28,7 @@
 #include "system-prompts.js.hpp"
 #include "prompt-formats.js.hpp"
 #include "json-schema-to-grammar.mjs.hpp"
+#include "loading.html.hpp"
 
 #include <atomic>
 #include <chrono>
@@ -2592,10 +2593,16 @@ 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));
+            auto tmp = string_split(req.path, '.');
+            if (req.path == "/" || tmp.back() == "html") {
+                res.set_content(reinterpret_cast<const char*>(loading_html), loading_html_len, "text/html; charset=utf-8");
+                res.status = 503;
+            } else {
+                res_error(res, format_error_response("Loading model", ERROR_TYPE_UNAVAILABLE));
+            }
             return false;
         }
         return true;