@simplexai/localmodels-linux-x64 0.1.0-dev.35 → 0.1.0-dev.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bootstrap.identity +1 -1
- package/bootstrap.sha256 +124 -102
- package/kit.py +1 -0
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/__main__.py +9 -3
- package/modules/localmodels/bifrost_config.py +188 -0
- package/modules/localmodels/budget.py +15 -2
- package/modules/localmodels/catalog.json +235 -2
- package/modules/localmodels/catalog.py +51 -320
- package/modules/localmodels/catalog_add.py +2 -8
- package/modules/localmodels/catalog_recipes.py +321 -0
- package/modules/localmodels/cli_parser.py +4 -1
- package/modules/localmodels/console.py +5 -4
- package/modules/localmodels/contracts.py +13 -3
- package/modules/localmodels/debug_cli.py +158 -0
- package/modules/localmodels/debug_mode.py +727 -0
- package/modules/localmodels/debug_stub_server.py +192 -0
- package/modules/localmodels/decode_calibration.json +1 -1
- package/modules/localmodels/decode_calibration.py +34 -17
- package/modules/localmodels/engines-strata-0.1.59.1.json +31 -0
- package/modules/localmodels/gateway.py +21 -155
- package/modules/localmodels/gateway_accept.py +201 -0
- package/modules/localmodels/gateway_bifrost.py +19 -184
- package/modules/localmodels/gateway_cli.py +11 -4
- package/modules/localmodels/gateway_foundations.py +2 -4
- package/modules/localmodels/gateway_probe.py +0 -1
- package/modules/localmodels/gateway_server.py +2 -3
- package/modules/localmodels/gpu_specs.py +12 -0
- package/modules/localmodels/guard.py +2 -7
- package/modules/localmodels/harness.py +16 -129
- package/modules/localmodels/harness_cleanup.py +135 -0
- package/modules/localmodels/harness_gateway.py +16 -14
- package/modules/localmodels/harness_probe.py +12 -4
- package/modules/localmodels/hosts.py +25 -2
- package/modules/localmodels/http_local.py +59 -0
- package/modules/localmodels/install.py +23 -8
- package/modules/localmodels/library_gateway.py +9 -9
- package/modules/localmodels/library_jobs.py +76 -27
- package/modules/localmodels/library_serve.py +12 -1
- package/modules/localmodels/library_state.py +6 -1
- package/modules/localmodels/llm_rank.py +155 -7
- package/modules/localmodels/metal_probe.py +11 -7
- package/modules/localmodels/probe.py +108 -174
- package/modules/localmodels/process_identity.py +109 -154
- package/modules/localmodels/process_windows.py +86 -0
- package/modules/localmodels/recommend.py +32 -3
- package/modules/localmodels/recommend_cli.py +14 -6
- package/modules/localmodels/remote_ops.py +65 -0
- package/modules/localmodels/remote_ops_download.py +2 -2
- package/modules/localmodels/remote_ops_prepare.py +19 -0
- package/modules/localmodels/remote_ops_service.py +14 -2
- package/modules/localmodels/runtime_args.py +10 -3
- package/modules/localmodels/runtime_auth.py +5 -9
- package/modules/localmodels/runtime_cli.py +128 -129
- package/modules/localmodels/runtime_discovery.py +84 -0
- package/modules/localmodels/runtime_install.py +101 -0
- package/modules/localmodels/runtime_releases.py +302 -0
- package/modules/localmodels/service_stop.py +8 -108
- package/modules/localmodels/service_upgrade.py +394 -63
- package/modules/localmodels/services_cli.py +24 -14
- package/modules/localmodels/setup_inspection.py +97 -9
- package/modules/localmodels/setup_text.py +7 -0
- package/modules/localmodels/sizecalc.py +0 -1
- package/modules/localmodels/stack.py +14 -221
- package/modules/localmodels/stack_arena.py +732 -0
- package/modules/localmodels/stack_args.py +15 -9
- package/modules/localmodels/stack_auto.py +384 -3
- package/modules/localmodels/stack_aux_gpu.py +4 -3
- package/modules/localmodels/stack_capacity.py +138 -0
- package/modules/localmodels/stack_cleanup.py +9 -4
- package/modules/localmodels/stack_cli.py +286 -0
- package/modules/localmodels/stack_compose.py +76 -32
- package/modules/localmodels/stack_console.py +9 -6
- package/modules/localmodels/stack_hardware.py +96 -270
- package/modules/localmodels/stack_hardware_text.py +263 -0
- package/modules/localmodels/stack_journal.py +3 -9
- package/modules/localmodels/stack_ledger.py +48 -18
- package/modules/localmodels/stack_lifecycle.py +33 -312
- package/modules/localmodels/stack_mcp.py +729 -0
- package/modules/localmodels/stack_memory.py +0 -2
- package/modules/localmodels/stack_picks.py +73 -18
- package/modules/localmodels/stack_plan.py +23 -5
- package/modules/localmodels/stack_preflight.py +11 -19
- package/modules/localmodels/stack_remove.py +373 -0
- package/modules/localmodels/stack_route.py +101 -17
- package/modules/localmodels/stack_suite.py +16 -10
- package/modules/localmodels/stack_summary.py +14 -0
- package/modules/localmodels/stack_try.py +238 -24
- package/modules/localmodels/stack_try_client.py +53 -15
- package/modules/localmodels/stack_try_docs.py +2 -2
- package/modules/localmodels/stack_view.py +24 -171
- package/modules/localmodels/stack_view_access.py +114 -1
- package/modules/localmodels/stack_view_agent.py +3 -13
- package/modules/localmodels/stack_view_hub.py +9 -10
- package/modules/localmodels/stack_view_llm.py +1 -1
- package/modules/localmodels/stack_view_sandbox.py +2 -2
- package/modules/localmodels/stack_view_schema.py +183 -0
- package/modules/localmodels/stack_view_serve.py +7 -1
- package/modules/localmodels/stack_view_service.py +1 -2
- package/modules/localmodels/stack_view_text.py +13 -9
- package/modules/localmodels/stack_warm.py +3 -0
- package/modules/localmodels/stack_warm_store.py +517 -0
- package/modules/localmodels/tui.py +28 -4
- package/modules/localmodels/tui_dialogs.py +136 -0
- package/modules/localmodels/tui_modals.py +279 -0
- package/modules/localmodels/tui_screen.py +113 -154
- package/modules/localmodels/tui_views.py +134 -203
- package/modules/localmodels/web/index.html +510 -101
- package/modules/localmodels/web/sizecalc/app.js +363 -10
- package/modules/localmodels/web/sizecalc/page.html +27 -3
- package/modules/localmodels/web/view/fleet.html +11 -2
- package/modules/localmodels/web/view/fleet.js +191 -17
- package/modules/localmodels/web/view/i18n.js +3 -2
- package/modules/localmodels/web/view/index.html +1 -1
- package/modules/localmodels/web/view/nav.js +22 -3
- package/modules/localmodels/web/view/view.css +63 -18
- package/modules/localmodels/web/view/view.js +169 -32
- package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/RECORD +120 -98
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/localmodels/engines-strata-0.1.49.1.json +0 -31
- /package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -12,6 +12,7 @@ import math
|
|
|
12
12
|
import sys
|
|
13
13
|
import time
|
|
14
14
|
import urllib.request
|
|
15
|
+
import uuid
|
|
15
16
|
from collections.abc import Callable, Iterator
|
|
16
17
|
from dataclasses import dataclass, field
|
|
17
18
|
from typing import cast
|
|
@@ -25,6 +26,10 @@ class DemoError(RuntimeError):
|
|
|
25
26
|
"""A fixed, content-free request failure suitable for the terminal."""
|
|
26
27
|
|
|
27
28
|
|
|
29
|
+
class InputError(ValueError):
|
|
30
|
+
"""Caller-supplied input violates a documented bound (maps to CLI exit 2)."""
|
|
31
|
+
|
|
32
|
+
|
|
28
33
|
class _NoRedirect(urllib.request.HTTPRedirectHandler):
|
|
29
34
|
def redirect_request(
|
|
30
35
|
self,
|
|
@@ -86,6 +91,10 @@ class StreamStats:
|
|
|
86
91
|
server_decode_tok_s: float | None = None
|
|
87
92
|
answered: bool = False
|
|
88
93
|
finish: str | None = None
|
|
94
|
+
response_model: str | None = None
|
|
95
|
+
answered_by: str | None = None
|
|
96
|
+
request_id: str | None = None
|
|
97
|
+
response_ids: set[str] = field(default_factory=set)
|
|
89
98
|
|
|
90
99
|
def lines(self) -> list[str]:
|
|
91
100
|
first = f"{self.first_token_s:.3f} s" if self.first_token_s is not None else "unavailable"
|
|
@@ -97,10 +106,13 @@ class StreamStats:
|
|
|
97
106
|
speed = (self.completion_tokens - 1) / span
|
|
98
107
|
basis = "observed stream, includes gateway and tool waits"
|
|
99
108
|
decode = f"{speed:.1f} tok/s ({basis})" if speed else "unavailable (no token timing)"
|
|
100
|
-
|
|
109
|
+
lines = [
|
|
101
110
|
f"Time to first token: {first} (measured, includes reasoning tokens).",
|
|
102
111
|
f"Decode speed: {decode}.",
|
|
103
112
|
]
|
|
113
|
+
if self.answered_by:
|
|
114
|
+
return [f"Answered by: {self.answered_by}.", *lines]
|
|
115
|
+
return lines
|
|
104
116
|
|
|
105
117
|
|
|
106
118
|
@dataclass(frozen=True)
|
|
@@ -110,14 +122,21 @@ class Gateway:
|
|
|
110
122
|
key: str = field(repr=False)
|
|
111
123
|
kind: str
|
|
112
124
|
|
|
113
|
-
def _open(
|
|
125
|
+
def _open(
|
|
126
|
+
self,
|
|
127
|
+
path: str,
|
|
128
|
+
body: dict[str, object],
|
|
129
|
+
extra_headers: dict[str, str] | None = None,
|
|
130
|
+
) -> http.client.HTTPResponse:
|
|
131
|
+
headers = {
|
|
132
|
+
"Authorization": f"Bearer {self.key}",
|
|
133
|
+
"Content-Type": "application/json",
|
|
134
|
+
**(extra_headers or {}),
|
|
135
|
+
}
|
|
114
136
|
request = urllib.request.Request(
|
|
115
137
|
self.base_url + path,
|
|
116
138
|
data=json.dumps(body).encode("utf-8"),
|
|
117
|
-
headers=
|
|
118
|
-
"Authorization": f"Bearer {self.key}",
|
|
119
|
-
"Content-Type": "application/json",
|
|
120
|
-
},
|
|
139
|
+
headers=headers,
|
|
121
140
|
)
|
|
122
141
|
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}), _NoRedirect())
|
|
123
142
|
return cast(http.client.HTTPResponse, opener.open(request, timeout=TIMEOUT_S))
|
|
@@ -133,11 +152,20 @@ class Gateway:
|
|
|
133
152
|
return _object(raw)
|
|
134
153
|
|
|
135
154
|
def stream(self, body: dict[str, object], write: Callable[[str], None]) -> StreamStats:
|
|
136
|
-
|
|
155
|
+
req_id = uuid.uuid4().hex
|
|
156
|
+
stats = StreamStats(request_id=req_id)
|
|
137
157
|
started = time.monotonic()
|
|
138
|
-
with self._open(
|
|
158
|
+
with self._open(
|
|
159
|
+
"/v1/chat/completions",
|
|
160
|
+
{**body, "stream": True},
|
|
161
|
+
extra_headers={"X-Request-Id": req_id},
|
|
162
|
+
) as response:
|
|
139
163
|
if response.headers.get_content_type() != "text/event-stream":
|
|
140
164
|
raise DemoError("The gateway did not stream an answer; run stack doctor.")
|
|
165
|
+
for header in ("X-Request-Id", "x-bf-request-id"):
|
|
166
|
+
val = response.headers.get(header)
|
|
167
|
+
if isinstance(val, str) and val.strip():
|
|
168
|
+
stats.response_ids.add(val.strip())
|
|
141
169
|
for event in _events(response):
|
|
142
170
|
_chunk(stats, event, time.monotonic() - started, write)
|
|
143
171
|
if not stats.answered or stats.finish != "stop":
|
|
@@ -148,6 +176,22 @@ class Gateway:
|
|
|
148
176
|
return stats
|
|
149
177
|
|
|
150
178
|
|
|
179
|
+
def _record_metadata(stats: StreamStats, event: dict[str, object]) -> None:
|
|
180
|
+
event_id = event.get("id")
|
|
181
|
+
if isinstance(event_id, str) and event_id.strip():
|
|
182
|
+
stats.response_ids.add(event_id.strip())
|
|
183
|
+
model = event.get("model")
|
|
184
|
+
if isinstance(model, str) and model.strip():
|
|
185
|
+
stats.response_model = model.strip()
|
|
186
|
+
usage = event.get("usage")
|
|
187
|
+
count = usage.get("completion_tokens") if isinstance(usage, dict) else None
|
|
188
|
+
if isinstance(count, int) and not isinstance(count, bool) and count >= 0:
|
|
189
|
+
stats.completion_tokens = count
|
|
190
|
+
timing = event.get("timings")
|
|
191
|
+
if isinstance(timing, dict):
|
|
192
|
+
stats.server_decode_tok_s = _positive(timing.get("predicted_per_second"))
|
|
193
|
+
|
|
194
|
+
|
|
151
195
|
def _chunk(
|
|
152
196
|
stats: StreamStats,
|
|
153
197
|
event: dict[str, object],
|
|
@@ -156,13 +200,7 @@ def _chunk(
|
|
|
156
200
|
) -> None:
|
|
157
201
|
if "error" in event:
|
|
158
202
|
raise DemoError("The gateway reported a request error; run stack doctor.")
|
|
159
|
-
|
|
160
|
-
count = usage.get("completion_tokens") if isinstance(usage, dict) else None
|
|
161
|
-
if isinstance(count, int) and not isinstance(count, bool) and count >= 0:
|
|
162
|
-
stats.completion_tokens = count
|
|
163
|
-
timing = event.get("timings")
|
|
164
|
-
if isinstance(timing, dict):
|
|
165
|
-
stats.server_decode_tok_s = _positive(timing.get("predicted_per_second"))
|
|
203
|
+
_record_metadata(stats, event)
|
|
166
204
|
choices = event.get("choices")
|
|
167
205
|
if not isinstance(choices, list):
|
|
168
206
|
raise DemoError("The gateway returned invalid stream choices.")
|
|
@@ -12,7 +12,7 @@ import os
|
|
|
12
12
|
from dataclasses import dataclass
|
|
13
13
|
from pathlib import Path
|
|
14
14
|
|
|
15
|
-
from localmodels.stack_try_client import DemoError, Gateway
|
|
15
|
+
from localmodels.stack_try_client import DemoError, Gateway, InputError
|
|
16
16
|
|
|
17
17
|
SUFFIXES = frozenset({".txt", ".md", ".rst", ".csv", ".json"})
|
|
18
18
|
MAX_FILES = 64
|
|
@@ -114,7 +114,7 @@ def _vectors(value: object, count: int) -> list[list[float]]:
|
|
|
114
114
|
|
|
115
115
|
def context(client: Gateway, model: str, folder: Path, question: str) -> str:
|
|
116
116
|
if len(question.encode("utf-8")) > MAX_QUESTION_BYTES:
|
|
117
|
-
raise
|
|
117
|
+
raise InputError(
|
|
118
118
|
"Docs questions must fit 2000 UTF-8 bytes to stay within the embedding input limit; "
|
|
119
119
|
"shorten the question and retry."
|
|
120
120
|
)
|
|
@@ -19,7 +19,7 @@ from __future__ import annotations
|
|
|
19
19
|
|
|
20
20
|
import datetime as dt
|
|
21
21
|
import math
|
|
22
|
-
from typing import Any,
|
|
22
|
+
from typing import Any, cast
|
|
23
23
|
|
|
24
24
|
from localmodels import (
|
|
25
25
|
app,
|
|
@@ -38,183 +38,36 @@ from localmodels import stack_view_apply as running
|
|
|
38
38
|
from localmodels.estimator import AGENT_VRAM_RESERVE_BYTES, HardwareBudget
|
|
39
39
|
from localmodels.records import Plan
|
|
40
40
|
from localmodels.stack_compose import agent_posture
|
|
41
|
-
from localmodels.stack_plan import Hardware, StackPlan,
|
|
41
|
+
from localmodels.stack_plan import Hardware, StackPlan, default_options
|
|
42
42
|
from localmodels.stack_view_events import Event
|
|
43
43
|
from localmodels.stack_view_gpu import GpuLoad
|
|
44
44
|
from localmodels.stack_view_llm import catalog_entry as catalog_entry
|
|
45
45
|
from localmodels.stack_view_llm import llm_parts as llm_parts
|
|
46
|
-
from localmodels.stack_view_measure import Measured,
|
|
46
|
+
from localmodels.stack_view_measure import Measured, measure, measured_rows
|
|
47
|
+
from localmodels.stack_view_measure import MeasuredRow as MeasuredRow
|
|
48
|
+
from localmodels.stack_view_schema import GIB as GIB
|
|
49
|
+
from localmodels.stack_view_schema import METRICS_BYTES as METRICS_BYTES
|
|
50
|
+
from localmodels.stack_view_schema import SCHEMA as SCHEMA
|
|
51
|
+
from localmodels.stack_view_schema import TASKS as TASKS
|
|
52
|
+
from localmodels.stack_view_schema import Client as Client
|
|
53
|
+
from localmodels.stack_view_schema import Component as Component
|
|
54
|
+
from localmodels.stack_view_schema import Counters as Counters
|
|
55
|
+
from localmodels.stack_view_schema import Figure as Figure
|
|
56
|
+
from localmodels.stack_view_schema import Fit as Fit
|
|
57
|
+
from localmodels.stack_view_schema import Gateway as Gateway
|
|
58
|
+
from localmodels.stack_view_schema import Gpu as Gpu
|
|
59
|
+
from localmodels.stack_view_schema import Host as Host
|
|
60
|
+
from localmodels.stack_view_schema import Memory as Memory
|
|
61
|
+
from localmodels.stack_view_schema import Perf as Perf
|
|
62
|
+
from localmodels.stack_view_schema import Reading as Reading
|
|
63
|
+
from localmodels.stack_view_schema import Segment as Segment
|
|
64
|
+
from localmodels.stack_view_schema import StackView as StackView
|
|
65
|
+
from localmodels.stack_view_schema import Step as Step
|
|
66
|
+
from localmodels.stack_view_schema import WhatIf as WhatIf
|
|
67
|
+
from localmodels.stack_view_schema import next_steps as next_steps
|
|
47
68
|
from localmodels.stack_view_slots import Slot, owned_get
|
|
48
69
|
from localmodels.stack_view_words import say
|
|
49
70
|
|
|
50
|
-
SCHEMA = "localmodels.stack-view/v1"
|
|
51
|
-
GIB = 1 << 30
|
|
52
|
-
METRICS_BYTES = 256 * 1024 # a llama-server /metrics page is a few KiB
|
|
53
|
-
TASKS = ("llm", "llm_fast", "decision", "embedding", "rerank", "stt", "tts")
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
class Figure(TypedDict):
|
|
57
|
-
value: float | None
|
|
58
|
-
basis: str # live | measured | estimate | demo | none
|
|
59
|
-
note: str
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
class Segment(TypedDict):
|
|
63
|
-
kind: str # weights kv state compute draft process decision embedding rerank stt ...
|
|
64
|
-
label: str
|
|
65
|
-
bytes: int
|
|
66
|
-
basis: str # measured | estimate | demo
|
|
67
|
-
component: str | None # the component it belongs to, None for the host's own share
|
|
68
|
-
note: str
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
class Fit(TypedDict):
|
|
72
|
-
"""A validated LLM that passes the agent gate on this card now (stack hardware's check)."""
|
|
73
|
-
|
|
74
|
-
id: str
|
|
75
|
-
quant: str
|
|
76
|
-
decode_tok_s: float # the planner's calibrated decode estimate
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
class Gpu(TypedDict):
|
|
80
|
-
index: int
|
|
81
|
-
name: str
|
|
82
|
-
total_bytes: int
|
|
83
|
-
used_bytes: int
|
|
84
|
-
bandwidth_gb_s: float | None
|
|
85
|
-
holders: list[str]
|
|
86
|
-
segments: list[Segment]
|
|
87
|
-
fits: list[Fit]
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
class Memory(TypedDict):
|
|
91
|
-
total_bytes: int
|
|
92
|
-
available_bytes: int
|
|
93
|
-
segments: list[Segment]
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
class Counters(TypedDict):
|
|
97
|
-
"""llama-server's own counters since it started; a client diffs two to get a rate."""
|
|
98
|
-
|
|
99
|
-
prompt_tokens: float
|
|
100
|
-
prompt_seconds: float
|
|
101
|
-
predicted_tokens: float
|
|
102
|
-
predicted_seconds: float
|
|
103
|
-
processing: float
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
class Perf(TypedDict):
|
|
107
|
-
prefill_tok_s: Figure # for embedding and rerank: the tokens they read per second
|
|
108
|
-
decode_tok_s: Figure
|
|
109
|
-
decode_bound: Figure # the bandwidth ceiling the planner estimates; never a measurement
|
|
110
|
-
latency_ms: Figure # mean call time in the gateway log; Jev: the gateway's share per turn
|
|
111
|
-
calls: int | None # calls in the gateway log's recent window
|
|
112
|
-
failed: int # of those, the ones that did not succeed (not in latency_ms)
|
|
113
|
-
tiers: dict[str, int] | None # Jev only: the tiers it chose in that window
|
|
114
|
-
counters: Counters | None
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
class Component(TypedDict):
|
|
118
|
-
id: str # llm | decision | embedding | rerank | stt | tts
|
|
119
|
-
role: str
|
|
120
|
-
title: str
|
|
121
|
-
model: str
|
|
122
|
-
quant: str
|
|
123
|
-
device: str
|
|
124
|
-
gpu: int | None
|
|
125
|
-
endpoint: str
|
|
126
|
-
state: str # serving | stopped | failed | planned
|
|
127
|
-
health: str
|
|
128
|
-
window: int | None
|
|
129
|
-
slots: int | None
|
|
130
|
-
kv_types: str | None
|
|
131
|
-
vram_bytes: int
|
|
132
|
-
ram_bytes: int
|
|
133
|
-
perf: Perf
|
|
134
|
-
explain: str
|
|
135
|
-
live_slots: list[Slot] | None # llama-server's slots now (stack_view_slots), None unread
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
class Client(TypedDict):
|
|
139
|
-
id: str
|
|
140
|
-
name: str
|
|
141
|
-
model: str
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
class Gateway(TypedDict):
|
|
145
|
-
kind: str # bifrost | magpie
|
|
146
|
-
addr: str
|
|
147
|
-
route: str # the routed model the clients pick
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
class WhatIf(TypedDict):
|
|
151
|
-
"""Enough for a slider to reprice the LLM's card at another window: linear in the window,
|
|
152
|
-
without the sliding-window cap, so it never under-prices (an upper bound)."""
|
|
153
|
-
|
|
154
|
-
gpu: int
|
|
155
|
-
window: int
|
|
156
|
-
slots: int
|
|
157
|
-
kv_bytes_per_token: float
|
|
158
|
-
compute_bytes_per_token: float
|
|
159
|
-
fixed_bytes: int # the LLM's window-independent share
|
|
160
|
-
room_bytes: int # what the card leaves the LLM: total less other programs, reserve, others
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
class Host(TypedDict):
|
|
164
|
-
hostname: str
|
|
165
|
-
system: str
|
|
166
|
-
tier: str
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
class Step(TypedDict):
|
|
170
|
-
command: str
|
|
171
|
-
why: str
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
def next_steps() -> list[Step]:
|
|
175
|
-
"""What a computer without an applied plan runs next, written the way the operator runs
|
|
176
|
-
this tool (``command``) and explained (stack_view_words "next.*")."""
|
|
177
|
-
steps = (("install", "install"), ("stack plan", "plan"), ("stack view --demo", "demo"))
|
|
178
|
-
return [{"command": f"{command()} {sub}", "why": say(f"next.{key}")} for sub, key in steps]
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
class StackView(TypedDict):
|
|
182
|
-
schema: str
|
|
183
|
-
generated_at: str
|
|
184
|
-
source: str # live | demo | empty
|
|
185
|
-
lang: str # always "en"; kept for clients that read it
|
|
186
|
-
plan_id: str | None
|
|
187
|
-
host: Host
|
|
188
|
-
gateway: Gateway | None
|
|
189
|
-
clients: list[Client]
|
|
190
|
-
components: list[Component]
|
|
191
|
-
gpus: list[Gpu]
|
|
192
|
-
ram: Memory
|
|
193
|
-
what_if: WhatIf | None
|
|
194
|
-
events: list[Event] # the gateway's recent calls, newest-ended first; metadata only
|
|
195
|
-
measured: list[MeasuredRow] # what the running services hold, beside what the plan priced
|
|
196
|
-
notes: list[str]
|
|
197
|
-
next_steps: list[Step] # empty once a plan is applied
|
|
198
|
-
apply: running.Apply | None # a stack apply running now, else None
|
|
199
|
-
gpu_load: list[GpuLoad] # each card's utilization, power and temperature now
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
class Reading(TypedDict):
|
|
203
|
-
"""What one look at the computer found; ``render`` draws it."""
|
|
204
|
-
|
|
205
|
-
hw: Hardware
|
|
206
|
-
plan: StackPlan | None
|
|
207
|
-
liveness: dict[str, tuple[str, str]]
|
|
208
|
-
counters: dict[str, Counters]
|
|
209
|
-
owned: hosts.Owned | None
|
|
210
|
-
events: list[Event]
|
|
211
|
-
measured: dict[str, Measured] # by task
|
|
212
|
-
source: str # live | demo
|
|
213
|
-
generated_at: str
|
|
214
|
-
apply: journal.Live | None
|
|
215
|
-
gpu_load: list[GpuLoad]
|
|
216
|
-
slots: dict[str, list[Slot]] # by deployment name
|
|
217
|
-
|
|
218
71
|
|
|
219
72
|
def now() -> str:
|
|
220
73
|
return dt.datetime.now(dt.timezone.utc).isoformat(timespec="seconds")
|
|
@@ -14,13 +14,14 @@ never logged; the page stays read-only either way.
|
|
|
14
14
|
from __future__ import annotations
|
|
15
15
|
|
|
16
16
|
import hmac
|
|
17
|
+
import html
|
|
17
18
|
import ipaddress
|
|
18
19
|
import os
|
|
19
20
|
import re
|
|
20
21
|
import secrets
|
|
21
22
|
import socket
|
|
22
23
|
from http.cookies import SimpleCookie
|
|
23
|
-
from urllib.parse import parse_qs, urlencode, urlsplit, urlunsplit
|
|
24
|
+
from urllib.parse import parse_qs, unquote, urlencode, urlsplit, urlunsplit
|
|
24
25
|
|
|
25
26
|
KEY_ENV = "LOCALMODELS_VIEW_KEY"
|
|
26
27
|
COOKIE = "lm_view_key"
|
|
@@ -98,6 +99,118 @@ class Gate:
|
|
|
98
99
|
rest = [(k, v) for k, vs in parse_qs(parts.query).items() if k != "k" for v in vs]
|
|
99
100
|
return urlunsplit(("", "", parts.path or "/", urlencode(rest), "")) or "/"
|
|
100
101
|
|
|
102
|
+
def wants_html_gate(self, path: str) -> bool:
|
|
103
|
+
"""Whether an unauthenticated GET for ``path`` should return the HTML key-entry gate."""
|
|
104
|
+
if self.key is None:
|
|
105
|
+
return False
|
|
106
|
+
clean = urlsplit(path).path or "/"
|
|
107
|
+
if clean in ("/", "/index.html", "/fleet.html"):
|
|
108
|
+
return True
|
|
109
|
+
if clean.startswith("/h/"):
|
|
110
|
+
name, sep, tail = clean[3:].partition("/")
|
|
111
|
+
decoded = unquote(name)
|
|
112
|
+
return bool(
|
|
113
|
+
sep
|
|
114
|
+
and name
|
|
115
|
+
and "/" not in decoded
|
|
116
|
+
and decoded not in (".", "..")
|
|
117
|
+
and tail in ("", "index.html")
|
|
118
|
+
)
|
|
119
|
+
return False
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def gate_page(title: str, path: str) -> bytes:
|
|
123
|
+
"""A self-contained, script-free HTML form that exchanges the LAN view key for a cookie."""
|
|
124
|
+
parts = urlsplit(path)
|
|
125
|
+
query = parse_qs(parts.query, keep_blank_values=True)
|
|
126
|
+
clean = Gate.clean_path(path)
|
|
127
|
+
clean_parts = urlsplit(clean)
|
|
128
|
+
escaped_title = html.escape(title)
|
|
129
|
+
escaped_clean = html.escape(clean, quote=True)
|
|
130
|
+
hidden = "".join(
|
|
131
|
+
f'<input type="hidden" name="{html.escape(k, quote=True)}" '
|
|
132
|
+
f'value="{html.escape(v, quote=True)}">'
|
|
133
|
+
for k, vs in parse_qs(clean_parts.query, keep_blank_values=True).items()
|
|
134
|
+
for v in vs
|
|
135
|
+
)
|
|
136
|
+
alert = (
|
|
137
|
+
'<p class="err" role="alert">'
|
|
138
|
+
"That view key was not accepted. Check the key printed in the server terminal and try again."
|
|
139
|
+
"</p>\n"
|
|
140
|
+
if "k" in query
|
|
141
|
+
else ""
|
|
142
|
+
)
|
|
143
|
+
body = f"""<!doctype html>
|
|
144
|
+
<html lang="en">
|
|
145
|
+
<head>
|
|
146
|
+
<meta charset="utf-8">
|
|
147
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
148
|
+
<meta name="color-scheme" content="light dark">
|
|
149
|
+
<title>{escaped_title}</title>
|
|
150
|
+
<style>
|
|
151
|
+
:root {{
|
|
152
|
+
color-scheme: light dark;
|
|
153
|
+
--bg: #f4f4f6; --fg: #1c1c21; --fg-2: #4a4a53; --muted: #5e5e68;
|
|
154
|
+
--line: #e3e3e8; --card: #ffffff; --accent: #4f46e5; --accent-fg: #ffffff; --bad: #d70015;
|
|
155
|
+
}}
|
|
156
|
+
@media (prefers-color-scheme: dark) {{
|
|
157
|
+
:root {{
|
|
158
|
+
--bg: #1b1b1e; --fg: #ececf0; --fg-2: #c2c2c9; --muted: #aaaab4;
|
|
159
|
+
--line: #34343a; --card: #232327; --accent: #9b95ff; --accent-fg: #1b1b1e; --bad: #fb7185;
|
|
160
|
+
}}
|
|
161
|
+
}}
|
|
162
|
+
* {{ box-sizing: border-box; }}
|
|
163
|
+
body {{
|
|
164
|
+
margin: 0; min-height: 100vh; display: grid; place-items: center; padding: 20px;
|
|
165
|
+
background: var(--bg); color: var(--fg);
|
|
166
|
+
font: 13px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
|
|
167
|
+
}}
|
|
168
|
+
main {{
|
|
169
|
+
width: 100%; max-width: 420px; padding: 20px; border-radius: 12px;
|
|
170
|
+
background: var(--card); border: 1px solid var(--line);
|
|
171
|
+
}}
|
|
172
|
+
h1 {{ margin: 0 0 8px; font-size: 16px; font-weight: 650; }}
|
|
173
|
+
p {{ margin: 0 0 14px; color: var(--fg-2); }}
|
|
174
|
+
label {{ display: block; margin-bottom: 6px; font-weight: 600; color: var(--fg); }}
|
|
175
|
+
.row {{ display: flex; gap: 8px; }}
|
|
176
|
+
input[type="password"] {{
|
|
177
|
+
flex: 1; min-width: 0; height: 34px; padding: 0 10px; border-radius: 8px;
|
|
178
|
+
border: 1px solid var(--line); background: var(--bg); color: var(--fg); font: inherit;
|
|
179
|
+
}}
|
|
180
|
+
input[type="password"]:focus-visible, button:focus-visible, a:focus-visible {{
|
|
181
|
+
outline: 2px solid var(--accent); outline-offset: 2px;
|
|
182
|
+
}}
|
|
183
|
+
button {{
|
|
184
|
+
height: 34px; padding: 0 14px; border: 0; border-radius: 8px; cursor: pointer;
|
|
185
|
+
background: var(--accent); color: var(--accent-fg); font: inherit; font-weight: 600;
|
|
186
|
+
}}
|
|
187
|
+
.err {{
|
|
188
|
+
margin: 0 0 14px; padding: 8px 10px; border-radius: 8px;
|
|
189
|
+
border: 1px solid color-mix(in srgb, var(--bad) 45%, var(--line));
|
|
190
|
+
background: color-mix(in srgb, var(--bad) 8%, var(--card)); color: var(--bad);
|
|
191
|
+
}}
|
|
192
|
+
.hint {{ margin: 14px 0 0; font-size: 12px; color: var(--muted); }}
|
|
193
|
+
.hint a {{ color: var(--accent); }}
|
|
194
|
+
</style>
|
|
195
|
+
</head>
|
|
196
|
+
<body>
|
|
197
|
+
<main>
|
|
198
|
+
<h1>{escaped_title}</h1>
|
|
199
|
+
<p>Enter the view key printed when this server started with --lan.</p>
|
|
200
|
+
{alert}<form method="get" action="{escaped_clean}">
|
|
201
|
+
{hidden}<label for="view-key">View key</label>
|
|
202
|
+
<div class="row">
|
|
203
|
+
<input id="view-key" name="k" type="password" required autofocus autocomplete="current-password">
|
|
204
|
+
<button type="submit">Open</button>
|
|
205
|
+
</div>
|
|
206
|
+
</form>
|
|
207
|
+
<p class="hint">Opened from another app? <a href="{escaped_clean}">Reload on this site</a> if your browser already saved the view key.</p>
|
|
208
|
+
</main>
|
|
209
|
+
</body>
|
|
210
|
+
</html>
|
|
211
|
+
"""
|
|
212
|
+
return body.encode("utf-8")
|
|
213
|
+
|
|
101
214
|
|
|
102
215
|
def lan_addresses() -> list[str]:
|
|
103
216
|
"""This computer's addresses another one on the LAN may use: the outbound interface first,
|
|
@@ -19,7 +19,6 @@ import datetime as dt
|
|
|
19
19
|
import gzip
|
|
20
20
|
import hashlib
|
|
21
21
|
import json
|
|
22
|
-
import os
|
|
23
22
|
import signal
|
|
24
23
|
import ssl
|
|
25
24
|
import sys
|
|
@@ -32,7 +31,7 @@ from pathlib import Path
|
|
|
32
31
|
from typing import TypedDict
|
|
33
32
|
from urllib.parse import urlsplit
|
|
34
33
|
|
|
35
|
-
from localmodels import cli_help, hosts, stack_view, stack_view_demo
|
|
34
|
+
from localmodels import cli_help, hosts, http_local, stack_view, stack_view_demo
|
|
36
35
|
from localmodels import stack_view_service as service_kind
|
|
37
36
|
from localmodels.stack_view_hub import MACHINE_HEADER
|
|
38
37
|
from localmodels.stack_view_serve import LiveReader
|
|
@@ -67,14 +66,7 @@ def hub_url(value: str) -> str:
|
|
|
67
66
|
return value.strip().rstrip("/")
|
|
68
67
|
|
|
69
68
|
|
|
70
|
-
|
|
71
|
-
path.parent.mkdir(parents=True, exist_ok=True)
|
|
72
|
-
path.parent.chmod(0o700)
|
|
73
|
-
temporary = path.with_name(f".{path.name}.{os.getpid()}.tmp")
|
|
74
|
-
fd = os.open(temporary, os.O_WRONLY | os.O_CREAT | os.O_TRUNC | os.O_NOFOLLOW, 0o600)
|
|
75
|
-
with os.fdopen(fd, "w", encoding="utf-8") as handle:
|
|
76
|
-
handle.write(text)
|
|
77
|
-
os.replace(temporary, path)
|
|
69
|
+
_write_private = http_local.write_private_text
|
|
78
70
|
|
|
79
71
|
|
|
80
72
|
def read_config(root: Path) -> Config | None:
|
|
@@ -104,9 +96,7 @@ def _opener(ca_file: str | None = None) -> urllib.request.OpenerDirector:
|
|
|
104
96
|
context = ssl.create_default_context(cafile=ca_file)
|
|
105
97
|
except (OSError, ssl.SSLError) as exc:
|
|
106
98
|
raise AgentError(f"cannot read the CA file {ca_file}: {exc}") from None
|
|
107
|
-
return urllib.request.
|
|
108
|
-
urllib.request.ProxyHandler({}), urllib.request.HTTPSHandler(context=context)
|
|
109
|
-
)
|
|
99
|
+
return http_local.no_proxy_opener(urllib.request.HTTPSHandler(context=context))
|
|
110
100
|
|
|
111
101
|
|
|
112
102
|
def machine() -> str:
|
|
@@ -38,9 +38,9 @@ from pathlib import Path
|
|
|
38
38
|
from typing import Any, TypedDict, cast
|
|
39
39
|
from urllib.parse import urlsplit
|
|
40
40
|
|
|
41
|
-
from localmodels import hosts, stack_view_text
|
|
41
|
+
from localmodels import hosts, http_local, stack_view_text
|
|
42
42
|
from localmodels.stack_view import SCHEMA, StackView
|
|
43
|
-
from localmodels.stack_view_access import KEY_ENV, Gate, lan_addresses, run_key
|
|
43
|
+
from localmodels.stack_view_access import KEY_ENV, Gate, gate_page, lan_addresses, run_key
|
|
44
44
|
from localmodels.stack_view_serve import (
|
|
45
45
|
FILES,
|
|
46
46
|
FORBIDDEN,
|
|
@@ -81,14 +81,7 @@ def hub_dir() -> Path:
|
|
|
81
81
|
return hosts.state_dir() / "view-hub"
|
|
82
82
|
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
path.parent.mkdir(parents=True, exist_ok=True)
|
|
86
|
-
path.parent.chmod(0o700)
|
|
87
|
-
temporary = path.with_name(f".{path.name}.{os.getpid()}.tmp")
|
|
88
|
-
fd = os.open(temporary, os.O_WRONLY | os.O_CREAT | os.O_TRUNC | os.O_NOFOLLOW, 0o600)
|
|
89
|
-
with os.fdopen(fd, "w", encoding="utf-8") as handle:
|
|
90
|
-
handle.write(text)
|
|
91
|
-
os.replace(temporary, path)
|
|
84
|
+
write_private = http_local.write_private_text
|
|
92
85
|
|
|
93
86
|
|
|
94
87
|
def _digest(token: str) -> str:
|
|
@@ -469,6 +462,12 @@ class HubHandler(BaseHTTPRequestHandler):
|
|
|
469
462
|
def do_GET(self) -> None:
|
|
470
463
|
peer, host = self.client_address[0], self.headers.get("Host")
|
|
471
464
|
if not self.gate.admit(peer, host, self.path, self.headers.get("Cookie")):
|
|
465
|
+
if self.command == "GET" and self.gate.wants_html_gate(self.path):
|
|
466
|
+
return self._send(
|
|
467
|
+
HTTPStatus.FORBIDDEN,
|
|
468
|
+
gate_page("localmodels - view hub", self.path),
|
|
469
|
+
"text/html; charset=utf-8",
|
|
470
|
+
)
|
|
472
471
|
return self._send(HTTPStatus.FORBIDDEN, FORBIDDEN, "text/plain; charset=utf-8")
|
|
473
472
|
if cookie := self.gate.set_cookie(self.path):
|
|
474
473
|
self.send_response(HTTPStatus.SEE_OTHER)
|
|
@@ -15,7 +15,7 @@ def _int(value: object) -> int:
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
def catalog_entry(model_id: str) -> cat.CatalogEntry | None:
|
|
18
|
-
return
|
|
18
|
+
return cat.find_entry(model_id)
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
def llm_parts(part: Plan, window: int | None = None) -> dict[str, int]:
|
|
@@ -156,8 +156,8 @@ def plan_flags(options: StackOptions) -> list[str]:
|
|
|
156
156
|
tasks = options.get("aux_tasks")
|
|
157
157
|
flags += ["--aux", ",".join(tasks) if tasks else "auto"]
|
|
158
158
|
flags += [flag for key, flag in SWITCHES if recorded.get(key)]
|
|
159
|
-
if options.get("search")
|
|
160
|
-
flags.append("--
|
|
159
|
+
if options.get("search"):
|
|
160
|
+
flags.append("--search")
|
|
161
161
|
gateway = options.get("gateway", "magpie") # absent: a plan from before the choice, Magpie
|
|
162
162
|
if gateway != harness.DEFAULT_GATEWAY:
|
|
163
163
|
flags += ["--gateway", gateway]
|