@simplexai/localmodels-linux-x64 0.1.0-dev.36 → 0.1.0-dev.38
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 +132 -110
- package/kit.py +1 -0
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/__main__.py +9 -3
- package/modules/localmodels/bifrost_checks.py +9 -6
- package/modules/localmodels/bifrost_config.py +203 -0
- package/modules/localmodels/bifrost_datasheet.py +12 -2
- package/modules/localmodels/budget.py +13 -2
- package/modules/localmodels/catalog.json +137 -2
- package/modules/localmodels/catalog.py +70 -321
- package/modules/localmodels/catalog_add.py +2 -8
- package/modules/localmodels/catalog_recipes.py +352 -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/gateway.py +21 -155
- package/modules/localmodels/gateway_accept.py +201 -0
- package/modules/localmodels/gateway_bifrost.py +30 -193
- package/modules/localmodels/gateway_cli.py +15 -6
- 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 +20 -9
- package/modules/localmodels/library_jobs.py +125 -28
- package/modules/localmodels/library_model.py +10 -0
- package/modules/localmodels/library_pricing.py +29 -22
- package/modules/localmodels/library_serve.py +17 -1
- package/modules/localmodels/library_state.py +15 -2
- package/modules/localmodels/library_status.py +30 -0
- package/modules/localmodels/llm_rank.py +185 -39
- package/modules/localmodels/probe.py +108 -174
- package/modules/localmodels/process_identity.py +120 -154
- package/modules/localmodels/process_windows.py +86 -0
- package/modules/localmodels/recommend.py +6 -3
- package/modules/localmodels/recommend_cli.py +14 -6
- package/modules/localmodels/remote_ops.py +65 -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/search_server.py +5 -1
- 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 +45 -235
- package/modules/localmodels/stack_arena.py +732 -0
- package/modules/localmodels/stack_args.py +21 -12
- 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 +288 -0
- package/modules/localmodels/stack_compose.py +63 -30
- package/modules/localmodels/stack_console.py +9 -6
- package/modules/localmodels/stack_hardware.py +95 -265
- 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_llm_ram.py +16 -6
- package/modules/localmodels/stack_mcp.py +729 -0
- package/modules/localmodels/stack_memory.py +0 -2
- package/modules/localmodels/stack_picks.py +62 -15
- package/modules/localmodels/stack_plan.py +19 -1
- package/modules/localmodels/stack_preflight.py +11 -19
- package/modules/localmodels/stack_progress.py +9 -1
- package/modules/localmodels/stack_remove.py +373 -0
- package/modules/localmodels/stack_route.py +101 -17
- package/modules/localmodels/stack_run.py +29 -0
- package/modules/localmodels/stack_suite.py +21 -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 +48 -4
- package/modules/localmodels/stack_warm_store.py +517 -0
- package/modules/localmodels/tools.json +32 -18
- package/modules/localmodels/transport.py +38 -13
- 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/localmodels/windows_job.py +69 -0
- package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/RECORD +128 -106
- 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.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"""Acceptance and Magpie usage-log checks for the stack gateway."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import csv
|
|
6
|
+
import io
|
|
7
|
+
import subprocess
|
|
8
|
+
import tempfile
|
|
9
|
+
import time
|
|
10
|
+
import urllib.error
|
|
11
|
+
import uuid
|
|
12
|
+
from collections.abc import Callable
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from localmodels import gateway_clients, harness, harness_gateway
|
|
16
|
+
from localmodels.contracts import decode
|
|
17
|
+
from localmodels.gateway_requests import PI_ACCEPT_FLAGS, AuxEndpoint, aux_answer, post, text
|
|
18
|
+
from localmodels.gateway_search import SEARCH, Check, search_checks, search_url
|
|
19
|
+
from localmodels.harness import HarnessPlan, ToolPlan
|
|
20
|
+
from localmodels.remote_ops import DECISION_QUESTION, DECISION_STATE, TOUCH_EXPECT, TOUCH_PROMPT
|
|
21
|
+
|
|
22
|
+
PostFn = Callable[[str, dict[str, object], str, float], dict[str, Any]]
|
|
23
|
+
MagpieFn = Callable[..., subprocess.CompletedProcess[str]]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def check_decision(
|
|
27
|
+
url: str, model: str, key: str, timeout: float = 120, *, post_fn: PostFn = post
|
|
28
|
+
) -> Check:
|
|
29
|
+
"""The same readiness question remote_ops asks a decision model this tool deploys."""
|
|
30
|
+
name = f"decision {url}/systemone"
|
|
31
|
+
try:
|
|
32
|
+
resp = post_fn(
|
|
33
|
+
f"{url}/systemone",
|
|
34
|
+
{
|
|
35
|
+
"model": model,
|
|
36
|
+
"state": DECISION_STATE,
|
|
37
|
+
"questions": {"outage": DECISION_QUESTION},
|
|
38
|
+
},
|
|
39
|
+
key,
|
|
40
|
+
timeout,
|
|
41
|
+
)
|
|
42
|
+
except (urllib.error.URLError, OSError, ValueError) as exc:
|
|
43
|
+
return {"check": name, "ok": False, "detail": f"{type(exc).__name__}: {exc}"}
|
|
44
|
+
answers = resp.get("answers")
|
|
45
|
+
answer = answers.get("outage") if isinstance(answers, dict) else None
|
|
46
|
+
noul = answer.get("noul") if isinstance(answer, dict) else None
|
|
47
|
+
ok = isinstance(noul, int | float) and not isinstance(noul, bool) and 0.5 < noul <= 1
|
|
48
|
+
return {"check": name, "ok": ok, "detail": f"noul={noul}"}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def logged_calls(
|
|
52
|
+
plan: ToolPlan, provider: str, kind: str | None = None, *, magpie: MagpieFn
|
|
53
|
+
) -> int | None:
|
|
54
|
+
"""Successful calls to ``provider`` in Magpie's usage log, only those of ``kind`` if given
|
|
55
|
+
(``routing`` for classifier calls; an embedding or rerank call has none)."""
|
|
56
|
+
out = magpie(plan, "usage", "--csv", "--last", "6h", timeout=60)
|
|
57
|
+
if out.returncode != 0:
|
|
58
|
+
return None
|
|
59
|
+
rows = list(csv.DictReader(io.StringIO(out.stdout)))
|
|
60
|
+
if rows and "kind" not in rows[0]:
|
|
61
|
+
return None
|
|
62
|
+
return len(
|
|
63
|
+
[
|
|
64
|
+
r
|
|
65
|
+
for r in rows
|
|
66
|
+
if r.get("provider") == provider
|
|
67
|
+
and (kind is None or r.get("kind") == kind)
|
|
68
|
+
and r.get("status") == "200"
|
|
69
|
+
]
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def logged_after(
|
|
74
|
+
plan: ToolPlan,
|
|
75
|
+
provider: str,
|
|
76
|
+
kind: str | None,
|
|
77
|
+
before: int | None,
|
|
78
|
+
*,
|
|
79
|
+
calls_fn: Callable[[ToolPlan, str, str | None], int | None],
|
|
80
|
+
) -> int | None:
|
|
81
|
+
after = before
|
|
82
|
+
for _ in range(10): # the usage log is written just after the reply
|
|
83
|
+
after = calls_fn(plan, provider, kind)
|
|
84
|
+
if before is None or after is None or after > before:
|
|
85
|
+
break
|
|
86
|
+
time.sleep(1)
|
|
87
|
+
return after
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def accept(
|
|
91
|
+
plan: HarnessPlan,
|
|
92
|
+
decision_key: str | None,
|
|
93
|
+
aux: list[AuxEndpoint],
|
|
94
|
+
timeout: float = 600,
|
|
95
|
+
*,
|
|
96
|
+
aux_providers: dict[str, str],
|
|
97
|
+
is_bifrost: bool,
|
|
98
|
+
post_fn: PostFn = post,
|
|
99
|
+
magpie: MagpieFn,
|
|
100
|
+
run_tool: Callable[..., subprocess.CompletedProcess[str]],
|
|
101
|
+
tool_path: Callable[[ToolPlan, str], str],
|
|
102
|
+
calls_fn: Callable[[ToolPlan, str, str | None], int | None],
|
|
103
|
+
after_fn: Callable[[ToolPlan, str, str | None, int | None], int | None],
|
|
104
|
+
) -> list[Check]:
|
|
105
|
+
"""Each claim needs a request: provider tests through Magpie, one routed turn through the
|
|
106
|
+
gateway (the decision model must be consulted), one embedding, rerank or transcription request
|
|
107
|
+
per wired auxiliary (Magpie's usage log must gain its row), and one pi prompt with the stack's model.
|
|
108
|
+
A Bifrost plan is accepted by ``bifrost_checks.accept``."""
|
|
109
|
+
if is_bifrost:
|
|
110
|
+
from localmodels import bifrost_checks
|
|
111
|
+
|
|
112
|
+
return bifrost_checks.accept(plan, decision_key, aux, timeout)
|
|
113
|
+
gw = plan["gateway"]
|
|
114
|
+
checks: list[Check] = []
|
|
115
|
+
|
|
116
|
+
def check(name: str, ok: bool, detail: str) -> None:
|
|
117
|
+
checks.append({"check": name, "ok": ok, "detail": detail[-300:]})
|
|
118
|
+
|
|
119
|
+
def provider_test(pid: str, kind: str) -> None:
|
|
120
|
+
out = magpie(plan, "provider", "test", pid, timeout=timeout)
|
|
121
|
+
lines = [ln.strip() for ln in out.stdout.splitlines() if kind in ln]
|
|
122
|
+
check(
|
|
123
|
+
f"magpie provider test {pid}",
|
|
124
|
+
out.returncode == 0 and any("✓" in ln for ln in lines),
|
|
125
|
+
"; ".join(lines) or out.stderr.strip()[-200:],
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
provider_test(gw["llm_provider"], "chat")
|
|
129
|
+
if gw["decision"] is not None and decision_key is not None:
|
|
130
|
+
provider_test(gw["decision_provider"], "decide")
|
|
131
|
+
routed = gw["decision"] is not None and decision_key is not None
|
|
132
|
+
decider = gw["decision_provider"]
|
|
133
|
+
before = calls_fn(plan, decider, "routing") if routed else None
|
|
134
|
+
# Magpie remembers a classified message's intent; a fresh nonce per run reaches the classifier.
|
|
135
|
+
prompt = f"{TOUCH_PROMPT} (check {uuid.uuid4().hex[:8]})"
|
|
136
|
+
try:
|
|
137
|
+
harness_gateway.require_target(plan)
|
|
138
|
+
resp = post_fn(
|
|
139
|
+
f"http://{gw['addr']}/v1/chat/completions",
|
|
140
|
+
{
|
|
141
|
+
"model": f"group/{gw['group']}",
|
|
142
|
+
"messages": [{"role": "user", "content": prompt}],
|
|
143
|
+
"max_tokens": 512,
|
|
144
|
+
"temperature": 0,
|
|
145
|
+
},
|
|
146
|
+
"magpie",
|
|
147
|
+
timeout,
|
|
148
|
+
)
|
|
149
|
+
answer = text(resp)
|
|
150
|
+
check(f"gateway group/{gw['group']}", TOUCH_EXPECT in answer.lower(), answer.strip()[:200])
|
|
151
|
+
except (urllib.error.URLError, OSError, ValueError) as exc:
|
|
152
|
+
check(f"gateway group/{gw['group']}", False, f"{type(exc).__name__}: {exc}")
|
|
153
|
+
if routed:
|
|
154
|
+
after = after_fn(plan, decider, "routing", before)
|
|
155
|
+
check(
|
|
156
|
+
"gateway consulted decision model",
|
|
157
|
+
before is not None and after is not None and after > before,
|
|
158
|
+
f"Magpie routing calls to {decider}: {before} → {after}",
|
|
159
|
+
)
|
|
160
|
+
for ep in aux:
|
|
161
|
+
if ep["contract"] == SEARCH:
|
|
162
|
+
checks += search_checks(plan, search_url(ep), timeout)
|
|
163
|
+
continue
|
|
164
|
+
pid = aux_providers[ep["contract"]]
|
|
165
|
+
name = f"gateway {ep['contract']} {pid}/{ep['model']}"
|
|
166
|
+
before = calls_fn(plan, pid, None)
|
|
167
|
+
try:
|
|
168
|
+
harness_gateway.require_target(plan)
|
|
169
|
+
check(name, *aux_answer(gw["addr"], ep, f"{pid}/{ep['model']}", timeout))
|
|
170
|
+
except (urllib.error.URLError, OSError, ValueError) as exc:
|
|
171
|
+
check(name, False, f"{type(exc).__name__}: {exc}")
|
|
172
|
+
continue
|
|
173
|
+
after = after_fn(plan, pid, None, before)
|
|
174
|
+
check(
|
|
175
|
+
f"Magpie logged {ep['contract']}",
|
|
176
|
+
before is not None and after is not None and after > before,
|
|
177
|
+
f"Magpie calls to {pid}: {before} → {after}",
|
|
178
|
+
)
|
|
179
|
+
pi = tool_path(plan, "pi")
|
|
180
|
+
env = harness.checked_gateway_environment(plan)
|
|
181
|
+
loopback = "127.0.0.1,localhost"
|
|
182
|
+
env["NO_PROXY"] = env["no_proxy"] = ",".join(x for x in (env.get("NO_PROXY"), loopback) if x)
|
|
183
|
+
with tempfile.TemporaryDirectory(prefix="localmodels-pi-") as cwd:
|
|
184
|
+
out = run_tool([pi, *PI_ACCEPT_FLAGS, TOUCH_PROMPT], timeout=timeout, cwd=cwd, env=env)
|
|
185
|
+
check(
|
|
186
|
+
"pi -p via Magpie",
|
|
187
|
+
out.returncode == 0 and TOUCH_EXPECT in out.stdout.lower(),
|
|
188
|
+
(out.stdout.strip() or out.stderr.strip())[-200:],
|
|
189
|
+
)
|
|
190
|
+
checks += [
|
|
191
|
+
decode(result, Check)
|
|
192
|
+
for result in gateway_clients.accept(
|
|
193
|
+
plan,
|
|
194
|
+
TOUCH_PROMPT,
|
|
195
|
+
TOUCH_EXPECT,
|
|
196
|
+
timeout,
|
|
197
|
+
lambda: calls_fn(plan, gw["llm_provider"], None),
|
|
198
|
+
lambda b: after_fn(plan, gw["llm_provider"], None, b),
|
|
199
|
+
)
|
|
200
|
+
]
|
|
201
|
+
return checks
|
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import contextlib
|
|
6
|
-
import json
|
|
7
6
|
import os
|
|
8
7
|
import secrets
|
|
9
8
|
import shutil
|
|
10
|
-
import signal
|
|
11
9
|
import subprocess
|
|
12
10
|
import time
|
|
13
11
|
import urllib.error
|
|
@@ -19,7 +17,6 @@ from typing import Any
|
|
|
19
17
|
|
|
20
18
|
from localmodels import (
|
|
21
19
|
bifrost_datasheet,
|
|
22
|
-
bifrost_provider,
|
|
23
20
|
bifrost_search,
|
|
24
21
|
bifrost_unit,
|
|
25
22
|
gateway_keys,
|
|
@@ -27,15 +24,27 @@ from localmodels import (
|
|
|
27
24
|
harness_gateway,
|
|
28
25
|
harness_probe,
|
|
29
26
|
hosts,
|
|
27
|
+
http_local,
|
|
30
28
|
process_identity,
|
|
31
29
|
remote_ops_service,
|
|
32
30
|
)
|
|
31
|
+
from localmodels.bifrost_config import ADMIN_USER as ADMIN_USER
|
|
32
|
+
from localmodels.bifrost_config import AGENT_RULE as AGENT_RULE
|
|
33
|
+
from localmodels.bifrost_config import AUX_PROVIDERS as AUX_PROVIDERS
|
|
34
|
+
from localmodels.bifrost_config import COMPLEX_RULE as COMPLEX_RULE
|
|
35
|
+
from localmodels.bifrost_config import DECISION_TIMEOUT as DECISION_TIMEOUT
|
|
36
|
+
from localmodels.bifrost_config import FAST_PROVIDER as FAST_PROVIDER
|
|
37
|
+
from localmodels.bifrost_config import LOG_BATCH_INTERVAL as LOG_BATCH_INTERVAL
|
|
38
|
+
from localmodels.bifrost_config import STORE as STORE
|
|
39
|
+
from localmodels.bifrost_config import read_config as read_config
|
|
40
|
+
from localmodels.bifrost_config import render as render
|
|
41
|
+
from localmodels.bifrost_config import render_config as render_config
|
|
42
|
+
from localmodels.bifrost_config import write_config as write_config
|
|
33
43
|
from localmodels.bifrost_provider import origin as origin
|
|
34
44
|
from localmodels.bifrost_unit import unit, unit_file, unit_for
|
|
35
45
|
from localmodels.gateway_requests import AuxEndpoint
|
|
36
46
|
from localmodels.gateway_search import Check
|
|
37
47
|
from localmodels.harness import (
|
|
38
|
-
GatewayPlan,
|
|
39
48
|
HarnessError,
|
|
40
49
|
HarnessPlan,
|
|
41
50
|
ToolAction,
|
|
@@ -44,6 +53,8 @@ from localmodels.harness import (
|
|
|
44
53
|
ToolState,
|
|
45
54
|
)
|
|
46
55
|
|
|
56
|
+
_write_config = write_config
|
|
57
|
+
|
|
47
58
|
APP_DIR = "~/.local/share/localmodels/bifrost"
|
|
48
59
|
# The routed model, named like Magpie's routing group: Codex, pi and Claude Code all send it, and
|
|
49
60
|
# the LLM's key lists it and the routing rules match it. No Claude-specific name: Claude Code reads
|
|
@@ -51,31 +62,8 @@ APP_DIR = "~/.local/share/localmodels/bifrost"
|
|
|
51
62
|
AGENT_MODEL = harness.GROUP
|
|
52
63
|
PI_PROVIDER = "localmodels"
|
|
53
64
|
PI_MODEL = f"{PI_PROVIDER}/{AGENT_MODEL}"
|
|
54
|
-
ADMIN_USER = "localmodels"
|
|
55
65
|
CALLER_KEY = gateway_keys.CALLER_KEY # clients send it; loopback inference checks no key
|
|
56
|
-
LOG_BATCH_INTERVAL = "250ms" # logs_store.writer.batch_interval; Bifrost's default is 5s
|
|
57
|
-
STORE = ("config.db", "config.db-wal", "config.db-shm") # derived from config.json and datasheets
|
|
58
|
-
COMPLEX_RULE = "localmodels-agent-complex"
|
|
59
|
-
AGENT_RULE = "localmodels-agent"
|
|
60
|
-
FAST_PROVIDER = "localmodels-llm-fast"
|
|
61
|
-
DECISION_TIMEOUT = "10s"
|
|
62
66
|
HEALTH_TIMEOUT_S = 180.0
|
|
63
|
-
# The auxiliaries Bifrost serves, by endpoint contract, under the provider ids Magpie used.
|
|
64
|
-
AUX_PROVIDERS = {
|
|
65
|
-
"embedding": "localmodels-embedding",
|
|
66
|
-
"rerank": "localmodels-rerank",
|
|
67
|
-
"stt": "localmodels-stt",
|
|
68
|
-
}
|
|
69
|
-
# The analyzer requires keyword lists even when the decision model classifies; they only decide
|
|
70
|
-
# when it does not answer, so a few plain words suffice.
|
|
71
|
-
_KEYWORDS = {
|
|
72
|
-
"simple_keywords": ["hello", "thanks", "what is"],
|
|
73
|
-
"medium_keywords": ["explain", "summarize", "write"],
|
|
74
|
-
"complex_keywords": ["refactor", "debug", "design", "architecture"],
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
_AGENT_MATCH = f"model == '{AGENT_MODEL}'"
|
|
79
67
|
|
|
80
68
|
|
|
81
69
|
def plan_tools(
|
|
@@ -93,7 +81,8 @@ def plan_tools(
|
|
|
93
81
|
raise HarnessError("the tool lock has no Bifrost")
|
|
94
82
|
build = harness.tool_build(lock["bifrost"]["builds"], platform, arch, "Bifrost")
|
|
95
83
|
version = lock["bifrost"]["version"]
|
|
96
|
-
|
|
84
|
+
# Windows starts only a file named .exe; the npm package and the CDN name it bifrost-http.
|
|
85
|
+
binary = f"{tools_dir}/bifrost-{version}/bifrost-http" + (".exe" if platform == "win32" else "")
|
|
97
86
|
found = os.path.expanduser(binary)
|
|
98
87
|
if os.path.lexists(found) and harness.digest(found) != build["sha256"]:
|
|
99
88
|
raise HarnessError(f"{binary} is not the pinned Bifrost {version}; deal with it first")
|
|
@@ -107,7 +96,7 @@ def plan_tools(
|
|
|
107
96
|
addr = state.get("bifrost_addr") or harness.bifrost_addr()
|
|
108
97
|
listeners = set(state.get("bifrost_listeners", []))
|
|
109
98
|
ours = hosts.load_owned(tools_dir)["gateway"].get("bifrost")
|
|
110
|
-
if listeners - {
|
|
99
|
+
if listeners - {process_identity.current_uid()}:
|
|
111
100
|
raise HarnessError(
|
|
112
101
|
f"Bifrost address {addr} is held by another user's program; ask them to free it, or "
|
|
113
102
|
"set LOCALMODELS_BIFROST_ADDR=127.0.0.1:<free port> in this terminal and plan again"
|
|
@@ -192,7 +181,8 @@ def install_binary(tools_dir: Path, action: ToolAction, log: Callable[[str], Non
|
|
|
192
181
|
|
|
193
182
|
|
|
194
183
|
def app_dir() -> Path:
|
|
195
|
-
|
|
184
|
+
override = os.environ.get("LOCALMODELS_BIFROST_DIR", "").strip()
|
|
185
|
+
return Path(os.path.expanduser(override or APP_DIR))
|
|
196
186
|
|
|
197
187
|
|
|
198
188
|
def _seal(app: Path) -> None:
|
|
@@ -217,160 +207,6 @@ def admin_password(app: Path | None = None) -> str:
|
|
|
217
207
|
return value
|
|
218
208
|
|
|
219
209
|
|
|
220
|
-
def render(
|
|
221
|
-
gw: GatewayPlan,
|
|
222
|
-
llm_key: str,
|
|
223
|
-
decision_key: str | None,
|
|
224
|
-
aux: list[AuxEndpoint],
|
|
225
|
-
app: Path,
|
|
226
|
-
password: str,
|
|
227
|
-
keep: dict[str, Any] | None = None,
|
|
228
|
-
*,
|
|
229
|
-
fast_key: str | None = None,
|
|
230
|
-
) -> dict[str, Any]:
|
|
231
|
-
"""The config.json for one approved plan, before ``bifrost_search.inject``. ``keep`` carries
|
|
232
|
-
providers of an earlier config this call does not manage (a re-sync keeps the STT provider)."""
|
|
233
|
-
llm = gw["llm"]
|
|
234
|
-
providers: dict[str, Any] = dict(keep or {})
|
|
235
|
-
providers[gw["llm_provider"]] = bifrost_provider.render(
|
|
236
|
-
"llm", llm["url"], llm["model"], llm_key, gw["llm_provider"]
|
|
237
|
-
)
|
|
238
|
-
decision = gw["decision"] if decision_key is not None else None
|
|
239
|
-
if decision is not None and decision_key is not None:
|
|
240
|
-
providers[gw["decision_provider"]] = bifrost_provider.render(
|
|
241
|
-
"decision", decision["url"], decision["model"], decision_key, gw["decision_provider"]
|
|
242
|
-
)
|
|
243
|
-
for ep in aux:
|
|
244
|
-
pid = AUX_PROVIDERS.get(str(ep.get("contract")))
|
|
245
|
-
if pid:
|
|
246
|
-
providers[pid] = bifrost_provider.render(
|
|
247
|
-
str(ep["contract"]), str(ep["url"]), str(ep["model"]), str(ep["key"]), pid
|
|
248
|
-
)
|
|
249
|
-
target = {"provider": gw["llm_provider"], "model": llm["model"], "weight": 1}
|
|
250
|
-
default_target = target
|
|
251
|
-
if fast := gw.get("llm_fast"):
|
|
252
|
-
if decision is None or not fast_key:
|
|
253
|
-
raise HarnessError("two-LLM routing requires both LLM keys and a ready decision model")
|
|
254
|
-
providers[FAST_PROVIDER] = bifrost_provider.render(
|
|
255
|
-
"llm", fast["url"], fast["model"], fast_key, FAST_PROVIDER
|
|
256
|
-
)
|
|
257
|
-
default_target = {"provider": FAST_PROVIDER, "model": fast["model"], "weight": 1}
|
|
258
|
-
rules: list[dict[str, Any]] = []
|
|
259
|
-
governance: dict[str, Any] = {
|
|
260
|
-
"auth_config": {
|
|
261
|
-
"is_enabled": True,
|
|
262
|
-
"admin_username": ADMIN_USER,
|
|
263
|
-
"admin_password": password,
|
|
264
|
-
"disable_auth_on_inference": True,
|
|
265
|
-
},
|
|
266
|
-
}
|
|
267
|
-
if decision is not None:
|
|
268
|
-
rules.append(
|
|
269
|
-
{
|
|
270
|
-
"id": COMPLEX_RULE,
|
|
271
|
-
"name": COMPLEX_RULE,
|
|
272
|
-
"description": "hard turns, as the decision model classifies them",
|
|
273
|
-
"cel_expression": f"{_AGENT_MATCH} && complexity_tier == 'COMPLEX'",
|
|
274
|
-
"targets": [target],
|
|
275
|
-
"priority": 0,
|
|
276
|
-
}
|
|
277
|
-
)
|
|
278
|
-
governance["complexity_analyzer_config"] = {
|
|
279
|
-
"keywords": _KEYWORDS,
|
|
280
|
-
"classifier": "decision",
|
|
281
|
-
"decision": {
|
|
282
|
-
"provider": gw["decision_provider"],
|
|
283
|
-
"model": decision["model"],
|
|
284
|
-
"timeout": DECISION_TIMEOUT,
|
|
285
|
-
"previous_message_count": 1,
|
|
286
|
-
},
|
|
287
|
-
}
|
|
288
|
-
rules.append(
|
|
289
|
-
{
|
|
290
|
-
"id": AGENT_RULE,
|
|
291
|
-
"name": AGENT_RULE,
|
|
292
|
-
"description": "local agent turns sent to the local LLM",
|
|
293
|
-
"cel_expression": _AGENT_MATCH,
|
|
294
|
-
"targets": [default_target],
|
|
295
|
-
"priority": 1,
|
|
296
|
-
}
|
|
297
|
-
)
|
|
298
|
-
governance["routing_rules"] = rules
|
|
299
|
-
config = render_config(providers, governance, app)
|
|
300
|
-
config["framework"] = bifrost_datasheet.framework(app)
|
|
301
|
-
return config
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
def render_config(
|
|
305
|
-
providers: dict[str, Any], governance: dict[str, Any], app: Path
|
|
306
|
-
) -> dict[str, Any]:
|
|
307
|
-
"""Shared private storage, management authentication and content logging policy."""
|
|
308
|
-
return {
|
|
309
|
-
"$schema": "https://www.getbifrost.ai/schema",
|
|
310
|
-
"source_of_truth": "config.json",
|
|
311
|
-
"client": {
|
|
312
|
-
"enable_logging": True,
|
|
313
|
-
"disable_content_logging": True,
|
|
314
|
-
"allow_per_request_content_storage_override": False,
|
|
315
|
-
"allow_per_request_raw_override": False,
|
|
316
|
-
"dump_errors_in_console_logs": False,
|
|
317
|
-
"enforce_auth_on_inference": False,
|
|
318
|
-
"max_request_body_size_mb": 32,
|
|
319
|
-
},
|
|
320
|
-
"config_store": {
|
|
321
|
-
"enabled": True,
|
|
322
|
-
"type": "sqlite",
|
|
323
|
-
"config": {"path": str(app / "config.db")},
|
|
324
|
-
},
|
|
325
|
-
"logs_store": {
|
|
326
|
-
"enabled": True,
|
|
327
|
-
"type": "sqlite",
|
|
328
|
-
"config": {"path": str(app / "logs.db")},
|
|
329
|
-
# Bifrost writes its request log in batches, 5 s apart by default; `stack view`
|
|
330
|
-
# reads that log to show calls, so a short interval keeps it close to real time.
|
|
331
|
-
# Measured on the pinned v2.3.0: a call is in the log 5.0 s after it ends by
|
|
332
|
-
# default, 0.2-0.25 s with this (2026-11-03, WHI-511).
|
|
333
|
-
"writer": {"batch_interval": LOG_BATCH_INTERVAL},
|
|
334
|
-
},
|
|
335
|
-
"providers": providers,
|
|
336
|
-
"governance": governance,
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
def read_config(app: Path) -> dict[str, Any]:
|
|
341
|
-
try:
|
|
342
|
-
value = json.loads((app / "config.json").read_text(encoding="utf-8"))
|
|
343
|
-
except (OSError, ValueError):
|
|
344
|
-
return {}
|
|
345
|
-
return value if isinstance(value, dict) else {}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
def _write_config(app: Path, config: dict[str, Any], sheets: dict[str, Any] | None = None) -> bool:
|
|
349
|
-
"""Write config.json (0600), and the datasheets it names when given, where any differs; the
|
|
350
|
-
derived config store goes with them, so providers or windows a new config leaves out cannot
|
|
351
|
-
linger in it, and Bifrost loads the datasheets into the empty store before it answers."""
|
|
352
|
-
files = (sheets or {}) | {"config.json": config}
|
|
353
|
-
changed = False
|
|
354
|
-
for name, value in files.items():
|
|
355
|
-
text = json.dumps(value, ensure_ascii=False, indent=1) + "\n"
|
|
356
|
-
path = app / name
|
|
357
|
-
with contextlib.suppress(OSError):
|
|
358
|
-
if path.read_text(encoding="utf-8") == text:
|
|
359
|
-
continue
|
|
360
|
-
app.mkdir(parents=True, exist_ok=True)
|
|
361
|
-
app.chmod(0o700)
|
|
362
|
-
tmp = path.with_name(f"{name}.tmp")
|
|
363
|
-
fd = os.open(tmp, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
|
|
364
|
-
with os.fdopen(fd, "w", encoding="utf-8") as f:
|
|
365
|
-
f.write(text)
|
|
366
|
-
os.replace(tmp, path)
|
|
367
|
-
changed = True
|
|
368
|
-
if changed:
|
|
369
|
-
for name in STORE:
|
|
370
|
-
(app / name).unlink(missing_ok=True)
|
|
371
|
-
return changed
|
|
372
|
-
|
|
373
|
-
|
|
374
210
|
# ---------------------------------------------------------------------------- running it
|
|
375
211
|
|
|
376
212
|
|
|
@@ -384,7 +220,7 @@ def _addr(plan: ToolPlan) -> str:
|
|
|
384
220
|
|
|
385
221
|
|
|
386
222
|
def opener() -> urllib.request.OpenerDirector:
|
|
387
|
-
return
|
|
223
|
+
return http_local.no_proxy_opener()
|
|
388
224
|
|
|
389
225
|
|
|
390
226
|
def owned_listener(record: hosts.OwnedBifrost) -> bool:
|
|
@@ -425,7 +261,7 @@ def owned_listener(record: hosts.OwnedBifrost) -> bool:
|
|
|
425
261
|
]
|
|
426
262
|
return bool(
|
|
427
263
|
before
|
|
428
|
-
and before["uid"] ==
|
|
264
|
+
and before["uid"] == process_identity.current_uid()
|
|
429
265
|
and remote_ops_service.command_matches(pid, argv)
|
|
430
266
|
and remote_ops_service.listener_problem(harness_gateway.address_port(addr), [pid])
|
|
431
267
|
is None
|
|
@@ -536,23 +372,24 @@ def _start(record: hosts.OwnedBifrost, restart: bool) -> None:
|
|
|
536
372
|
_stop_serve(app) # ours: restarted, or an earlier instance that stopped answering
|
|
537
373
|
host, _, port = addr.rpartition(":")
|
|
538
374
|
env = {**os.environ, "NO_PROXY": "127.0.0.1,localhost", "no_proxy": "127.0.0.1,localhost"}
|
|
375
|
+
options: dict[str, Any] = {"cwd": app, "env": env, "stdin": subprocess.DEVNULL}
|
|
376
|
+
if os.name != "nt":
|
|
377
|
+
options["umask"] = 0o077 # its SQLite stores and log stay private
|
|
539
378
|
with (app / "bifrost.log").open("ab") as log:
|
|
540
|
-
|
|
379
|
+
# Its own session; on Windows also no console, out of the starting job (a scheduled
|
|
380
|
+
# task ends its job's processes), at normal priority, as every service this tool runs.
|
|
381
|
+
proc = process_identity.spawn_detached(
|
|
541
382
|
[record["binary"], "-app-dir", str(app), "-host", host, "-port", port]
|
|
542
383
|
+ ["-log-style", "json", "-log-level", "warn"],
|
|
543
|
-
cwd=app,
|
|
544
|
-
env=env,
|
|
545
|
-
stdin=subprocess.DEVNULL,
|
|
546
384
|
stdout=log,
|
|
547
385
|
stderr=log,
|
|
548
|
-
|
|
549
|
-
umask=0o077, # its SQLite stores and log stay private
|
|
386
|
+
**options,
|
|
550
387
|
)
|
|
551
388
|
try:
|
|
552
389
|
process_identity.save(app / "bifrost.pid", proc.pid)
|
|
553
390
|
except (OSError, RuntimeError, subprocess.TimeoutExpired) as exc:
|
|
554
391
|
with contextlib.suppress(OSError): # not yet reaped, so the group is still ours
|
|
555
|
-
|
|
392
|
+
process_identity.kill_started(proc.pid) # its group; its tree on Windows
|
|
556
393
|
proc.wait(timeout=10)
|
|
557
394
|
raise HarnessError(f"cannot record Bifrost process identity ({exc}); stopped it") from None
|
|
558
395
|
|
|
@@ -19,7 +19,14 @@ import urllib.request
|
|
|
19
19
|
from pathlib import Path
|
|
20
20
|
from typing import Any
|
|
21
21
|
|
|
22
|
-
from localmodels import
|
|
22
|
+
from localmodels import (
|
|
23
|
+
cli_help,
|
|
24
|
+
gateway_bifrost,
|
|
25
|
+
harness,
|
|
26
|
+
http_local,
|
|
27
|
+
runtime_cli,
|
|
28
|
+
runtime_io,
|
|
29
|
+
)
|
|
23
30
|
|
|
24
31
|
SCHEMA = "localmodels.gateway-owned/v1"
|
|
25
32
|
|
|
@@ -79,8 +86,10 @@ def choose_kind(
|
|
|
79
86
|
if choice == "magpie":
|
|
80
87
|
return choice
|
|
81
88
|
platform, arch = runtime_cli._platform().split("-", 1)
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
# Windows keeps Magpie (decisions 32 and 48): its Bifrost build (since localmodels.6) serves
|
|
90
|
+
# the model library, whose own gateway is a different instance; this one is not verified there.
|
|
91
|
+
available = platform != "win32" and any(
|
|
92
|
+
b["platform"] == platform and b["arch"] == arch
|
|
84
93
|
for b in harness.load_lock()["bifrost"]["builds"]
|
|
85
94
|
)
|
|
86
95
|
if choice == "auto" and (not available or runtime is None):
|
|
@@ -191,9 +200,9 @@ def _request(
|
|
|
191
200
|
headers={"Authorization": "Bearer " + key},
|
|
192
201
|
method=method,
|
|
193
202
|
)
|
|
194
|
-
with
|
|
195
|
-
|
|
196
|
-
)
|
|
203
|
+
with http_local.no_proxy_opener(allow_redirects=False).open(
|
|
204
|
+
request, timeout=timeout
|
|
205
|
+
) as response:
|
|
197
206
|
value: dict[str, Any] = json.load(response)
|
|
198
207
|
return value
|
|
199
208
|
|
|
@@ -8,7 +8,7 @@ import urllib.request
|
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
from typing import Any
|
|
10
10
|
|
|
11
|
-
from localmodels import gateway, harness,
|
|
11
|
+
from localmodels import gateway, harness, http_local, runtime_io
|
|
12
12
|
from localmodels.service_jobs import selected_roles
|
|
13
13
|
|
|
14
14
|
|
|
@@ -35,9 +35,7 @@ def status(port: int, key: str) -> dict[str, Any]:
|
|
|
35
35
|
f"http://127.0.0.1:{port}/v1/model-services",
|
|
36
36
|
headers={"Authorization": "Bearer " + key},
|
|
37
37
|
)
|
|
38
|
-
with
|
|
39
|
-
runtime_auth._NoRedirect(), urllib.request.ProxyHandler({})
|
|
40
|
-
).open(request, timeout=2) as response:
|
|
38
|
+
with http_local.no_proxy_opener(allow_redirects=False).open(request, timeout=2) as response:
|
|
41
39
|
value: dict[str, Any] = json.load(response)
|
|
42
40
|
return value
|
|
43
41
|
|
|
@@ -53,7 +53,6 @@ def finding(check: str, level: Level, detail: str, fix: str = "") -> Finding:
|
|
|
53
53
|
return {"check": check, "level": level, "detail": detail, "fix": fix}
|
|
54
54
|
|
|
55
55
|
|
|
56
|
-
MARKS = {"pass": "✓", "warn": "!", "fail": "✗"}
|
|
57
56
|
_LEVELS = {"pass": "ok", "warn": "warn", "fail": "fail"}
|
|
58
57
|
|
|
59
58
|
|
|
@@ -25,6 +25,7 @@ from localmodels import (
|
|
|
25
25
|
gateway_cli,
|
|
26
26
|
gateway_foundations,
|
|
27
27
|
harness,
|
|
28
|
+
http_local,
|
|
28
29
|
runtime_auth,
|
|
29
30
|
runtime_cli,
|
|
30
31
|
runtime_io,
|
|
@@ -229,9 +230,7 @@ def model_ids(port: int) -> list[str]:
|
|
|
229
230
|
request = urllib.request.Request(
|
|
230
231
|
f"http://127.0.0.1:{port}/v1/models", headers={"Authorization": "Bearer magpie"}
|
|
231
232
|
)
|
|
232
|
-
with
|
|
233
|
-
runtime_auth._NoRedirect(), urllib.request.ProxyHandler({})
|
|
234
|
-
).open(request, timeout=2) as response:
|
|
233
|
+
with http_local.no_proxy_opener(allow_redirects=False).open(request, timeout=2) as response:
|
|
235
234
|
value = json.load(response)
|
|
236
235
|
return [
|
|
237
236
|
row["id"]
|
|
@@ -77,6 +77,18 @@ def normalized(name: str) -> str:
|
|
|
77
77
|
return " ".join(_DROPPED.sub(" ", name.lower().replace("-", " ")).split())
|
|
78
78
|
|
|
79
79
|
|
|
80
|
+
def device_class(name: str) -> str:
|
|
81
|
+
"""Canonical device model class for calibration and lower-bound joins; empty when unnamed."""
|
|
82
|
+
key = normalized(name)
|
|
83
|
+
if not key:
|
|
84
|
+
return ""
|
|
85
|
+
if re.fullmatch(r"rtx pro 6000 blackwell( max q)?( workstation| server)?( edition)?", key):
|
|
86
|
+
return "rtx pro 6000 blackwell"
|
|
87
|
+
if key in ("rtx 4090", "rtx 4090 d"):
|
|
88
|
+
return "rtx 4090"
|
|
89
|
+
return key
|
|
90
|
+
|
|
91
|
+
|
|
80
92
|
def bandwidth_gb_s(name: str) -> float | None:
|
|
81
93
|
"""The published memory bandwidth of the card nvidia-smi names ``name``; None: not listed."""
|
|
82
94
|
key = normalized(name)
|
|
@@ -15,7 +15,7 @@ import sys
|
|
|
15
15
|
from pathlib import Path
|
|
16
16
|
from typing import Literal, TypedDict
|
|
17
17
|
|
|
18
|
-
from localmodels import cli_help, probe
|
|
18
|
+
from localmodels import cli_help, http_local, probe
|
|
19
19
|
from localmodels.catalog import ComponentRecipe, component_recipe
|
|
20
20
|
from localmodels.contracts import decode
|
|
21
21
|
from localmodels.privacy import PrivacyError, PrivacySession, Span, parse_spans, strict_json
|
|
@@ -46,12 +46,7 @@ class ArtifactPlan(TypedDict):
|
|
|
46
46
|
plan_id: str
|
|
47
47
|
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
digest = hashlib.sha256()
|
|
51
|
-
with path.open("rb") as stream:
|
|
52
|
-
for chunk in iter(lambda: stream.read(1 << 20), b""):
|
|
53
|
-
digest.update(chunk)
|
|
54
|
-
return digest.hexdigest()
|
|
49
|
+
_sha = http_local.sha256_file
|
|
55
50
|
|
|
56
51
|
|
|
57
52
|
def _digest(plan: ArtifactPlan) -> str:
|