Proxy in front of vLLM too; dashboard reset/clear; opencode effort variants

- Move the MLX proxy into backends/proxy.py and run it on both backends:
  public port 1134 is the proxy, the model server listens on 127.0.0.1:1135.
  On vLLM this brings the reasoning chooser, the "default" alias and the
  per-request table. Effort levels the model lacks map to the nearest it has
  (high -> xhigh on qwen3.8); vLLM's own key is sent upstream; streamed runs
  are counted from the usage chunk (MTP packs several tokens per chunk).
- Dashboard: restore METRIC_RE (vLLM page stuck on "loading"); Statistics
  header with Reset, Requests header with Clear; drop the TTFT chart; rename
  token columns; Peak KV shows "-" when no samples cover a run.
- opencode: config snippet's model points at <provider>/default, and
  reasoning models get variants built from the levels the template accepts.
- README: proxy on both platforms; NVIDIA checklist split into verified / open.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
neil 2026-11-03 13:03:52 -08:00
parent 1121c3f908
commit 8879db44a0
12 changed files with 886 additions and 493 deletions

View file

@ -5,9 +5,12 @@ llm-host detects the hardware, picks the models (and the right build of each) th
installs the inference backend, and runs it as a background service with a web dashboard.
- **Linux + NVIDIA** → [vLLM](https://github.com/vllm-project/vllm)
- **macOS on Apple Silicon** → [MLX](https://github.com/ml-explore/mlx-lm), behind a small proxy that adds API keys
- **macOS on Apple Silicon** → [MLX](https://github.com/ml-explore/mlx-lm)
Either way you get the same OpenAI-compatible API (with an API key) on port 1134 and a dashboard on port 11340.
The model server itself listens on localhost (port 1135), behind a small proxy on 1134 that checks the key,
answers to the model's names, applies the dashboard's reasoning setting and times each request — the same
proxy on both platforms, so clients and the dashboard see one API.
Everything installs into your home directory; no sudo, Docker or system CUDA toolkit needed.
## Install
@ -87,12 +90,17 @@ of remote ones at once, each named after the machine it reaches:
Each provider offers a **single model**, `default`, rather than every model that fits. One model is loaded at a
time, so a list of them would be a menu of one entry that works and the rest answering `404 model_not_found` —
and naming the loaded model would break the client's saved default on the next `llmhost switch`. `default` is a
name the API also answers to, so `llmhost/default` keeps working across switches: vLLM takes it as a second
`--served-model-name` (and still reports the real slug, being the first), and on a Mac the proxy accepts it as an
alias. The local entry is labelled with whatever is loaded — `Default model · Qwen3.8 27B (Local)` — and
name the API also answers to, so `llmhost/default` keeps working across switches: the proxy accepts it as an
alias, and `/v1/models` reports the real slug. The local entry is labelled with whatever is loaded — `Default model · Qwen3.8 27B (Local)` — and
`llmhost switch`, the dashboard and `llmhost update` keep that label current. A config that still points at a
specific model (`llmhost/qwen3.8-27b`) is migrated to `llmhost/default` the next time llm-host writes the block.
opencode offers its own `low`/`medium`/`high` effort menu for any reasoning model, and a level the model's
template doesn't define makes every request fail. So the block carries `variants` that hide the levels the
loaded model lacks and add the ones it has (Qwen3.8 27B: no `high`, plus `xhigh`). A pasted remote block can't
follow a later switch, so the proxy also maps a level the model lacks to the nearest one it has (`high` →
`xhigh`); a stale menu entry still works.
To serve a different model, switch the server: `llmhost switch <name>` or the dashboard. Clients don't choose.
Which block belongs to *this* machine is decided by the key-file reference it carries, not by its name. So the
@ -136,8 +144,8 @@ The setting is a default for requests that don't ask for anything: the proxy add
completions, and a `chat_template_kwargs` key the client sets itself always wins. Changing it
takes effect on the next request with no reload, so the model stays in memory.
On Linux + NVIDIA there's no chooser: vLLM runs without a proxy in front, so nothing is in the
path to add the argument. Clients can still pass `chat_template_kwargs` themselves.
This works the same on vLLM and MLX. A client's own top-level `reasoning_effort` also wins over
the dashboard's level, and one the model lacks is mapped to the nearest level it has.
## How models are chosen
@ -185,50 +193,43 @@ python3 tests/test_opencode.py # or run one directly
| | |
|---|---|
| `tests/test_opencode.py` | provider naming and ownership, removal, the credential cache |
| `tests/test_proxy.py` | the API refusing a model that isn't loaded, against a fake `mlx_lm` |
| `tests/test_proxy.py` | model names, effort mapping, upstream key, streamed-run counting, against a fake server |
| `tests/test_dashboard.py` | KV parsing, per-run summaries, log collapsing |
| `tests/test_reasoning.py` | effort options matching the real chat templates |
## Continuing on an NVIDIA box
Everything in this branch was written and tested on Apple Silicon + MLX. The parts below are
either **unverified on vLLM** or deliberately not wired there, so start here when you check the
repo out on the Linux machine. `python3 tests/run.py` passes on either platform (the suites are
hermetic and don't need a GPU), so run that first to confirm nothing is broken.
This branch was written on Apple Silicon + MLX, then checked on Linux (vLLM 0.33.0, RTX PRO 6000
Blackwell, qwen3.8-27b) on 2026-11-03. `python3 tests/run.py` passes on either platform (the
suites are hermetic and don't need a GPU), so run that first.
**Verify first — it can stop the server from starting:**
**Verified on the NVIDIA box:**
- `--served-model-name <slug> default` (`plan.vllm_args`). vLLM documents multiple names ("the
server will respond to any of them", with the first reported back), and the CLI form is one
flag with several tokens. Not run against a real vLLM, though, so confirm `vllm serve` accepts
it and that `curl -H "Authorization: Bearer $(llmhost key)" .../v1/chat/completions -d
'{"model":"default",...}'` answers. Until that's confirmed, the `llmhost-<host>/default` block
that `llmhost opencode-config` prints can't work from a client.
- `/v1/models` should still report the real slug, not `default`. If it reports `default`, the
dashboard's readiness check (`active in served`) will sit on "loading" forever.
- vLLM runs behind the proxy (`backends/proxy.py`), on `127.0.0.1:1135` with its own API key,
which the proxy sends on. From the LAN: a wrong key gets 401, the inner port is unreachable,
`"model":"default"` is answered, an unknown model gets the proxy's `404 model_not_found`, and
`/v1/models` lists only the slug.
- Reasoning chooser: offers what Qwen3.8's template accepts; setting "Thinking off" from the
dashboard took effect on the next request with no restart.
- Completed-requests table: filled from the proxy, with prompt tokens net of the prefix cache
(`--enable-prompt-tokens-details`) and generated tokens from the usage chunk (a vLLM stream
chunk can carry several tokens).
- opencode from another machine: streaming and tool calls through the proxy; its generic `high`
maps to `xhigh` instead of failing; the generated block hides `high` and adds `xhigh`.
- Dashboard: GPU temperature and power from `nvidia-smi`, and KV usage from vLLM's `/metrics`
(read from the inner port). `METRIC_RE` had been dropped from `web/server.py`, leaving the
dashboard stuck on "loading"; `tests/test_dashboard.py` now covers it.
**Not wired on vLLM, by design — each needs a decision, not a bug fix:**
**Still open:**
- **Reasoning chooser.** The setting is injected per request by the MLX proxy, and llm-host runs
vLLM with nothing in front of it, so there's nowhere to inject. Either put a proxy on Linux too
(it would also bring the per-request table and the API-key handling into one place) or find a
vLLM flag for default chat-template kwargs. The dashboard hides the panel rather than offer a
control that does nothing.
- **Completed-requests table.** Same reason: the per-request timings come from the proxy. vLLM
exposes histograms on `/metrics` rather than per-request rows, so this would be a different
implementation, not a port.
- **`404 model_not_found` for a model that isn't loaded.** That's the proxy. On vLLM the two
served names both answer and anything else gets vLLM's own 404, which is the same outcome by a
different route — worth confirming the message is clear enough.
**Should work, but has never run on this hardware:**
- GPU temperature and power come from `nvidia-smi`, so the charts the dashboard hides on a Mac
should appear here. Check that the `hasTP` test in `index.html` doesn't hide them wrongly.
- KV cache on vLLM comes from `vllm:kv_cache_usage_perc` and predates this branch; the new
log-parsing path is MLX-only.
- `llmhost opencode-remove`, the opencode credential-cache clearing, and
`uninstall --purge --keep-key` are all platform-independent, but worth one smoke test each.
- opencode 1.19 keeps credentials in `~/.local/share/opencode/opencode.db` (a `credential`
table), not `auth.json`, so `opencode.clear_auth` no longer finds a stale cached key there.
- Power is summed over the GPUs that report it, so on a multi-GPU box a card showing `[N/A]`
makes the total read low (seen with a stub `nvidia-smi`, not real hardware).
- `llmhost opencode-remove` and `uninstall --purge --keep-key` pass their hermetic tests on Linux
but haven't been run against a real install there.
- An existing install picks up the second port on the next restart; `setup` checks it's free,
a bare restart doesn't (vLLM fails to bind and the log says so).
## Files