Skip to content

Commit ff934e2

Browse files
authored
server: Introduce LLAMA_BUILD_WEBUI build flag to allow disabling the embedded web ui (ggml-org#20158)
* introduce LLAMA_SERVER_NO_WEBUI * LLAMA_SERVER_NO_WEBUI → LLAMA_BUILD_WEBUI * LLAMA_BUILD_WEBUI ON by default not based on LLAMA_STANDALONE * MIssed this * Add useWebUi to package.nix
1 parent ee051c1 commit ff934e2

4 files changed

Lines changed: 32 additions & 15 deletions

File tree

.devops/nix/package.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
effectiveStdenv ? if useCuda then cudaPackages.backendStdenv else stdenv,
4242
enableStatic ? effectiveStdenv.hostPlatform.isStatic,
4343
precompileMetalShaders ? false,
44+
useWebUi ? true,
4445
}:
4546

4647
let
@@ -164,6 +165,7 @@ effectiveStdenv.mkDerivation (finalAttrs: {
164165
cmakeFlags =
165166
[
166167
(cmakeBool "LLAMA_BUILD_SERVER" true)
168+
(cmakeBool "LLAMA_BUILD_WEBUI" useWebUi)
167169
(cmakeBool "BUILD_SHARED_LIBS" (!enableStatic))
168170
(cmakeBool "CMAKE_SKIP_BUILD_RPATH" true)
169171
(cmakeBool "GGML_NATIVE" false)

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ option(LLAMA_BUILD_TESTS "llama: build tests" ${LLAMA_STANDALONE})
108108
option(LLAMA_BUILD_TOOLS "llama: build tools" ${LLAMA_STANDALONE})
109109
option(LLAMA_BUILD_EXAMPLES "llama: build examples" ${LLAMA_STANDALONE})
110110
option(LLAMA_BUILD_SERVER "llama: build server example" ${LLAMA_STANDALONE})
111+
option(LLAMA_BUILD_WEBUI "llama: build the embedded Web UI for server" ON)
111112
option(LLAMA_TOOLS_INSTALL "llama: install tools" ${LLAMA_TOOLS_INSTALL_DEFAULT})
112113
option(LLAMA_TESTS_INSTALL "llama: install tests" ON)
113114

tools/server/CMakeLists.txt

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,29 @@ set(TARGET_SRCS
3737
server-models.cpp
3838
server-models.h
3939
)
40-
set(PUBLIC_ASSETS
41-
index.html.gz
42-
loading.html
43-
)
4440

45-
foreach(asset ${PUBLIC_ASSETS})
46-
set(input "${CMAKE_CURRENT_SOURCE_DIR}/public/${asset}")
47-
set(output "${CMAKE_CURRENT_BINARY_DIR}/${asset}.hpp")
48-
list(APPEND TARGET_SRCS ${output})
49-
add_custom_command(
50-
DEPENDS "${input}"
51-
OUTPUT "${output}"
52-
COMMAND "${CMAKE_COMMAND}" "-DINPUT=${input}" "-DOUTPUT=${output}" -P "${PROJECT_SOURCE_DIR}/scripts/xxd.cmake"
41+
option(LLAMA_BUILD_WEBUI "Build the embedded Web UI" ON)
42+
43+
if (LLAMA_BUILD_WEBUI)
44+
set(PUBLIC_ASSETS
45+
index.html.gz
46+
loading.html
5347
)
54-
set_source_files_properties(${output} PROPERTIES GENERATED TRUE)
55-
endforeach()
48+
49+
foreach(asset ${PUBLIC_ASSETS})
50+
set(input "${CMAKE_CURRENT_SOURCE_DIR}/public/${asset}")
51+
set(output "${CMAKE_CURRENT_BINARY_DIR}/${asset}.hpp")
52+
list(APPEND TARGET_SRCS ${output})
53+
add_custom_command(
54+
DEPENDS "${input}"
55+
OUTPUT "${output}"
56+
COMMAND "${CMAKE_COMMAND}" "-DINPUT=${input}" "-DOUTPUT=${output}" -P "${PROJECT_SOURCE_DIR}/scripts/xxd.cmake"
57+
)
58+
set_source_files_properties(${output} PROPERTIES GENERATED TRUE)
59+
endforeach()
60+
add_definitions(-DLLAMA_BUILD_WEBUI)
61+
else()
62+
endif()
5663

5764
add_executable(${TARGET} ${TARGET_SRCS})
5865
install(TARGETS ${TARGET} RUNTIME)

tools/server/server-http.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
#include <string>
99
#include <thread>
1010

11+
#ifdef LLAMA_BUILD_WEBUI
1112
// auto generated files (see README.md for details)
1213
#include "index.html.gz.hpp"
1314
#include "loading.html.hpp"
15+
#endif
1416

1517
//
1618
// HTTP implementation using cpp-httplib
@@ -181,11 +183,14 @@ bool server_http_context::init(const common_params & params) {
181183
auto middleware_server_state = [this](const httplib::Request & req, httplib::Response & res) {
182184
bool ready = is_ready.load();
183185
if (!ready) {
186+
#ifdef LLAMA_BUILD_WEBUI
184187
auto tmp = string_split<std::string>(req.path, '.');
185188
if (req.path == "/" || tmp.back() == "html") {
186189
res.status = 503;
187190
res.set_content(reinterpret_cast<const char*>(loading_html), loading_html_len, "text/html; charset=utf-8");
188-
} else {
191+
} else
192+
#endif
193+
{
189194
// no endpoints is allowed to be accessed when the server is not ready
190195
// this is to prevent any data races or inconsistent states
191196
res.status = 503;
@@ -255,6 +260,7 @@ bool server_http_context::init(const common_params & params) {
255260
return 1;
256261
}
257262
} else {
263+
#ifdef LLAMA_BUILD_WEBUI
258264
// using embedded static index.html
259265
srv->Get(params.api_prefix + "/", [](const httplib::Request & req, httplib::Response & res) {
260266
if (req.get_header_value("Accept-Encoding").find("gzip") == std::string::npos) {
@@ -268,6 +274,7 @@ bool server_http_context::init(const common_params & params) {
268274
}
269275
return false;
270276
});
277+
#endif
271278
}
272279
}
273280
return true;

0 commit comments

Comments
 (0)