@simplexai/localmodels-darwin-arm64 0.1.0-dev.42 → 0.1.0-dev.44
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 +40 -39
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/auth_proxy.py +285 -82
- package/modules/localmodels/bifrost_models.py +9 -2
- package/modules/localmodels/bifrost_provider.py +42 -7
- package/modules/localmodels/catalog.json +8 -0
- package/modules/localmodels/debug_mode.py +2 -18
- package/modules/localmodels/engines.py +19 -6
- package/modules/localmodels/gateway_bifrost.py +10 -1
- package/modules/localmodels/harness.py +3 -1
- package/modules/localmodels/library_convert.py +491 -57
- package/modules/localmodels/library_gateway.py +15 -7
- package/modules/localmodels/library_pricing.py +159 -31
- package/modules/localmodels/library_status.py +29 -4
- package/modules/localmodels/probe.py +42 -9
- package/modules/localmodels/runtime_args.py +2 -1
- package/modules/localmodels/runtime_auth.py +75 -25
- package/modules/localmodels/runtime_cli.py +9 -9
- package/modules/localmodels/runtime_install.py +55 -22
- package/modules/localmodels/runtime_io.py +76 -210
- package/modules/localmodels/runtime_process.py +15 -7
- package/modules/localmodels/runtime_windows_acl.py +196 -0
- package/modules/localmodels/source_byok.py +116 -30
- package/modules/localmodels/source_byok_probe.py +57 -141
- package/modules/localmodels/source_cli.py +11 -17
- package/modules/localmodels/stack.py +12 -1
- package/modules/localmodels/stack_client_settings.py +8 -1
- package/modules/localmodels/stack_compose.py +1 -0
- package/modules/localmodels/stack_route.py +1 -5
- package/modules/localmodels/stack_up.py +20 -1
- package/modules/localmodels/vision.py +2 -1
- package/modules/localmodels/web/view/view.css +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev42.dist-info → simplex_localmodels-0.1.0.dev44.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev42.dist-info → simplex_localmodels-0.1.0.dev44.dist-info}/RECORD +37 -36
- package/package.json +1 -1
- package/tool.json +1 -1
- /package/modules/{simplex_localmodels-0.1.0.dev42.dist-info → simplex_localmodels-0.1.0.dev44.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev42.dist-info → simplex_localmodels-0.1.0.dev44.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev42.dist-info → simplex_localmodels-0.1.0.dev44.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev42.dist-info → simplex_localmodels-0.1.0.dev44.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""BYOK endpoint
|
|
1
|
+
"""BYOK endpoint checks: one request to the address the user built, and its model list."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
@@ -8,24 +8,20 @@ import urllib.error
|
|
|
8
8
|
import urllib.request
|
|
9
9
|
from typing import Any, TypedDict
|
|
10
10
|
|
|
11
|
-
from localmodels import bifrost_provider
|
|
12
11
|
from localmodels.source_byok import (
|
|
13
12
|
CREDENTIALS_SCHEMA,
|
|
14
13
|
MAX_CONTEXT_WINDOW,
|
|
15
|
-
PROTOCOL_ORDER,
|
|
16
14
|
ByokCredentials,
|
|
17
15
|
ByokEndpoint,
|
|
18
16
|
ByokError,
|
|
19
17
|
Protocol,
|
|
20
|
-
|
|
18
|
+
models_url,
|
|
19
|
+
request_url,
|
|
21
20
|
validate_url,
|
|
22
21
|
)
|
|
23
22
|
|
|
24
23
|
MAX_PROBE_BYTES = 1 << 20
|
|
25
24
|
MAX_LISTED_MODELS = 1000
|
|
26
|
-
# Gateways that serve both API families often put OpenAI under /v1 and Anthropic under
|
|
27
|
-
# /anthropic on one host, so a format missing at the entered URL is also tried there.
|
|
28
|
-
ANTHROPIC_SUFFIX = "/anthropic"
|
|
29
25
|
# The list field each wire format's reply carries, which tells a real reply from a page
|
|
30
26
|
# that answers any path.
|
|
31
27
|
_REPLY_FIELD: dict[Protocol, str] = {
|
|
@@ -33,8 +29,6 @@ _REPLY_FIELD: dict[Protocol, str] = {
|
|
|
33
29
|
"openai-responses": "output",
|
|
34
30
|
"anthropic": "content",
|
|
35
31
|
}
|
|
36
|
-
# Which failure explains a refused endpoint best when nothing answered.
|
|
37
|
-
_FAILURE_RANK = ("BYOK_AUTH_FAILED", "BYOK_MODEL_NOT_FOUND", "BYOK_UPSTREAM_REJECTED")
|
|
38
32
|
_WINDOW_FIELDS = ("context_length", "context_window", "max_input_tokens")
|
|
39
33
|
|
|
40
34
|
|
|
@@ -51,22 +45,6 @@ class _NoRedirect(urllib.request.HTTPRedirectHandler):
|
|
|
51
45
|
return None
|
|
52
46
|
|
|
53
47
|
|
|
54
|
-
def _alternate(root: str) -> str:
|
|
55
|
-
"""The other half of the /v1 and /anthropic layout."""
|
|
56
|
-
if root.endswith(ANTHROPIC_SUFFIX):
|
|
57
|
-
return root.removesuffix(ANTHROPIC_SUFFIX)
|
|
58
|
-
return root + ANTHROPIC_SUFFIX
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def _roots(base_url: str, protocol: Protocol) -> list[str]:
|
|
62
|
-
"""Where ``protocol`` may be served: the entered URL first, then the alternate when the
|
|
63
|
-
entered URL names the other API family."""
|
|
64
|
-
root = bifrost_provider.origin(base_url)
|
|
65
|
-
if root.endswith(ANTHROPIC_SUFFIX) == (protocol == "anthropic"):
|
|
66
|
-
return [root]
|
|
67
|
-
return [root, _alternate(root)]
|
|
68
|
-
|
|
69
|
-
|
|
70
48
|
def _headers(protocol: Protocol, api_key: str) -> dict[str, str]:
|
|
71
49
|
headers = {"Accept": "application/json", "Content-Type": "application/json"}
|
|
72
50
|
if protocol == "anthropic":
|
|
@@ -97,18 +75,17 @@ def _call(
|
|
|
97
75
|
except urllib.error.HTTPError as exc:
|
|
98
76
|
if exc.code in (401, 403):
|
|
99
77
|
raise ByokError(
|
|
100
|
-
"BYOK_AUTH_FAILED", "
|
|
78
|
+
"BYOK_AUTH_FAILED", f"{url} rejected the API key (HTTP {exc.code})."
|
|
101
79
|
) from None
|
|
102
80
|
if exc.code == 404:
|
|
103
81
|
raise ByokError(
|
|
104
|
-
"
|
|
82
|
+
"BYOK_NOT_FOUND",
|
|
83
|
+
f"{url} returned HTTP 404: the address or the model was not found.",
|
|
105
84
|
) from None
|
|
106
|
-
raise ByokError(
|
|
107
|
-
"BYOK_UPSTREAM_REJECTED", f"Upstream endpoint returned HTTP {exc.code}."
|
|
108
|
-
) from None
|
|
85
|
+
raise ByokError("BYOK_UPSTREAM_REJECTED", f"{url} returned HTTP {exc.code}.") from None
|
|
109
86
|
except (urllib.error.URLError, TimeoutError, OSError) as exc:
|
|
110
87
|
raise ByokError(
|
|
111
|
-
"BYOK_UNREACHABLE", f"Could not reach
|
|
88
|
+
"BYOK_UNREACHABLE", f"Could not reach {url} ({type(exc).__name__})."
|
|
112
89
|
) from None
|
|
113
90
|
try:
|
|
114
91
|
return json.loads(raw) if len(raw) <= MAX_PROBE_BYTES else None
|
|
@@ -143,34 +120,35 @@ def _model_rows(doc: Any) -> list[ByokModel] | None:
|
|
|
143
120
|
return models
|
|
144
121
|
|
|
145
122
|
|
|
146
|
-
def
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
path, body = {
|
|
152
|
-
"anthropic": ("messages", {"model": model, "max_tokens": 16}),
|
|
153
|
-
"openai-responses": ("responses", {"model": model, "max_output_tokens": 16}),
|
|
154
|
-
"openai-chat": ("chat/completions", {"model": model, "max_tokens": 16}),
|
|
155
|
-
}[protocol]
|
|
123
|
+
def _probe_request(endpoint: ByokEndpoint, private: bool, timeout: float) -> None:
|
|
124
|
+
"""Send one small request in the endpoint's wire format; raise ByokError unless it is
|
|
125
|
+
answered."""
|
|
126
|
+
protocol = endpoint["protocol"]
|
|
127
|
+
body: dict[str, Any] = {"model": endpoint["model_id"]}
|
|
156
128
|
if protocol == "openai-responses":
|
|
157
|
-
body
|
|
129
|
+
body |= {"input": "Reply with OK.", "max_output_tokens": 16, "stream": False}
|
|
158
130
|
else:
|
|
159
|
-
body
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
doc = _call(
|
|
131
|
+
body |= {"messages": [{"role": "user", "content": "Reply with OK."}], "max_tokens": 16}
|
|
132
|
+
if protocol == "openai-chat":
|
|
133
|
+
body["stream"] = False
|
|
134
|
+
url = request_url(endpoint)
|
|
135
|
+
doc = _call(url, _headers(protocol, endpoint["api_key"]), private, timeout, body)
|
|
164
136
|
if not isinstance(doc, dict) or not isinstance(doc.get(_REPLY_FIELD[protocol]), list):
|
|
165
|
-
raise ByokError(
|
|
166
|
-
|
|
167
|
-
|
|
137
|
+
raise ByokError("BYOK_UPSTREAM_REJECTED", f"{url} answered in an unexpected format.")
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _listed(endpoint: ByokEndpoint, private: bool, timeout: float) -> list[ByokModel]:
|
|
141
|
+
url = models_url(endpoint)
|
|
142
|
+
headers = _headers(endpoint["protocol"], endpoint["api_key"])
|
|
143
|
+
rows = _model_rows(_call(url, headers, private, timeout))
|
|
144
|
+
if not rows:
|
|
145
|
+
raise ByokError("BYOK_UPSTREAM_REJECTED", f"{url} listed no models.")
|
|
146
|
+
return rows
|
|
168
147
|
|
|
169
148
|
|
|
170
149
|
def _window_for(rows: list[ByokModel], target: str) -> int | None:
|
|
171
150
|
"""The listed window of ``target``, matching an exact ID first and then an ID with one
|
|
172
|
-
more provider prefix on either side, since
|
|
173
|
-
under different IDs."""
|
|
151
|
+
more provider prefix on either side, since gateways list one model under several IDs."""
|
|
174
152
|
exact = [row for row in rows if row["id"] == target]
|
|
175
153
|
loose = [
|
|
176
154
|
row
|
|
@@ -180,96 +158,34 @@ def _window_for(rows: list[ByokModel], target: str) -> int | None:
|
|
|
180
158
|
return next((row["context_window"] for row in exact + loose if row["context_window"]), None)
|
|
181
159
|
|
|
182
160
|
|
|
183
|
-
def
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
the other half of a /v1 and /anthropic gateway, whose list may carry windows when the
|
|
188
|
-
answering half's does not."""
|
|
161
|
+
def probe_upstream(endpoint: ByokEndpoint, *, timeout: float = 35.0) -> ByokCredentials:
|
|
162
|
+
"""Check that the endpoint answers one request at its address, and read the model's
|
|
163
|
+
context window from its model list when it reports one."""
|
|
164
|
+
_, private = validate_url(endpoint["base_url"])
|
|
189
165
|
deadline = time.monotonic() + timeout
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
for listing_root, style in ((root, protocol), (alternate, alternate_style)):
|
|
195
|
-
remaining = deadline - time.monotonic()
|
|
196
|
-
if remaining <= 0:
|
|
197
|
-
return None
|
|
198
|
-
headers = _headers(style, endpoint["api_key"])
|
|
166
|
+
_probe_request(endpoint, private, timeout)
|
|
167
|
+
remaining = min(deadline - time.monotonic(), 8.0)
|
|
168
|
+
window = None
|
|
169
|
+
if remaining > 1:
|
|
199
170
|
try:
|
|
200
|
-
|
|
171
|
+
window = _window_for(_listed(endpoint, private, remaining), endpoint["model_id"])
|
|
201
172
|
except ByokError:
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
173
|
+
window = None
|
|
174
|
+
return {
|
|
175
|
+
"schema": CREDENTIALS_SCHEMA,
|
|
176
|
+
"protocol": endpoint["protocol"],
|
|
177
|
+
"base_url": endpoint["base_url"],
|
|
178
|
+
"path": endpoint["path"],
|
|
179
|
+
"endpoint": endpoint["endpoint"],
|
|
180
|
+
"api_key": endpoint["api_key"],
|
|
181
|
+
"model_id": endpoint["model_id"],
|
|
182
|
+
"context_window": window or endpoint["context_window"],
|
|
183
|
+
"key_saved": bool(endpoint["api_key"]),
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def list_models(endpoint: ByokEndpoint, *, timeout: float = 20.0) -> list[ByokModel]:
|
|
188
|
+
"""The models the endpoint lists at its model address, sorted by ID."""
|
|
217
189
|
_, private = validate_url(endpoint["base_url"])
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
for protocol in PROTOCOL_ORDER[runtime]:
|
|
221
|
-
for root in _roots(endpoint["base_url"], protocol):
|
|
222
|
-
remaining = deadline - time.monotonic()
|
|
223
|
-
if remaining <= 0:
|
|
224
|
-
raise ByokError("BYOK_UNREACHABLE", "Upstream endpoint did not answer in time.")
|
|
225
|
-
try:
|
|
226
|
-
_probe_format(root, endpoint, protocol, private, remaining)
|
|
227
|
-
except ByokError as exc:
|
|
228
|
-
if exc.code == "BYOK_UNREACHABLE":
|
|
229
|
-
raise
|
|
230
|
-
failures.append(exc)
|
|
231
|
-
continue
|
|
232
|
-
remaining = deadline - time.monotonic()
|
|
233
|
-
discovered = (
|
|
234
|
-
_discover_window(root, endpoint, protocol, private, min(remaining, 8.0))
|
|
235
|
-
if remaining > 1
|
|
236
|
-
else None
|
|
237
|
-
)
|
|
238
|
-
return {
|
|
239
|
-
"schema": CREDENTIALS_SCHEMA,
|
|
240
|
-
"protocol": protocol,
|
|
241
|
-
"base_url": endpoint["base_url"],
|
|
242
|
-
"upstream_url": root,
|
|
243
|
-
"api_key": endpoint["api_key"],
|
|
244
|
-
"model_id": endpoint["model_id"],
|
|
245
|
-
"context_window": discovered or endpoint["context_window"],
|
|
246
|
-
"key_saved": bool(endpoint["api_key"]),
|
|
247
|
-
}
|
|
248
|
-
raise min(failures, key=lambda exc: _FAILURE_RANK.index(exc.code))
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
def list_models(endpoint: ByokEndpoint, *, timeout: float = 20.0) -> tuple[str, list[ByokModel]]:
|
|
252
|
-
"""The models the endpoint lists, sorted by ID, and the address that listed them."""
|
|
253
|
-
_, private = validate_url(endpoint["base_url"])
|
|
254
|
-
deadline = time.monotonic() + timeout
|
|
255
|
-
failures: list[ByokError] = []
|
|
256
|
-
entered = bifrost_provider.origin(endpoint["base_url"])
|
|
257
|
-
for root in (entered, _alternate(entered)):
|
|
258
|
-
for protocol in ("openai-chat", "anthropic"):
|
|
259
|
-
remaining = deadline - time.monotonic()
|
|
260
|
-
if remaining <= 0:
|
|
261
|
-
raise ByokError("BYOK_UNREACHABLE", "Upstream endpoint did not answer in time.")
|
|
262
|
-
headers = _headers(protocol, endpoint["api_key"])
|
|
263
|
-
try:
|
|
264
|
-
rows = _model_rows(_call(f"{root}/v1/models", headers, private, remaining))
|
|
265
|
-
except ByokError as exc:
|
|
266
|
-
if exc.code == "BYOK_UNREACHABLE":
|
|
267
|
-
raise
|
|
268
|
-
failures.append(exc)
|
|
269
|
-
continue
|
|
270
|
-
if rows:
|
|
271
|
-
return root, sorted(rows, key=lambda row: row["id"])[:MAX_LISTED_MODELS]
|
|
272
|
-
failures.append(
|
|
273
|
-
ByokError("BYOK_UPSTREAM_REJECTED", "Upstream endpoint listed no models.")
|
|
274
|
-
)
|
|
275
|
-
raise min(failures, key=lambda exc: _FAILURE_RANK.index(exc.code))
|
|
190
|
+
rows = _listed(endpoint, private, timeout)
|
|
191
|
+
return sorted(rows, key=lambda row: row["id"])[:MAX_LISTED_MODELS]
|
|
@@ -64,18 +64,13 @@ def add_parser(sub: argparse._SubParsersAction[argparse.ArgumentParser]) -> None
|
|
|
64
64
|
required=True,
|
|
65
65
|
help="read BYOK configuration JSON from standard input",
|
|
66
66
|
)
|
|
67
|
-
check.add_argument(
|
|
68
|
-
"--runtime",
|
|
69
|
-
choices=source_byok.RUNTIMES,
|
|
70
|
-
required=True,
|
|
71
|
-
help="agent runtime the endpoint will serve; its own wire format is tried first",
|
|
72
|
-
)
|
|
73
67
|
check.add_argument("--json", action="store_true", help="accepted; output is JSON")
|
|
74
68
|
cli_help.document(
|
|
75
69
|
check,
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
|
|
70
|
+
"Send one request in the given wire format (OpenAI chat, OpenAI responses, or "
|
|
71
|
+
"Anthropic) to base URL + path + endpoint, without saving credentials or changing the "
|
|
72
|
+
"active model source.",
|
|
73
|
+
examples=[("%(prog)s --config-stdin --json", "")],
|
|
79
74
|
)
|
|
80
75
|
|
|
81
76
|
models = verbs.add_parser("models", help="list the models a BYOK endpoint serves")
|
|
@@ -88,8 +83,8 @@ def add_parser(sub: argparse._SubParsersAction[argparse.ArgumentParser]) -> None
|
|
|
88
83
|
models.add_argument("--json", action="store_true", help="accepted; output is JSON")
|
|
89
84
|
cli_help.document(
|
|
90
85
|
models,
|
|
91
|
-
"List the models
|
|
92
|
-
"
|
|
86
|
+
"List the models at base URL + path + /models, with their names and context windows "
|
|
87
|
+
"when the endpoint reports them, without saving credentials.",
|
|
93
88
|
examples=[("%(prog)s --config-stdin --json", "")],
|
|
94
89
|
)
|
|
95
90
|
|
|
@@ -268,7 +263,7 @@ def _ensure_runtime_installed(
|
|
|
268
263
|
|
|
269
264
|
def _apply_byok(args: argparse.Namespace, runtime: Runtime) -> SourceState:
|
|
270
265
|
payload = _read_stdin_json() if args.config_stdin else None
|
|
271
|
-
creds = source_byok_probe.probe_upstream(source_byok.resolve_endpoint(payload)
|
|
266
|
+
creds = source_byok_probe.probe_upstream(source_byok.resolve_endpoint(payload))
|
|
272
267
|
_unload_loaded_local_models(args.base_dir)
|
|
273
268
|
source_byok.save_credentials(creds)
|
|
274
269
|
facts = library_jobs.probe()
|
|
@@ -344,14 +339,13 @@ def cli(args: argparse.Namespace) -> int:
|
|
|
344
339
|
print(json.dumps(doc, ensure_ascii=False, indent=1))
|
|
345
340
|
return 0
|
|
346
341
|
if verb == "check":
|
|
347
|
-
runtime = cast(Runtime, args.runtime)
|
|
348
342
|
|
|
349
343
|
def check(payload: dict[str, Any]) -> dict[str, Any]:
|
|
350
344
|
endpoint = source_byok.resolve_endpoint(payload, require_input=True)
|
|
351
|
-
creds = source_byok_probe.probe_upstream(endpoint
|
|
345
|
+
creds = source_byok_probe.probe_upstream(endpoint)
|
|
352
346
|
return {
|
|
353
347
|
"protocol": creds["protocol"],
|
|
354
|
-
"
|
|
348
|
+
"url": source_byok.request_url(creds),
|
|
355
349
|
"model_id": creds["model_id"],
|
|
356
350
|
"context_window": creds["context_window"],
|
|
357
351
|
}
|
|
@@ -363,8 +357,8 @@ def cli(args: argparse.Namespace) -> int:
|
|
|
363
357
|
endpoint = source_byok.resolve_endpoint(
|
|
364
358
|
payload, require_input=True, require_model=False
|
|
365
359
|
)
|
|
366
|
-
|
|
367
|
-
return {"
|
|
360
|
+
listed = source_byok_probe.list_models(endpoint)
|
|
361
|
+
return {"url": source_byok.models_url(endpoint), "models": listed}
|
|
368
362
|
|
|
369
363
|
return _endpoint_command(source_byok.MODELS_SCHEMA, models)
|
|
370
364
|
|
|
@@ -340,6 +340,14 @@ def _deploy_aux(task: str, part: Plan, key: str, log: Log, do: Effects) -> Compo
|
|
|
340
340
|
return do.deploy(task, part, key, log)
|
|
341
341
|
|
|
342
342
|
|
|
343
|
+
def _sync_library(plan: StackPlan, attempt_id: str | None) -> None:
|
|
344
|
+
"""Keep an already-used model library in step with a newly accepted stack apply."""
|
|
345
|
+
from localmodels import library_convert
|
|
346
|
+
|
|
347
|
+
if library_convert.initialized():
|
|
348
|
+
library_convert.sync_stack(plan, attempt_id=attempt_id, if_initialized=True)
|
|
349
|
+
|
|
350
|
+
|
|
343
351
|
def execute(
|
|
344
352
|
plan: StackPlan,
|
|
345
353
|
log: Log,
|
|
@@ -374,11 +382,14 @@ def execute(
|
|
|
374
382
|
journal = stack_journal.Journal(plan["plan_id"], session["attempt_id"]) # for stack view
|
|
375
383
|
try:
|
|
376
384
|
with stack_run.checkpointed(session):
|
|
377
|
-
|
|
385
|
+
result = _run_components(
|
|
378
386
|
plan, log, steps, session, parts, persist, journal.tee(on_progress)
|
|
379
387
|
)
|
|
380
388
|
finally:
|
|
381
389
|
journal.close()
|
|
390
|
+
if result["ok"]:
|
|
391
|
+
_sync_library(plan, result.get("attempt_id"))
|
|
392
|
+
return result
|
|
382
393
|
|
|
383
394
|
|
|
384
395
|
def _run_components(
|
|
@@ -12,7 +12,7 @@ import argparse
|
|
|
12
12
|
import json
|
|
13
13
|
import urllib.parse
|
|
14
14
|
|
|
15
|
-
from localmodels import bifrost_models, gateway_bifrost, harness, hosts, stack_update
|
|
15
|
+
from localmodels import bifrost_models, gateway_bifrost, harness, hosts, stack_update, vision
|
|
16
16
|
from localmodels.bifrost_models import StackClients
|
|
17
17
|
from localmodels.stack_plan import StackError, command
|
|
18
18
|
|
|
@@ -53,6 +53,13 @@ def settings(base: str | None = None) -> StackClients:
|
|
|
53
53
|
f" proven this tool's); start it with {command()} stack up"
|
|
54
54
|
)
|
|
55
55
|
listed = bifrost_models.listed(record["addr"])
|
|
56
|
+
if "vision" not in gw:
|
|
57
|
+
fast = plan.get("llm_fast")
|
|
58
|
+
gw = {
|
|
59
|
+
**gw,
|
|
60
|
+
"vision": vision.reads_pictures(plan["llm"]["launch"])
|
|
61
|
+
and (fast is None or vision.reads_pictures(fast["launch"])),
|
|
62
|
+
}
|
|
56
63
|
return bifrost_models.clients(
|
|
57
64
|
plan["plan_id"],
|
|
58
65
|
gw,
|
|
@@ -685,6 +685,7 @@ def assemble(
|
|
|
685
685
|
# A plan saved before the choice existed has no gateway option: it used Magpie.
|
|
686
686
|
gateway_kind=options.get("gateway", "magpie"),
|
|
687
687
|
context=int(str(llm["launch"].get("window") or 0)) or None,
|
|
688
|
+
vision=stack_route.reads_images(llm),
|
|
688
689
|
)
|
|
689
690
|
if fast is not None:
|
|
690
691
|
tools_plan["gateway"]["llm_fast"] = {
|
|
@@ -187,11 +187,7 @@ def add(
|
|
|
187
187
|
|
|
188
188
|
|
|
189
189
|
def reads_images(part: Plan) -> bool:
|
|
190
|
-
return vision.reads_pictures(part["launch"])
|
|
191
|
-
None,
|
|
192
|
-
"",
|
|
193
|
-
"off",
|
|
194
|
-
)
|
|
190
|
+
return vision.reads_pictures(part["launch"])
|
|
195
191
|
|
|
196
192
|
|
|
197
193
|
def _target_vram(facts: HostFacts, placement: str, primary: Plan) -> int:
|
|
@@ -182,6 +182,22 @@ def _unstartable(part: Plan, state: str) -> str:
|
|
|
182
182
|
)
|
|
183
183
|
|
|
184
184
|
|
|
185
|
+
def _sync_library(plan: StackPlan) -> None:
|
|
186
|
+
"""Keep an already-used model library in step after ``stack up`` revives the stack."""
|
|
187
|
+
from localmodels import library_convert
|
|
188
|
+
|
|
189
|
+
if library_convert.initialized():
|
|
190
|
+
attempt = next(
|
|
191
|
+
(
|
|
192
|
+
str(run["attempt_id"])
|
|
193
|
+
for run, _ in reversed(hosts.stack_runs())
|
|
194
|
+
if run.get("plan_id") == plan["plan_id"] and run.get("attempt_id")
|
|
195
|
+
),
|
|
196
|
+
None,
|
|
197
|
+
)
|
|
198
|
+
library_convert.sync_stack(plan, attempt_id=attempt, if_initialized=True)
|
|
199
|
+
|
|
200
|
+
|
|
185
201
|
def up(
|
|
186
202
|
plan: StackPlan,
|
|
187
203
|
*,
|
|
@@ -199,9 +215,12 @@ def up(
|
|
|
199
215
|
)
|
|
200
216
|
try:
|
|
201
217
|
with hosts.stack_apply_lock():
|
|
202
|
-
|
|
218
|
+
report = _up(plan, share_gpu, timeout, out)
|
|
203
219
|
except hosts.LockedError as exc:
|
|
204
220
|
raise StackError("another stack apply is running") from exc
|
|
221
|
+
if report["ok"]:
|
|
222
|
+
_sync_library(plan)
|
|
223
|
+
return report
|
|
205
224
|
|
|
206
225
|
|
|
207
226
|
def _up(plan: StackPlan, share_gpu: bool, timeout: float, out: Out) -> UpReport:
|
|
@@ -92,7 +92,8 @@ def launch_keys(mmproj: AssetFile, mode: str) -> dict[str, object]:
|
|
|
92
92
|
|
|
93
93
|
def reads_pictures(launch: Mapping[str, object]) -> bool:
|
|
94
94
|
"""Whether a plan's launch has its picture reader on (decision 31): readiness reads one."""
|
|
95
|
-
|
|
95
|
+
mode = launch.get("vision")
|
|
96
|
+
return bool(mode) and mode != "off"
|
|
96
97
|
|
|
97
98
|
|
|
98
99
|
def priced(
|
|
@@ -240,7 +240,7 @@ main { min-width: 0; padding: 0 22px 60px; }
|
|
|
240
240
|
.node.tick { animation: tick 0.5s; }
|
|
241
241
|
@keyframes tick { 40% { transform: scale(1.05); } }
|
|
242
242
|
.node .ic { display: grid; place-items: center; width: 26px; height: 26px; margin-bottom: 2px; border-radius: 8px; font-weight: 700; font-size: 12px; color: #000; }
|
|
243
|
-
.node .ic.client-logo { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; overflow: hidden; background: #fff; border: 1px solid #e3e3e8; }
|
|
243
|
+
.node .ic.client-logo { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; overflow: hidden; background: #fff; border: 1px solid #e3e3e8; }
|
|
244
244
|
.ic.client-logo img { display: block; flex-shrink: 0; width: 32px; height: 32px; object-fit: contain; }
|
|
245
245
|
.ic.client-logo img[src="logo-pi.svg"] { width: 36px; height: 36px; }
|
|
246
246
|
.ic.client-logo img[src="logo-claude.svg"] { width: 24px; height: 24px; }
|