AQIT 0.1.0
Loading...
Searching...
No Matches
help_display.py
Go to the documentation of this file.
1# Copyright (c) 2025-present Aquin Labs Private Limited. All Rights Reserved.
2"""Rich terminal layout for `aquin help` - no GPU / torch imports."""
3
4from __future__ import annotations
5
6from typing import Literal
7
8from rich.console import Console, Group
9from rich.panel import Panel
10from rich.rule import Rule
11from rich.table import Table
12from rich.text import Text
13from rich.theme import Theme
14
15SessionMode = Literal["llm"]
16
17_THEME = Theme({
18 "brand": "bold #facc15",
19 "heading": "bold bright_white",
20 "cmd": "bold #34d399",
21 "muted": "dim #6b7280",
22 "label": "dim #9ca3af",
23 "value": "#e5e7eb",
24 "accent": "#34d399",
25 "warn": "#fbbf24",
26})
27
28
29def _console() -> Console:
30 return Console(theme=_THEME, highlight=False)
31
32
33def _cmd_table(rows: list[tuple[str, str]]) -> Table:
34 table = Table(
35 box=None,
36 show_header=False,
37 pad_edge=False,
38 padding=(0, 1),
39 collapse_padding=True,
40 )
41 table.add_column(style="cmd", no_wrap=True, min_width=26, max_width=42)
42 table.add_column(style="muted", overflow="fold")
43 for cmd, desc in rows:
44 table.add_row(cmd, desc)
45 return table
46
47
48def _section(title: str, rows: list[tuple[str, str]], *, footnote: str | None = None) -> Group:
49 parts: list = [Rule(f"[heading]{title}[/]", style="dim #374151")]
50 if rows:
51 parts.append(_cmd_table(rows))
52 if footnote:
53 parts.append(Text(footnote, style="muted"))
54 return Group(*parts)
55
56
57def render_help(
58 *,
59 connected: bool,
60 mode: SessionMode | None,
61 show_llm: bool,
62 model_id: str | None = None,
63 show_embed: bool = False,
64) -> None:
65 from aquin.session_mode import mode_label
66
67 console = _console()
68
69 title = Text("aquin", style="brand")
70 title.append(" CLI", style="heading")
71
72 meta = Table.grid(padding=(0, 2))
73 meta.add_column(style="label", justify="right")
74 meta.add_column(style="value")
75 if model_id:
76 if mode:
77 meta.add_row(
78 "model",
79 Text.assemble((model_id, "value"), (f" ({mode_label(mode)})", "accent")),
80 )
81 else:
82 meta.add_row("model", model_id)
83 else:
84 meta.add_row("model", "[warn]not loaded[/]")
85
86 console.print(Panel(Group(title, "", meta), border_style="dim #374151", padding=(0, 1)))
87 console.print()
88
89 sections: list[Group] = []
90
91 sections.append(
93 "Meta",
94 [
95 ("status", "Loaded model & local engine"),
96 ("version", "Installed CLI version"),
97 ("license", "AQIT Apache 2.0 license"),
98 ("update", "Upgrade from PyPI"),
99 ("desktop install", "Install Aquin desktop (detect OS, confirm)"),
100 ("setup machine", "Prepare this host + model daemon; print SSH tunnel for desktop"),
101 ],
102 )
103 )
104
105 sections.append(
106 _section(
107 "Develop",
108 [
109 ("aqit train", "<recipe.yaml> DataRevision → train → Checkpoint → EvalGate"),
110 ],
111 footnote="AQIT: Recipe for CSV linear/boosting and LLM LoRA. Inspect after a failed gate.",
112 )
113 )
114
115 sections.append(
116 _section(
117 "Workflow",
118 [
119 ("load model", "<id> load & keep model resident in VRAM"),
120 ("unload", "free the resident model's VRAM ([--stop] to stop engine)"),
121 ("prompt", "<text> try the loaded model (quick generation)"),
122 ("help commands", "show tracked-command subcommands and flags"),
123 ("chat", "multi-turn agent (loaded model)"),
124 ],
125 footnote="aquin load model <id> -> aquin prompt \"hello\" / trace / chat. Model stays resident across commands; do not shell-bg the load command.",
126 )
127 )
128
129 sections.append(
130 _section(
131 "Models & SAE",
132 [
133 ("load model", "<hf-id> e.g. meta-llama/Llama-3.2-1B-Instruct"),
134 ("info sae", "<model-l{n}> SAE metadata"),
135 ("load sae", "<model-l{n}> | --user <name> | --path <file>"),
136 ("sae train / align", "train supports --activations <dir>"),
137 ("sae catalog-metrics / publish", "public catalog pipeline"),
138 ],
139 footnote="Pass HuggingFace ids directly. Self-train: aquin sae train.",
140 )
141 )
142
143 sections.append(
144 _section(
145 "Diff",
146 [
147 ("diff weight", "--checkpoint <path> per-layer ||dW|| + merge verdict"),
148 ("diff sae", "--checkpoint <path> feature activation deltas"),
149 ("diff residue", "--checkpoint <path> activation drift per layer"),
150 ],
151 )
152 )
153
154 sections.append(
155 _section(
156 "Check",
157 [
158 ("check trajectory", "--checkpoints <glob> multi-step trajectory"),
159 ],
160 )
161 )
162
163 sections.append(
164 _section(
165 "AQIT: capture and SAE",
166 [
167 ("aqit activations capture", "--dir <path>"),
168 ("aqit activations replay", "--from <capture_dir>"),
169 ("aqit features compare", "--from <capture_dir> --group <field>"),
170 ("aqit feature locate", "rank SAE features [--umap]"),
171 ("aqit sae train", "[--activations <dir>]"),
172 ],
173 )
174 )
175
176 if show_llm:
177 sections.append(
178 _section(
179 "AQIT: inspect | LLM",
180 [
181 ("aqit trace", "--prompt <text> --layer <n>"),
182 ("aqit feature logit", "--feature <idx>"),
183 ("aqit steer", "--feature_idx <n> [--save|--vector]"),
184 ("aqit check attention", "--prompt <text>"),
185 ("aqit check layer", "--prompts <json>"),
186 ("aqit benchmark", "--feature_idx <n>"),
187 ],
188 )
189 )
190 sections.append(
191 _section(
192 "AQIT: evals | LLM",
193 [
194 ("aqit eval consistency", "--query --templates"),
195 ("aqit eval suppress", "--topics <json>"),
196 ("aqit eval custom", "--name --prompts --reference_answers"),
197 ("aqit red-team", "[--vectors <json>]"),
198 ],
199 )
200 )
201 sections.append(
202 _section(
203 "AQIT: simulate",
204 [
205 ("aqit simulate", "--dataset <path>"),
206 ("aqit list simulation", "saved runs"),
207 ("aqit replay simulation", "--run_id <id>"),
208 ("aqit compare simulation", "--run_id_a --run_id_b"),
209 ],
210 )
211 )
212
213 sections.append(
214 _section(
215 "Shared",
216 [
217 ("commands list / show / clear", "tracked CLI outputs (local)"),
218 ("<tool-verb>", "any registry tool one-shot"),
219 ],
220 footnote="GPU tools support --check (JSON + PNG artifacts in cwd)",
221 )
222 )
223
224 if not connected:
225 console.print(
226 Text(
227 "Load a model with aquin load model <id>, then run tools.",
228 style="muted",
229 )
230 )
231 console.print()
232
233 for block in sections:
234 console.print(block)
235 console.print()
236
237 workflow = Table(box=None, show_header=False, pad_edge=False, padding=(0, 1))
238 workflow.add_column(style="label", justify="right", width=3)
239 workflow.add_column(style="cmd")
240 workflow.add_row("1.", "aqit train recipe.yaml")
241 workflow.add_row("2.", "if EvalGate FAIL → aqit inspect that run")
242 workflow.add_row("3.", "aqit load model … / aqit eval custom --prompts probes.jsonl")
243
244 console.print(Rule("[heading]Typical workflow[/]", style="dim #374151"))
245 console.print(workflow)
246 console.print()
247 console.print(Text("Docs: https://aquin.app/docs", style="muted"))
248 console.print(
249 Text(
250 "AQIT is Apache 2.0. Run aqit help for commands.",
251 style="muted",
252 )
253 )
Group _section(str title, list[tuple[str, str]] rows, *, str|None footnote=None)
None render_help(*, bool connected, SessionMode|None mode, bool show_llm, str|None model_id=None, bool show_embed=False)
Table _cmd_table(list[tuple[str, str]] rows)