From af47ec5df26ab4044aab5e6a8a469ef470b6bb59 Mon Sep 17 00:00:00 2001 From: Pavel Semchukov Date: Wed, 25 Nov 2026 12:29:26 +0300 Subject: [PATCH] serve: About's This PC shows the PC's real network IP --- terminal/serve/server.py | 16 ++++++++++++++-- terminal/serve/test_web_monitor_notes.py | 18 ++++++++++++++++++ terminal/serve/web/app.js | 2 ++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/terminal/serve/server.py b/terminal/serve/server.py index 698f2368fe..200fd75723 100644 --- a/terminal/serve/server.py +++ b/terminal/serve/server.py @@ -4297,6 +4297,8 @@ def __init__(self, engine: Engine, tokenizer, template: ChatTemplate, model_name # "*" = any), and every name it answers to, which serve() works out from the address it listens on self.allowed_hosts: list[str] = [] self.host_names: set[str] = set(LOOPBACK_NAMES) + # the PC's real network IP (what another device types in), shown in About > This PC; worked out once at serve() + self.server_ip: str | None = None self.status = {"busy": False, "queued": 0} # GET /status: what the model is doing right now self.rate = collections.deque(maxlen=32) # (time, generated) samples for the live tok/s window # "parallel" (the engine's batch slots): every running request's own status and rate window; self.status @@ -5754,11 +5756,13 @@ def metrics(self, all_requests=False) -> dict: engine["vision_note"] = self.vision.cpu_note tel = self.telemetry.snapshot() if getattr(self, "telemetry", None) else {"now": {}, "history": {}, "static": {}} parked = self.conv_log.poll(getattr(self.engine, "log_path", None), getattr(self.engine, "log_start", None)) + static = dict(tel["static"]) + if self.server_ip: # About > This PC: the PC's real network IP (no port) + static["server_ip"] = self.server_ip return {"engine": engine, "live": live, "requests": hist[::-1][:None if all_requests else 12], "conversation_cache": conversation_cache_view(engine, hist, totals, parked), "requests_kept": len(hist), "totals": totals, "hardware": tel["now"], - "hardware_static": - tel["static"], "history": tel["history"], "time": now} + "hardware_static": static, "history": tel["history"], "time": now} def prometheus(self) -> str: """GET /metrics/prometheus: the totals and what is running in Prometheus' text format, under llama-server's @@ -9106,6 +9110,13 @@ def lan_addresses() -> list[str]: return ([first] if ok(first) else []) + sorted(ip for ip in ips if ok(ip) and ip != first) +def machine_ip() -> str | None: + """The PC's real network IP (what another device types in): its IPv4 addresses on the networks, without loopback + or link-local. None when the machine has none (only loopback, or only IPv6).""" + ips = lan_addresses() + return ", ".join(ips) if ips else None + + def host_names_for(bind_host: str, allowed_hosts=(), trusted_origins=()) -> set[str]: """Every name this server answers to besides an IP address: localhost, the address it listens on, the config's allowed_hosts and trusted_origins' hosts, and - listening beyond this PC (0.0.0.0 or a LAN address) - this PC's @@ -9128,6 +9139,7 @@ def host_names_for(bind_host: str, allowed_hosts=(), trusted_origins=()) -> set[ def serve(svc: Service, host="127.0.0.1", port=8095) -> ThreadingHTTPServer: svc.host_names = host_names_for(host, svc.allowed_hosts, svc.trusted_origins) + svc.server_ip = machine_ip() # About > This PC: the PC's real IP, worked out once at start svc.start_telemetry() httpd = Server((host, port), make_handler(svc)) httpd.svc = svc diff --git a/terminal/serve/test_web_monitor_notes.py b/terminal/serve/test_web_monitor_notes.py index b08b9bbcfb..f9e722117e 100644 --- a/terminal/serve/test_web_monitor_notes.py +++ b/terminal/serve/test_web_monitor_notes.py @@ -84,6 +84,24 @@ def test_about_shows_the_reason_beside_a_named_gpu(self): "console.log(JSON.stringify(rows['facts-hw'].find(r => r[0] === 'GPU')[1]));") self.assertEqual(run_node(script), f"Apple M5 Max, 122 GB · {MAC_NOTE}") + SERVER_IP = "192.168.1.42" + + def _about_hw(self, st): + app = (WEB / "app.js").read_text(encoding="utf-8") + return (STUBS + "const rows = {}; const facts = (el, r) => { rows[el.id] = r; }; const projectionText = () => null;\n" + "globalThis.location = {origin: 'http://127.0.0.1:8080'};\n" + function_source(app, "renderAbout") + + f"renderAbout({{}}, {json.dumps({})}, {json.dumps(st)});\n" + "const row = rows['facts-hw'].find(r => r[0] === 'Server');\n" + "console.log(JSON.stringify(row ? row[1] : null));") + + def test_about_shows_the_server_ip(self): + cards = run_node(self._about_hw({"gpu_name": "NVIDIA GeForce RTX 4090", "server_ip": self.SERVER_IP})) + self.assertEqual(cards, self.SERVER_IP, "the PC's real network IP, beside GPU/CPU/RAM") + + def test_about_hides_the_server_row_without_an_ip(self): + cards = run_node(self._about_hw({"gpu_name": "NVIDIA GeForce RTX 4090"})) + self.assertIsNone(cards, "no server_ip from an older server: the row is left out") + if __name__ == "__main__": unittest.main() diff --git a/terminal/serve/web/app.js b/terminal/serve/web/app.js index 86435b0a6d..26fad0930f 100644 --- a/terminal/serve/web/app.js +++ b/terminal/serve/web/app.js @@ -828,6 +828,8 @@ function renderAbout(eng, hw, st) { ["GPU", st.gpu_name ? `${st.gpu_name}${hw.gpu_mem_total ? `, ${gb(hw.gpu_mem_total, 0)} GB` : ""}${st.gpu_note ? ` · ${st.gpu_note}` : ""}` : (st.gpu_note || "not readable (NVML)")], ["CPU", st.cpu_name ? `${st.cpu_name}${st.threads ? `, ${st.threads} threads` : ""}` : null], ["RAM", hw.ram_total ? `${gb(hw.ram_total, 0)} GB` : null], + // the PC's real network IP (no port - that is in the base URLs above); the server sends nothing when it has none + ["Server", st.server_ip || null], ]); const base = location.origin; facts($("facts-api"), [