diff --git a/cli.sh b/scripts/cli.sh similarity index 100% rename from cli.sh rename to scripts/cli.sh diff --git a/scripts/server.sh b/scripts/server.sh new file mode 100755 index 0000000..a763fa4 --- /dev/null +++ b/scripts/server.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Add additional command line arguments as configured +SERVER_OPTS=() +read -r -a SERVER_OPTS <<< "$(snapctl get server-opts)"; +exec "${SNAP}"/bin/cli-wrapper server "${SERVER_OPTS[@]}" diff --git a/snap/hooks/configure b/snap/hooks/configure index 409523a..4fe3c4c 100755 --- a/snap/hooks/configure +++ b/snap/hooks/configure @@ -19,3 +19,8 @@ esac if [ -z "$backend" ]; then snapctl set backend=auto fi + +# Set the default value for server-opts +if [ -z "$(snapctl get server-opts)" ]; then + snapctl set server-opts="" +fi diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index cc3cc74..004bcea 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -21,6 +21,21 @@ description: | or override it per invocation with the env var: LLAMA_CPP_BACKEND=cpu llama-cpp cli ... + + The llama.cpp web server can also be run using the llama-cpp.server app. This + is disabled by default but can be enabled by running: + + snap start --enable llama-cpp.server + + By default, no additional arguments are passed to the server, meaning it will + listen on the default port and address. Arguments can be specified by setting + the server-opts configuration value, e.g.: + + snap set llama-cpp server-opts="--host 0.0.0.0" + + Afterwards, the server must be restarted for the new arguments to take effect: + + snap restart llama-cpp.server license: MIT source-code: - https://github.com/talhaHavadar/snap-llama.cpp @@ -88,10 +103,10 @@ components: apps: llama-cpp: command: bin/cli-wrapper - extensions: + extensions: &extensions # Automatically binds host Vulkan/OpenGL maps - gpu - plugs: + plugs: &plugs - home - network - network-bind @@ -106,15 +121,23 @@ apps: # llama.cpp pins worker threads with sched_setaffinity. Without this # application fails to init. - process-control + server: + command: bin/server-wrapper + daemon: simple + install-mode: disable + extensions: *extensions + plugs: *plugs parts: # --- Wrapper script ------------------------------------------------------ cli: plugin: dump - source: . + source: scripts stage: - bin/cli-wrapper + - bin/server-wrapper organize: cli.sh: bin/cli-wrapper + server.sh: bin/server-wrapper # --- ggml: CPU + loader libs, lives in the main snap -------------------- # Builds llama.cpp's bundled ggml/ subdirectory standalone with the # backend-dl loader enabled and every CPU variant emitted as its own .so.