@simplexai/localmodels-linux-x64 0.1.0-dev.36 → 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 +119 -98
- 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 +13 -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/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 +102 -9
- 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 +1 -1
- 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/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 +58 -25
- package/modules/localmodels/stack_console.py +9 -6
- package/modules/localmodels/stack_hardware.py +92 -263
- 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 +59 -12
- package/modules/localmodels/stack_plan.py +19 -1
- 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 +11 -7
- 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.dev36.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/RECORD +115 -94
- 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.dev37.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""What the terminal UI shows:
|
|
1
|
+
"""What the terminal UI shows: view formatters and re-exported dialog/width helpers.
|
|
2
2
|
|
|
3
3
|
Pure functions from controller documents to lines of (text, style); no curses and no I/O.
|
|
4
4
|
Widths count East Asian wide characters as two columns, since the interface text is Chinese.
|
|
@@ -7,78 +7,31 @@ Widths count East Asian wide characters as two columns, since the interface text
|
|
|
7
7
|
from __future__ import annotations
|
|
8
8
|
|
|
9
9
|
import json
|
|
10
|
-
import re
|
|
11
|
-
import unicodedata
|
|
12
|
-
from collections.abc import Callable
|
|
13
|
-
from dataclasses import dataclass
|
|
14
10
|
from pathlib import Path
|
|
15
|
-
from typing import Literal
|
|
16
11
|
|
|
17
|
-
from localmodels import console, hosts, recommend_cli, stack
|
|
12
|
+
from localmodels import console, deploy, harness, hosts, recommend_cli, stack
|
|
18
13
|
from localmodels.budget import gib
|
|
19
14
|
from localmodels.probe import HostFacts
|
|
20
15
|
from localmodels.recommend import CatalogRow, HostCatalog
|
|
21
16
|
from localmodels.records import Device, FinishedRecord, Plan, ProgressEvent
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
break
|
|
41
|
-
used += w
|
|
42
|
-
out.append(c)
|
|
43
|
-
return "".join(out)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def pad(text: str, cols: int) -> str:
|
|
47
|
-
"""Exactly ``cols`` display columns, with at least one space after a clipped cell."""
|
|
48
|
-
cut = clip(text, cols - 1) if width(text) >= cols else text
|
|
49
|
-
return cut + " " * (cols - width(cut))
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
# A summary row: its leading spaces, then a short label padded with spaces (" 硬件 …").
|
|
53
|
-
_LABEL = re.compile(r"^( *)(\S{1,8} {2,})?")
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
def wrap(text: str, cols: int) -> list[str]:
|
|
57
|
-
"""``text`` in rows of ``cols`` columns. A continuation starts under the text after the
|
|
58
|
-
row's indent and label, so " 硬件 GPU 0 …" keeps 硬件 alone in its column."""
|
|
59
|
-
if cols <= 0 or width(text) <= cols:
|
|
60
|
-
return [text]
|
|
61
|
-
match = _LABEL.match(text)
|
|
62
|
-
hang = width(match.group(0)) if match else 0
|
|
63
|
-
if hang > cols // 2:
|
|
64
|
-
hang = 0
|
|
65
|
-
lines: list[str] = []
|
|
66
|
-
rest = text
|
|
67
|
-
while rest:
|
|
68
|
-
room = cols if not lines else cols - hang
|
|
69
|
-
head = clip(rest, room) or rest[0]
|
|
70
|
-
# Break at the last space or CJK punctuation in the row when there is one, not mid-word.
|
|
71
|
-
if len(head) < len(rest):
|
|
72
|
-
cut = max(head.rfind(" "), *(head.rfind(p) + 1 for p in ",、;:"))
|
|
73
|
-
if cut > len(head) // 2 and (not lines or cut > 0):
|
|
74
|
-
head = head[:cut]
|
|
75
|
-
lines.append(head if not lines else " " * hang + head)
|
|
76
|
-
rest = rest[len(head) :].lstrip(" ")
|
|
77
|
-
return lines
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
def key_label(key: str) -> str:
|
|
81
|
-
return "Enter" if key == "enter" else key
|
|
17
|
+
from localmodels.tui_modals import CODE_CHARS as CODE_CHARS
|
|
18
|
+
from localmodels.tui_modals import HELP as HELP
|
|
19
|
+
from localmodels.tui_modals import Confirm as Confirm
|
|
20
|
+
from localmodels.tui_modals import Field as Field
|
|
21
|
+
from localmodels.tui_modals import Form as Form
|
|
22
|
+
from localmodels.tui_modals import Line as Line
|
|
23
|
+
from localmodels.tui_modals import Modal as Modal
|
|
24
|
+
from localmodels.tui_modals import Outcome as Outcome
|
|
25
|
+
from localmodels.tui_modals import Picker as Picker
|
|
26
|
+
from localmodels.tui_modals import Style as Style
|
|
27
|
+
from localmodels.tui_modals import clip as clip
|
|
28
|
+
from localmodels.tui_modals import help_modal as help_modal
|
|
29
|
+
from localmodels.tui_modals import key_label as key_label
|
|
30
|
+
from localmodels.tui_modals import modal_keys as modal_keys
|
|
31
|
+
from localmodels.tui_modals import modal_lines as modal_lines
|
|
32
|
+
from localmodels.tui_modals import pad as pad
|
|
33
|
+
from localmodels.tui_modals import width as width
|
|
34
|
+
from localmodels.tui_modals import wrap as wrap
|
|
82
35
|
|
|
83
36
|
|
|
84
37
|
def error_text(exc: Exception) -> str:
|
|
@@ -116,11 +69,29 @@ def frame(
|
|
|
116
69
|
height = max(0, rows - 3 - len(dim))
|
|
117
70
|
body = (body + [("", "text")] * height)[:height]
|
|
118
71
|
rows_dim: list[Line] = [(d, "dim") for d in dim]
|
|
119
|
-
out: list[Line] = [(head, "title"), (tab_row, "
|
|
72
|
+
out: list[Line] = [(head, "title"), (tab_row, "tabs")]
|
|
120
73
|
out += [*body, *rows_dim, status]
|
|
121
74
|
return [(clip(text, cols), style) for text, style in out[:rows]]
|
|
122
75
|
|
|
123
76
|
|
|
77
|
+
def small_screen_lines(cols: int, rows: int, min_cols: int = 52, min_rows: int = 14) -> list[Line]:
|
|
78
|
+
"""Centered warning when the terminal is too small for the full TUI."""
|
|
79
|
+
if rows <= 0:
|
|
80
|
+
return []
|
|
81
|
+
messages: list[Line] = [
|
|
82
|
+
(f"请将终端窗口放大至至少 {min_cols}×{min_rows}", "warn"),
|
|
83
|
+
(f"当前 {cols}×{rows}", "dim"),
|
|
84
|
+
]
|
|
85
|
+
centered: list[Line] = []
|
|
86
|
+
for text, style in messages:
|
|
87
|
+
for part in wrap(text, max(1, cols)):
|
|
88
|
+
pad_left = max(0, (cols - width(part)) // 2)
|
|
89
|
+
centered.append((clip(" " * pad_left + part, cols), style))
|
|
90
|
+
pad_line: Line = ("", "text")
|
|
91
|
+
out: list[Line] = [pad_line] * ((rows - len(centered)) // 2) + centered
|
|
92
|
+
return (out + [pad_line] * rows)[:rows]
|
|
93
|
+
|
|
94
|
+
|
|
124
95
|
def list_window(
|
|
125
96
|
head: list[Line], rows: list[Line], cursor: int, detail: str | None, cols: int, height: int
|
|
126
97
|
) -> list[Line]:
|
|
@@ -158,99 +129,68 @@ def text_window(
|
|
|
158
129
|
return wrapped[start : start + height], offset
|
|
159
130
|
|
|
160
131
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
self.accept()
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
@dataclass
|
|
227
|
-
class Picker:
|
|
228
|
-
title: str
|
|
229
|
-
items: list[str]
|
|
230
|
-
choose: Callable[[int], None]
|
|
231
|
-
index: int = 0
|
|
232
|
-
|
|
233
|
-
def key(self, key: str) -> Outcome:
|
|
234
|
-
if key in ("up", "down"):
|
|
235
|
-
moved = self.index + (1 if key == "down" else -1)
|
|
236
|
-
self.index = max(0, min(len(self.items) - 1, moved))
|
|
237
|
-
return "finish" if key == "enter" and self.items else "open"
|
|
238
|
-
|
|
239
|
-
def finish(self) -> None:
|
|
240
|
-
self.choose(self.index)
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
Modal = Form | Confirm | Picker
|
|
244
|
-
|
|
245
|
-
HELP: list[Line] = [
|
|
246
|
-
("1-7 / Tab 切换页面;↑↓ PgUp PgDn 选择或滚动;? 帮助;q 退出", "text"),
|
|
247
|
-
("对话框:Enter 确认或提交,Esc 取消;表单中 ↑↓ 切换字段,空格切换开关", "text"),
|
|
248
|
-
("", "text"),
|
|
249
|
-
("只读:探测、推荐、生成计划。会改动主机的操作都要先确认:", "text"),
|
|
250
|
-
(" 部署:输入 yes(所选 GPU 已被占用时输入 share);执行前重新探测核对计划", "dim"),
|
|
251
|
-
(f" 套件:输入计划确认码的前 {CODE_CHARS} 位;stack apply 同样会重新核对", "dim"),
|
|
252
|
-
(" 服务启停与移除只作用于本工具的部署记录", "dim"),
|
|
253
|
-
]
|
|
132
|
+
def deploy_confirm_body(plan: Plan, device: str, busy: list[str]) -> list[Line]:
|
|
133
|
+
"""Confirmation dialog body for executing a single-model deploy plan."""
|
|
134
|
+
svc = plan["service"]
|
|
135
|
+
body: list[Line] = [
|
|
136
|
+
(f"在 {plan['hostname']}({device})上执行显示的计划:", "text"),
|
|
137
|
+
(
|
|
138
|
+
f" 下载 {gib(plan['model']['download_bytes'])}({len(plan['files'])} 个文件,"
|
|
139
|
+
"已校验的跳过)",
|
|
140
|
+
"text",
|
|
141
|
+
),
|
|
142
|
+
(f" 写入 {svc['deploy_dir']},服务 {svc['name']}", "text"),
|
|
143
|
+
(f" 启动 {svc['kind']} 服务,监听 {svc['bind']}:{svc['port']}", "text"),
|
|
144
|
+
("执行前重新探测;计划内容有变化时拒绝执行并显示新计划。", "dim"),
|
|
145
|
+
*((f"注意:{w}", "warn") for w in plan["warnings"]),
|
|
146
|
+
*((f"占用:{b}", "error") for b in busy),
|
|
147
|
+
]
|
|
148
|
+
if busy:
|
|
149
|
+
body.append(("与已有进程共用这张卡需要你明确同意:输入 share。", "warn"))
|
|
150
|
+
return body
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def stack_confirm_body(path: Path, plan: stack.StackPlan) -> list[Line]:
|
|
154
|
+
"""Confirmation dialog body for applying a stack plan, naming its actual gateway."""
|
|
155
|
+
gw = (
|
|
156
|
+
"Bifrost" if harness.gateway_kind(plan["harness"].get("gateway")) == "bifrost" else "Magpie"
|
|
157
|
+
)
|
|
158
|
+
return [
|
|
159
|
+
(f"{path}", "dim"),
|
|
160
|
+
(f"将按计划安装工具、部署决策模型与 LLM、接入 {gw} 并修改 pi 默认模型,", "text"),
|
|
161
|
+
("最后逐项验收。执行前重新探测,影响计划的事实变了就拒绝。", "text"),
|
|
162
|
+
(f"确认码 {plan['plan_id']}", "text"),
|
|
163
|
+
]
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def plan_form_fields(model_id: str) -> list[Field]:
|
|
167
|
+
"""Form fields for building a single-model deployment plan."""
|
|
168
|
+
return [
|
|
169
|
+
Field("model_id", "模型 id", model_id),
|
|
170
|
+
Field("placement_id", "位置(auto 或推荐页中的位置 id)", "auto"),
|
|
171
|
+
Field("port", "端口", str(deploy.DEFAULT_PORT)),
|
|
172
|
+
Field("bind", "监听地址", "127.0.0.1"),
|
|
173
|
+
Field("hf_download_endpoint", "权重下载源", deploy.HF_API),
|
|
174
|
+
Field("engine_path", "沿用主机已有 llama-server(可空)", ""),
|
|
175
|
+
]
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def stack_form_fields(o: stack.StackOptions) -> list[Field]:
|
|
179
|
+
"""Form fields for building a local agent stack plan."""
|
|
180
|
+
return [
|
|
181
|
+
Field("llm", "LLM(auto 或目录 id)", o["llm"]),
|
|
182
|
+
Field("decision", "选装决策模型(none / auto / 组件 id)", o["decision"]),
|
|
183
|
+
Field("llm_port", "LLM 端口(0 为自动)", str(o["llm_port"])),
|
|
184
|
+
Field("decision_port", "决策模型端口(0 为自动)", str(o["decision_port"])),
|
|
185
|
+
Field("share_gpu", "与已占用 GPU 的进程共用", o["share_gpu"]),
|
|
186
|
+
Field("aux", "选装 embedding、reranker、STT(默认不装)", o["aux"]),
|
|
187
|
+
Field("tts", "调试 TTS(可选,默认不装)", False),
|
|
188
|
+
Field("suite_memory", "套件内存上限", o["suite_memory"]),
|
|
189
|
+
Field("conversation_cache", "LLM 会话缓存(auto / off / MiB)", o["conversation_cache"]),
|
|
190
|
+
Field("hf_endpoint", "权重下载源", o["hf_endpoint"]),
|
|
191
|
+
Field("base_dir", "引擎、权重与部署目录", o["base_dir"]),
|
|
192
|
+
Field("reuse_from", "复用目录(逗号分隔,可空)", ""),
|
|
193
|
+
]
|
|
254
194
|
|
|
255
195
|
|
|
256
196
|
def _device_summary(facts: HostFacts | None) -> str:
|
|
@@ -370,12 +310,38 @@ def _verdict(m: CatalogRow, busy: bool) -> str:
|
|
|
370
310
|
return "容量够·卡上有其他程序" if busy else "完全在 GPU 上运行"
|
|
371
311
|
|
|
372
312
|
|
|
373
|
-
def
|
|
313
|
+
def _row_matches(m: CatalogRow, q: str) -> bool:
|
|
314
|
+
haystack = (
|
|
315
|
+
m.get("id"),
|
|
316
|
+
m.get("display_name"),
|
|
317
|
+
m.get("quant"),
|
|
318
|
+
m.get("status"),
|
|
319
|
+
m.get("fit_summary"),
|
|
320
|
+
)
|
|
321
|
+
return any(q in str(v or "").lower() for v in haystack)
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def filter_models(models: list[CatalogRow], query: str) -> list[CatalogRow]:
|
|
325
|
+
"""Filter catalog rows matching ``query`` in id, display_name, quant, status, or fit_summary."""
|
|
326
|
+
q = query.strip().lower()
|
|
327
|
+
if not q:
|
|
328
|
+
return list(models)
|
|
329
|
+
return [m for m in models if _row_matches(m, q)]
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def models_view(
|
|
333
|
+
device: str, catalog: HostCatalog | None, query: str = ""
|
|
334
|
+
) -> tuple[list[Line], list[Line]]:
|
|
374
335
|
"""The verdict, size, status and placement lead each row and the id and name follow, so a
|
|
375
336
|
narrow terminal keeps what decides the choice; ``model_detail`` gives the selected row's
|
|
376
337
|
reason in full."""
|
|
377
338
|
if catalog is None:
|
|
378
339
|
return [(f"{device} 尚未探测;按 p 只读探测后显示推荐。", "warn")], []
|
|
340
|
+
q = query.strip()
|
|
341
|
+
all_models = catalog["models"]
|
|
342
|
+
models = filter_models(all_models, q)
|
|
343
|
+
if q and not models:
|
|
344
|
+
return [(f"没有匹配「{q}」的模型;按 / 修改或留空恢复全部。", "warn")], []
|
|
379
345
|
placements = {str(p["id"]): p for p in catalog["placements"]}
|
|
380
346
|
|
|
381
347
|
def busy(placement_id: str) -> bool:
|
|
@@ -388,7 +354,6 @@ def models_view(device: str, catalog: HostCatalog | None) -> tuple[list[Line], l
|
|
|
388
354
|
return str(m.get("placement", {}).get("id", "-"))
|
|
389
355
|
|
|
390
356
|
rec = catalog["recommendation"]
|
|
391
|
-
models = catalog["models"]
|
|
392
357
|
verdicts = [_verdict(m, busy(spot(m))) for m in models]
|
|
393
358
|
statuses = [
|
|
394
359
|
recommend_cli.status_label(str(m.get("status", "")), m.get("validated_on") or ())
|
|
@@ -400,6 +365,11 @@ def models_view(device: str, catalog: HostCatalog | None) -> tuple[list[Line], l
|
|
|
400
365
|
spots = max([width(where(spot(m))) for m in models] + [4]) + 2
|
|
401
366
|
ids = max([width(str(m.get("id", ""))) for m in models] + [20]) + 2
|
|
402
367
|
gpu_rows = [p for p in catalog["placements"] if p.get("gpu_indices") and not p.get("uma")]
|
|
368
|
+
filter_row: list[Line] = (
|
|
369
|
+
[(f"筛选:「{q}」(命中 {len(models)}/{len(all_models)} 项,按 / 修改或清空)", "dim")]
|
|
370
|
+
if q
|
|
371
|
+
else []
|
|
372
|
+
)
|
|
403
373
|
head: list[Line] = [
|
|
404
374
|
(
|
|
405
375
|
f"推荐:{rec['id']}({rec['reason_text'].rstrip('。.')};位置 {where(rec['placement'])})"
|
|
@@ -409,6 +379,7 @@ def models_view(device: str, catalog: HostCatalog | None) -> tuple[list[Line], l
|
|
|
409
379
|
),
|
|
410
380
|
("容量适配与预测速度是估算,不是实测。", "dim"),
|
|
411
381
|
*(ALL_BUSY if gpu_rows and all(p.get("busy") for p in gpu_rows) else []),
|
|
382
|
+
*filter_row,
|
|
412
383
|
(
|
|
413
384
|
f" {pad('结论', judged)}{pad('大小', 10)}{pad('状态', stated)}{pad('位置', spots)}"
|
|
414
385
|
f"{pad('id', ids)}名称",
|
|
@@ -553,43 +524,3 @@ def services_view(device: str, records: list[FinishedRecord]) -> tuple[list[Line
|
|
|
553
524
|
for r in records
|
|
554
525
|
]
|
|
555
526
|
return head, rows
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
def modal_lines(modal: Modal | None, cols: int) -> list[Line]:
|
|
559
|
-
if isinstance(modal, Form):
|
|
560
|
-
lines: list[Line] = [(modal.title, "title")]
|
|
561
|
-
if modal.note:
|
|
562
|
-
lines.append((modal.note, "dim"))
|
|
563
|
-
lines.append(("", "text"))
|
|
564
|
-
labels = max(width(f.label) for f in modal.fields) + 2 # every label whole
|
|
565
|
-
for i, f in enumerate(modal.fields):
|
|
566
|
-
value = ("[x]" if f.value else "[ ]") if isinstance(f.value, bool) else f.value
|
|
567
|
-
cursor = "▏" if i == modal.index and not isinstance(f.value, bool) else ""
|
|
568
|
-
lines.append(
|
|
569
|
-
(
|
|
570
|
-
f" {pad(f.label, labels)}{value}{cursor}",
|
|
571
|
-
"select" if i == modal.index else "text",
|
|
572
|
-
)
|
|
573
|
-
)
|
|
574
|
-
return lines
|
|
575
|
-
if isinstance(modal, Confirm):
|
|
576
|
-
lines = [(modal.title, "title"), ("", "text"), *modal.body]
|
|
577
|
-
if modal.code is not None:
|
|
578
|
-
lines += [("", "text"), (f"输入 {modal.code}:{modal.typed}▏", "warn")]
|
|
579
|
-
return [(part, style) for text, style in lines for part in wrap(text, cols)]
|
|
580
|
-
if isinstance(modal, Picker):
|
|
581
|
-
lines = [(modal.title, "title"), ("", "text")]
|
|
582
|
-
return lines + [
|
|
583
|
-
(f" {item}", "select" if i == modal.index else "text")
|
|
584
|
-
for i, item in enumerate(modal.items)
|
|
585
|
-
]
|
|
586
|
-
return []
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
def modal_keys(modal: Modal) -> str:
|
|
590
|
-
"""The open dialog's keys, shown once in the footer."""
|
|
591
|
-
if isinstance(modal, Form):
|
|
592
|
-
return "↑↓ 切换字段 空格 切换开关 Enter 提交 Esc 取消"
|
|
593
|
-
if isinstance(modal, Confirm):
|
|
594
|
-
return modal.hint if modal.code is None else f"输入 {modal.code} 后 Enter 确认 Esc 取消"
|
|
595
|
-
return "↑↓ 选择 Enter 打开 Esc 取消"
|