Commit 074f1f3f7 for llama.cpp
commit 074f1f3f730c1d17f34645d62c1859c74bedbdd8
Author: Aleksander Grygier <aleksander.grygier@gmail.com>
Date: Thu Nov 26 08:52:24 2026 +0100
ui: npx llama-chat talks to llama-server on :9931 by default (#33095)
Without --server, the CLI's config.json now points the app at
llama-server's default port on the host the page was opened from,
instead of the CLI's own address, which has no API and answered 404.
Bump @ggml-org/llama-chat and llama-chat to 0.3.1.
Assisted-by: Claude (Opus 5.5 Medium)
diff --git a/ui/apps/chat/README.md b/ui/apps/chat/README.md
index 7838e7878..639587467 100644
--- a/ui/apps/chat/README.md
+++ b/ui/apps/chat/README.md
@@ -19,14 +19,15 @@ It works with a llama-server in either mode: **MODEL** (one model) or **ROUTER**
Llama Chat is published to npm as [`@ggml-org/llama-chat`](https://www.npmjs.com/package/@ggml-org/llama-chat), with [`llama-chat`](https://www.npmjs.com/package/llama-chat) as its short name. It serves the prebuilt app as static files on localhost, or writes them to a folder for any static file server (see [Self-hosting](#self-hosting)); it brings no server and no models of its own. It needs Node.js 20 or later.
```bash
-npx @ggml-org/llama-chat --server http://localhost:8080 # serve it on http://127.0.0.1:3000 for that llama-server
+npx @ggml-org/llama-chat # serve it on http://127.0.0.1:3000 for llama-server on :9931
+npx @ggml-org/llama-chat --server http://localhost:8080 # for a llama-server elsewhere
npx llama-chat --host 0.0.0.0 --no-open # by its short name, reachable from other devices
npx llama-chat build # write the static app to ./llama-chat instead
```
| Flag | Default | What it does |
| --------------------------------- | ----------- | ------------------------------------------------------------------------------------------- |
-| `--server <url>` | | The llama-server the app talks to, e.g. `http://localhost:8080`; also for `build` |
+| `--server <url>` | `:9931` | The llama-server the app talks to, e.g. `http://localhost:8080`; also for `build` |
| `--port <n>` | `3000` | Fixed, so the origin, and the chats the browser stores under it, stay the same between runs |
| `--host <addr>` | `127.0.0.1` | `0.0.0.0` to open it to the LAN |
| `--open` / `--no-open` | open | Opens the default browser once it listens |
@@ -46,7 +47,7 @@ The app reaches the llama-server on its own origin by default (llama-server serv
{ "server": "http://localhost:8080" }
```
-`npx llama-chat build --server <url>` writes that file, and `npx llama-chat --server <url>` answers it without one. The app reads it on every start, past its caches, so a host can change it without a new build. That llama-server needs `--cors-origins` for the app's address when it restricts origins.
+`npx llama-chat build --server <url>` writes that file, and `npx llama-chat` answers it without one, with `--server <url>` or else llama-server's default port on the host the page is opened from. The app reads it on every start, past its caches, so a host can change it without a new build. That llama-server needs `--cors-origins` for the app's address when it restricts origins.
## Features
diff --git a/ui/apps/chat/alias/package.json b/ui/apps/chat/alias/package.json
index 2c306f455..cf9582d80 100644
--- a/ui/apps/chat/alias/package.json
+++ b/ui/apps/chat/alias/package.json
@@ -1,6 +1,6 @@
{
"name": "llama-chat",
- "version": "0.3.0",
+ "version": "0.3.1",
"description": "npx llama-chat: runs Llama Chat, the chat app for llama.cpp. Same as npx @ggml-org/llama-chat.",
"keywords": [
"llama.cpp",
@@ -28,6 +28,6 @@
"node": ">=20"
},
"dependencies": {
- "@ggml-org/llama-chat": "0.3.0"
+ "@ggml-org/llama-chat": "0.3.1"
}
}
diff --git a/ui/apps/chat/cli/server.js b/ui/apps/chat/cli/server.js
index 95aa60373..8778ed84c 100644
--- a/ui/apps/chat/cli/server.js
+++ b/ui/apps/chat/cli/server.js
@@ -25,7 +25,9 @@ export const DEFAULTS = Object.freeze({
// the folder `build` writes to, in the current directory
out: 'llama-chat',
// fixed, so the origin, and the chats the browser stores under it, stay the same between runs
- port: 3000
+ port: 3000,
+ // llama-server's own default port, on the host the app is opened from, when no --server
+ serverPort: 9931
});
// The same caching llama-server applies to the UI it embeds (tools/server/server-http.cpp):
@@ -77,7 +79,8 @@ when it restricts origins.
Options:
--server <url> the llama-server the app talks to, e.g. http://localhost:8080
- (also for build; default: the address the app is served on)
+ (default: port ${DEFAULTS.serverPort} of the host the page is opened on;
+ for build: the address the app is served on)
--port <n> port to listen on (default: ${DEFAULTS.port})
--host <addr> address to listen on, 0.0.0.0 for the LAN (default: ${DEFAULTS.host})
--open open the browser once it listens (default)
@@ -90,6 +93,7 @@ Build options:
--force write into a folder that is not empty
Examples:
+ npx @ggml-org/llama-chat
npx @ggml-org/llama-chat --server http://localhost:8080
npx @ggml-org/llama-chat --host 0.0.0.0 --port 3000 --no-open
npx @ggml-org/llama-chat build --out ./public --server https://llm.example.com`;
@@ -258,8 +262,19 @@ function configJson(server) {
}
/**
- * The HTTP server: the files of `dist`, read-only. With `server`, it answers config.json
- * itself, so the app talks to that llama-server instead of this address.
+ * The llama-server on its default port, on the host a request was made to: localhost when
+ * opened here, the same LAN or Tailscale address when opened from another device.
+ * @param {http.IncomingMessage} req
+ */
+function defaultServer(req) {
+ const { hostname } = new URL(`http://${req.headers.host ?? 'localhost'}`);
+
+ return `http://${hostname}:${DEFAULTS.serverPort}`;
+}
+
+/**
+ * The HTTP server: the files of `dist`, read-only. It answers config.json itself, so the app
+ * talks to `server`, or by default to llama-server's default port, instead of this address.
* @param {{ distDir?: string, server?: string }} [options]
*/
export function createChatServer({ distDir = DIST_DIR, server = '' } = {}) {
@@ -275,8 +290,8 @@ export function createChatServer({ distDir = DIST_DIR, server = '' } = {}) {
return;
}
- if (server && pathname === CONFIG_PATH) {
- const body = configJson(server);
+ if (pathname === CONFIG_PATH) {
+ const body = configJson(server || defaultServer(req));
res.writeHead(200, {
'Cache-Control': CACHE_REVALIDATE,
@@ -429,7 +444,9 @@ export async function main(argv) {
console.log(`Llama Chat ${packageVersion()} on ${url}`);
- if (options.server) console.log(`Talking to llama-server on ${options.server}`);
+ console.log(
+ `Talking to llama-server on ${options.server || `port ${DEFAULTS.serverPort}, pick another with --server`}`
+ );
console.log(
`If llama-server restricts origins (tools or MCP on), start it with --cors-origins ${url.slice(0, -1)}`
diff --git a/ui/apps/chat/package-lock.json b/ui/apps/chat/package-lock.json
index 5ba3b6f46..d314541a4 100644
--- a/ui/apps/chat/package-lock.json
+++ b/ui/apps/chat/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "@ggml-org/llama-chat",
- "version": "0.3.0",
+ "version": "0.3.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@ggml-org/llama-chat",
- "version": "0.3.0",
+ "version": "0.3.1",
"license": "MIT",
"bin": {
"llama-chat": "bin/cli.js"
diff --git a/ui/apps/chat/package.json b/ui/apps/chat/package.json
index 6ff5b6712..7f7f03d52 100644
--- a/ui/apps/chat/package.json
+++ b/ui/apps/chat/package.json
@@ -1,6 +1,6 @@
{
"name": "@ggml-org/llama-chat",
- "version": "0.3.0",
+ "version": "0.3.1",
"description": "Llama Chat, the chat app for llama.cpp. Run it with npx @ggml-org/llama-chat against any llama-server.",
"keywords": [
"llama.cpp",
diff --git a/ui/apps/chat/tests/unit/cli.test.ts b/ui/apps/chat/tests/unit/cli.test.ts
index be0b9e37a..37cc49725 100644
--- a/ui/apps/chat/tests/unit/cli.test.ts
+++ b/ui/apps/chat/tests/unit/cli.test.ts
@@ -203,9 +203,13 @@ describe('llama-chat server', () => {
expect(worker.headers.get('cache-control')).toBe('no-cache');
});
- it('answers config.json with the llama-server it was given, revalidated', async () => {
- expect((await fetch(`${chatUrl}/config.json`)).status).toBe(404);
+ it('answers config.json with llama-server on its default port when given none', async () => {
+ expect(await (await fetch(`${chatUrl}/config.json`)).json()).toEqual({
+ server: `http://127.0.0.1:${DEFAULTS.serverPort}`
+ });
+ });
+ it('answers config.json with the llama-server it was given, revalidated', async () => {
const pointed = createChatServer({ distDir: dist, server: 'http://localhost:8080' });
const pointedUrl = await listen(pointed);