Skip to content

Commit 91c36c2

Browse files
authored
server : (web ui) Various improvements, now use vite as bundler (#10599)
* hide buttons in dropdown menu * use npm as deps manager and vite as bundler * fix build * fix build (2) * fix responsive on mobile * fix more problems on mobile * sync build * (test) add CI step for verifying build * fix ci * force rebuild .hpp files * cmake: clean up generated files pre build
1 parent 1cd3df4 commit 91c36c2

21 files changed

+3936
-27401
lines changed

.github/workflows/server.yml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,26 @@ jobs:
7676
run: |
7777
pip install -r examples/server/tests/requirements.txt
7878
79-
- name: Verify server deps
80-
id: verify_server_deps
79+
# Setup nodejs (to be used for verifying bundled index.html)
80+
- uses: actions/setup-node@v4
81+
with:
82+
node-version: 22
83+
84+
- name: Verify bundled index.html
85+
id: verify_server_index_html
8186
run: |
8287
git config --global --add safe.directory $(realpath .)
83-
cd examples/server
84-
git ls-files --others --modified
88+
cd examples/server/webui
8589
git status
86-
./deps.sh
90+
npm ci
91+
npm run build
8792
git status
88-
not_ignored_files="$(git ls-files --others --modified)"
89-
echo "Modified files: ${not_ignored_files}"
90-
if [ -n "${not_ignored_files}" ]; then
91-
echo "Repository is dirty or server deps are not built as expected"
92-
echo "${not_ignored_files}"
93+
modified_files="$(git status -s)"
94+
echo "Modified files: ${modified_files}"
95+
if [ -n "${modified_files}" ]; then
96+
echo "Repository is dirty or server/webui is not built as expected"
97+
echo "Hint: You may need to follow Web UI build guide in server/README.md"
98+
echo "${modified_files}"
9399
exit 1
94100
fi
95101

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ examples/server/*.mjs.hpp
104104
!examples/sycl/*.bat
105105
!examples/sycl/*.sh
106106

107+
# Server Web UI temporary files
108+
node_modules
109+
examples/server/webui/dist
110+
107111
# Python
108112

109113
/.venv

Makefile

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,8 +1145,15 @@ $(LIB_COMMON_S): $(OBJ_COMMON)
11451145
# Include dependency files
11461146
-include $(DEP_FILES)
11471147

1148+
# Clean generated server assets
1149+
clean-server-assets:
1150+
find examples/server -type f -name "*.js.hpp" -delete
1151+
find examples/server -type f -name "*.mjs.hpp" -delete
1152+
find examples/server -type f -name "*.css.hpp" -delete
1153+
find examples/server -type f -name "*.html.hpp" -delete
1154+
11481155
# Clean rule
1149-
clean:
1156+
clean: clean-server-assets
11501157
rm -vrf $(BUILD_TARGETS) $(TEST_TARGETS)
11511158
rm -rvf *.a *.dll *.so *.dot
11521159
find ggml src common tests examples pocs -type f -name "*.o" -delete
@@ -1354,20 +1361,14 @@ llama-server: \
13541361
examples/server/utils.hpp \
13551362
examples/server/httplib.h \
13561363
examples/server/index.html.hpp \
1357-
examples/server/completion.js.hpp \
13581364
examples/server/loading.html.hpp \
1359-
examples/server/deps_daisyui.min.css.hpp \
1360-
examples/server/deps_markdown-it.js.hpp \
1361-
examples/server/deps_tailwindcss.js.hpp \
1362-
examples/server/deps_vue.esm-browser.js.hpp \
13631365
common/json.hpp \
1364-
common/stb_image.h \
13651366
$(OBJ_ALL)
13661367
$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
13671368
$(CXX) $(CXXFLAGS) $(filter-out %.h %.hpp $<,$^) -Iexamples/server $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) $(LWINSOCK2)
13681369

13691370
# Portable equivalent of `cd examples/server/public && xxd -i $(notdir $<) ../$(notdir $<).hpp`:
1370-
examples/server/%.hpp: examples/server/public/% Makefile
1371+
examples/server/%.hpp: examples/server/public/% FORCE Makefile
13711372
@( export NAME=$(subst .,_,$(subst -,_,$(notdir $<))) && \
13721373
echo "unsigned char $${NAME}[] = {" && \
13731374
cat $< | od -v -t x1 -An | sed -E 's/([0-9a-fA-F]+)/0x\1, /g' && \
@@ -1542,7 +1543,7 @@ llama-q8dot: pocs/vdot/q8dot.cpp ggml/src/ggml.o \
15421543
# Deprecated binaries that we want to keep around long enough for people to migrate to the new filenames, then these can be removed.
15431544
#
15441545
# Mark legacy binary targets as .PHONY so that they are always checked.
1545-
.PHONY: main quantize perplexity embedding server
1546+
.PHONY: FORCE main quantize perplexity embedding server
15461547

15471548
# Define the object file target
15481549
examples/deprecation-warning/deprecation-warning.o: examples/deprecation-warning/deprecation-warning.cpp

examples/server/CMakeLists.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ set(TARGET_SRCS
1616
)
1717
set(PUBLIC_ASSETS
1818
index.html
19-
completion.js
2019
loading.html
21-
deps_daisyui.min.css
22-
deps_markdown-it.js
23-
deps_tailwindcss.js
24-
deps_vue.esm-browser.js
2520
)
2621

2722
foreach(asset ${PUBLIC_ASSETS})
@@ -33,11 +28,20 @@ foreach(asset ${PUBLIC_ASSETS})
3328
OUTPUT "${output}"
3429
COMMAND "${CMAKE_COMMAND}" "-DINPUT=${input}" "-DOUTPUT=${output}" -P "${PROJECT_SOURCE_DIR}/scripts/xxd.cmake"
3530
)
31+
set_source_files_properties(${output} PROPERTIES GENERATED TRUE)
3632
endforeach()
3733

3834
add_executable(${TARGET} ${TARGET_SRCS})
3935
install(TARGETS ${TARGET} RUNTIME)
4036

37+
# clean up generated files in pre-build step
38+
foreach(asset ${PUBLIC_ASSETS})
39+
set(output "${CMAKE_CURRENT_BINARY_DIR}/${asset}.hpp")
40+
add_custom_command(TARGET ${TARGET} PRE_BUILD
41+
COMMAND "${CMAKE_COMMAND}" -E remove -f "${output}"
42+
)
43+
endforeach()
44+
4145
target_link_libraries(${TARGET} PRIVATE common ${CMAKE_THREAD_LIBS_INIT})
4246

4347
if (LLAMA_SERVER_SSL)

examples/server/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,37 @@ services:
217217
cmake --build build --config Release -t llama-server
218218
```
219219

220+
## Web UI
221+
222+
The project includes a web-based user interface that enables interaction with the model through the `/chat/completions` endpoint.
223+
224+
The web UI is developed using:
225+
- `vue` framework for frontend development
226+
- `tailwindcss` and `daisyui` for styling
227+
- `vite` for build tooling
228+
229+
A pre-built version is available as a single HTML file under `/public` directory.
230+
231+
To build or to run the dev server (with hot reload):
232+
233+
```sh
234+
# make sure you have nodejs installed
235+
cd examples/server/webui
236+
npm i
237+
238+
# to run the dev server
239+
npm run dev
240+
241+
# to build the public/index.html
242+
npm run build
243+
```
244+
245+
NOTE: if you are using the vite dev server, you can change the API base URL to llama.cpp. To do that, run this code snippet in browser's console:
246+
247+
```js
248+
localStorage.setItem('base', 'http://localhost:8080')
249+
```
250+
220251
## Quick Start
221252

222253
To get started right away, run the following command, making sure to use the correct path for the model you have:

examples/server/deps.sh

Lines changed: 0 additions & 25 deletions
This file was deleted.

examples/server/public/deps_daisyui.min.css

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)