AQIT
0.1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
types.py
Go to the documentation of this file.
1
# Copyright (c) 2025-present Aquin Labs Private Limited. All Rights Reserved.
2
# This file is part of the Aquin Engine. Unauthorized copying, modification,
3
# distribution, or use of this file, via any medium, is strictly prohibited.
4
# Proprietary and confidential. See LICENSE for terms.
5
6
from
__future__
import
annotations
7
from
typing
import
Any, Literal, Optional, Union
8
from
pydantic
import
BaseModel
9
10
11
# ─── CaptureBundle ────────────────────────────────────────────────────────────
12
13
class
CaptureBundle
(BaseModel):
14
version: int = 1
15
capture_id: str
16
session_id: str
17
model_id: str
18
hf_name: str
19
prompt: str
20
response: str
21
created_at: str
22
top_features: list[Any]
23
sae_layer: int
24
logit_lens: list[Any]
25
attention: dict[str, Any]
26
27
28
# ─── Refs + summaries ────────────────────────────────────────────────────────
29
30
class
CaptureRef
(BaseModel):
31
r2_key: str
32
size_bytes: int
33
34
35
class
ArtifactRef
(BaseModel):
36
r2_key: str
37
artifact_type: str
38
39
40
class
CaptureSummary
(BaseModel):
41
model_id: str
42
prompt: str
43
top_feature_count: int
44
45
46
# ─── EngineRegistration ───────────────────────────────────────────────────────
47
48
class
EngineRegistration
(BaseModel):
49
id: str
50
user_id: str
51
device: str
52
status: Literal[
"online"
,
"offline"
]
53
last_heartbeat: str
54
default_model_hf: Optional[str]
55
gpu_info: Optional[str]
56
57
58
# ─── SessionState ─────────────────────────────────────────────────────────────
59
60
class
SessionState
(BaseModel):
61
messages: list[dict[str, Any]]
62
subAgentPanels: list[dict[str, Any]]
63
captures: dict[str, CaptureRef]
64
artifacts: dict[str, ArtifactRef]
65
activeModelId: Optional[str]
66
67
68
# ─── SyncEvent — everything engine pushes to web ─────────────────────────────
69
70
class
SyncEventMessageAppend
(BaseModel):
71
type: Literal[
"message.append"
]
72
message: dict[str, Any]
73
74
class
SyncEventMessagePatch
(BaseModel):
75
type: Literal[
"message.patch"
]
76
message_id: str
77
patch: dict[str, Any]
78
79
class
SyncEventPanelUpsert
(BaseModel):
80
type: Literal[
"panel.upsert"
]
81
panel: dict[str, Any]
82
83
class
SyncEventPanelPatch
(BaseModel):
84
type: Literal[
"panel.patch"
]
85
panel_id: str
86
patch: dict[str, Any]
87
88
class
SyncEventCaptureReady
(BaseModel):
89
type: Literal[
"capture.ready"
]
90
capture_id: str
91
ref: CaptureRef
92
summary: CaptureSummary
93
94
class
SyncEventArtifactReady
(BaseModel):
95
type: Literal[
"artifact.ready"
]
96
artifact_id: str
97
ref: ArtifactRef
98
99
class
SyncEventToolStart
(BaseModel):
100
type: Literal[
"tool.start"
]
101
tool_call_id: str
102
tool_name: str
103
args: Any
104
105
class
SyncEventToolResult
(BaseModel):
106
type: Literal[
"tool.result"
]
107
tool_call_id: str
108
result: Any
109
card: Optional[dict[str, Any]] =
None
110
111
class
SyncEventSessionMeta
(BaseModel):
112
type: Literal[
"session.meta"
]
113
patch: dict[str, Any]
114
115
class
SyncEventEngineHeartbeat
(BaseModel):
116
type: Literal[
"engine.heartbeat"
]
117
device: str
118
gpu_info: Optional[str] =
None
119
120
class
SyncEventEngineDisconnect
(BaseModel):
121
type: Literal[
"engine.disconnect"
]
122
123
class
SyncEventEngineLog
(BaseModel):
124
type: Literal[
"engine.log"
]
125
line: str
126
127
class
SyncEventCommandAck
(BaseModel):
128
type: Literal[
"command.ack"
]
129
command_id: str
130
status: Literal[
"accepted"
,
"rejected"
,
"done"
]
131
error: Optional[str] =
None
132
133
134
SyncEvent = Union[
135
SyncEventMessageAppend,
136
SyncEventMessagePatch,
137
SyncEventPanelUpsert,
138
SyncEventPanelPatch,
139
SyncEventCaptureReady,
140
SyncEventArtifactReady,
141
SyncEventToolStart,
142
SyncEventToolResult,
143
SyncEventSessionMeta,
144
SyncEventEngineHeartbeat,
145
SyncEventEngineDisconnect,
146
SyncEventEngineLog,
147
SyncEventCommandAck,
148
]
149
150
def
parse_sync_event
(data: dict[str, Any]) -> SyncEvent:
151
from
pydantic
import
TypeAdapter
152
return
TypeAdapter(SyncEvent).validate_python(data)
153
154
155
# ─── WebCommand — every UI action web sends to engine ────────────────────────
156
157
class
CmdBase
(BaseModel):
158
command_id: str
159
160
# core session
161
class
CmdChat
(
CmdBase
):
162
type: Literal[
"command.chat"
]
163
text: str
164
hidden: Optional[bool] =
None
165
166
class
CmdApprove
(
CmdBase
):
167
type: Literal[
"command.approve"
]
168
plan_id: str
169
170
class
CmdAbort
(
CmdBase
):
171
type: Literal[
"command.abort"
]
172
job_id: Optional[str] =
None
173
174
class
CmdSetModel
(
CmdBase
):
175
type: Literal[
"command.set_model"
]
176
model_id: str
177
178
class
CmdSetDataset
(
CmdBase
):
179
type: Literal[
"command.set_dataset"
]
180
rows: list[Any]
181
182
class
CmdUI
(
CmdBase
):
183
type: Literal[
"command.ui"
]
184
action: str
185
payload: Any
186
187
# inspection
188
class
CmdInspect
(
CmdBase
):
189
type: Literal[
"command.inspect"
]
190
prompt: str
191
model_id: Optional[str] =
None
192
193
class
CmdRunFullInspection
(
CmdBase
):
194
type: Literal[
"command.run_full_inspection"
]
195
prompt: Optional[str] =
None
196
197
class
CmdRunBenchmarksOnTopFeature
(
CmdBase
):
198
type: Literal[
"command.run_benchmarks_on_top_feature"
]
199
feature_idx: int
200
201
class
CmdRunAudit
(
CmdBase
):
202
type: Literal[
"command.run_audit"
]
203
204
class
CmdRunConsistencyEval
(
CmdBase
):
205
type: Literal[
"command.run_consistency_eval"
]
206
query: str
207
templates: list[str]
208
209
class
CmdRunSuppressionEval
(
CmdBase
):
210
type: Literal[
"command.run_suppression_eval"
]
211
topics: dict[str, list[str]]
212
213
class
CmdRunBoundaryEval
(
CmdBase
):
214
type: Literal[
"command.run_boundary_eval"
]
215
prompts: list[str]
216
217
class
CmdGetFeatureLogits
(
CmdBase
):
218
type: Literal[
"command.get_feature_logits"
]
219
feature_idx: int
220
top_k: Optional[int] =
None
221
222
class
CmdGetFeatureNeighbors
(
CmdBase
):
223
type: Literal[
"command.get_feature_neighbors"
]
224
feature_idx: int
225
top_k: Optional[int] =
None
226
227
class
CmdRunLayerAnalysis
(
CmdBase
):
228
type: Literal[
"command.run_layer_analysis"
]
229
prompts: Optional[list[str]] =
None
230
top_k: Optional[int] =
None
231
in_domain_prompts: Optional[list[str]] =
None
232
ood_prompts: Optional[list[str]] =
None
233
234
class
CmdRunPerturbationSensitivity
(
CmdBase
):
235
type: Literal[
"command.run_perturbation_sensitivity"
]
236
prompt: str
237
n_channels: Optional[int] =
None
238
method: Optional[Literal[
"dropout"
,
"gaussian"
]] =
None
239
240
class
CmdRunAttentionRouting
(
CmdBase
):
241
type: Literal[
"command.run_attention_routing"
]
242
prompt: str
243
top_k: Optional[int] =
None
244
245
# steering
246
class
CmdSteer
(
CmdBase
):
247
type: Literal[
"command.steer"
]
248
capture_id: str
249
feature_idx: int
250
scale: float
251
252
class
CmdRunSteerAndShow
(
CmdBase
):
253
type: Literal[
"command.run_steer_and_show"
]
254
prompt: str
255
feature_idx: int
256
feature_label: str
257
strength: Optional[float] =
None
258
max_new_tokens: Optional[int] =
None
259
260
class
SteerFeature
(BaseModel):
261
feature_idx: int
262
strength: float
263
label: str
264
265
class
CmdRunMultiSteer
(
CmdBase
):
266
type: Literal[
"command.run_multi_steer"
]
267
prompt: str
268
features: list[SteerFeature]
269
max_new_tokens: Optional[int] =
None
270
271
# UMAP
272
class
CmdEnsureUmapLoaded
(
CmdBase
):
273
type: Literal[
"command.ensure_umap_loaded"
]
274
275
# dataset (LLM)
276
class
CmdDatasetGenerate
(
CmdBase
):
277
type: Literal[
"command.dataset_generate"
]
278
topic: str
279
count: Optional[int] =
None
280
format: Optional[str] =
None
281
282
# simulation
283
class
CmdRunSimulation
(
CmdBase
):
284
type: Literal[
"command.run_simulation"
]
285
topic: Optional[str] =
None
286
dataset: Optional[str] =
None
287
algo: Optional[str] =
None
288
count: Optional[int] =
None
289
rank: Optional[int] =
None
290
alpha: Optional[float] =
None
291
lr: Optional[float] =
None
292
epochs: Optional[int] =
None
293
dropout: Optional[float] =
None
294
targetModules: Optional[list[str]] =
None
295
warmupSteps: Optional[int] =
None
296
gradClip: Optional[float] =
None
297
weightDecay: Optional[float] =
None
298
gradAccumSteps: Optional[int] =
None
299
optimizer: Optional[Literal[
"adamw"
,
"sgd"
,
"lion"
]] =
None
300
scheduler: Optional[Literal[
"cosine"
,
"linear"
,
"constant"
]] =
None
301
maxSeqLen: Optional[int] =
None
302
useQlora: Optional[bool] =
None
303
use_rlhf: Optional[bool] =
None
304
rlhf_beta: Optional[float] =
None
305
rows: Optional[list[dict]] =
None
306
307
class
CmdListSimulationRuns
(
CmdBase
):
308
type: Literal[
"command.list_simulation_runs"
]
309
310
class
CmdLoadSimulationRun
(
CmdBase
):
311
type: Literal[
"command.load_simulation_run"
]
312
run_id: str
313
314
class
CmdCompareSimulations
(
CmdBase
):
315
type: Literal[
"command.compare_simulations"
]
316
run_id_a: str
317
run_id_b: str
318
label_a: Optional[str] =
None
319
label_b: Optional[str] =
None
320
321
# interactive cards
322
class
CmdRunRedTeam
(
CmdBase
):
323
type: Literal[
"command.run_red_team"
]
324
vectors: Optional[list[str]] =
None
325
326
class
CmdCheckWeights
(
CmdBase
):
327
type: Literal[
"command.check_weights"
]
328
collapse_threshold: Optional[float] =
None
329
330
class
CmdRunCustomEval
(
CmdBase
):
331
type: Literal[
"command.run_custom_eval"
]
332
name: str
333
prompts: list[str]
334
reference_answers: list[str]
335
description: Optional[str] =
None
336
threshold: Optional[float] =
None
337
max_tokens: Optional[int] =
None
338
temperature: Optional[float] =
None
339
340
# session memory
341
class
CmdWriteSessionMemory
(
CmdBase
):
342
type: Literal[
"command.write_session_memory"
]
343
key: str
344
value: Any
345
346
class
CmdReadSessionMemory
(
CmdBase
):
347
type: Literal[
"command.read_session_memory"
]
348
key: str
349
350
351
WebCommand = Union[
352
CmdChat, CmdApprove, CmdAbort, CmdSetModel, CmdSetDataset, CmdUI,
353
CmdInspect, CmdRunFullInspection, CmdRunBenchmarksOnTopFeature, CmdRunAudit,
354
CmdRunConsistencyEval, CmdRunSuppressionEval, CmdRunBoundaryEval,
355
CmdGetFeatureLogits, CmdGetFeatureNeighbors,
356
CmdRunLayerAnalysis, CmdRunPerturbationSensitivity, CmdRunAttentionRouting,
357
CmdSteer, CmdRunSteerAndShow, CmdRunMultiSteer,
358
CmdEnsureUmapLoaded,
359
CmdDatasetGenerate,
360
CmdRunSimulation,
361
CmdListSimulationRuns, CmdLoadSimulationRun, CmdCompareSimulations,
362
CmdRunRedTeam, CmdCheckWeights,
363
CmdRunCustomEval,
364
CmdWriteSessionMemory, CmdReadSessionMemory,
365
]
366
367
def
parse_web_command
(data: dict[str, Any]) -> WebCommand:
368
from
pydantic
import
TypeAdapter
369
return
TypeAdapter(WebCommand).validate_python(data)
370
371
372
__all__ = [
373
"CaptureBundle"
,
374
"CaptureRef"
,
"ArtifactRef"
,
"CaptureSummary"
,
375
"EngineRegistration"
,
"SessionState"
,
376
"SyncEvent"
,
"parse_sync_event"
,
377
"WebCommand"
,
"parse_web_command"
,
378
"CmdChat"
,
"CmdApprove"
,
"CmdAbort"
,
"CmdSetModel"
,
"CmdSetDataset"
,
"CmdUI"
,
379
"CmdInspect"
,
"CmdRunFullInspection"
,
"CmdRunBenchmarksOnTopFeature"
,
"CmdRunAudit"
,
380
"CmdRunConsistencyEval"
,
"CmdRunSuppressionEval"
,
"CmdRunBoundaryEval"
,
381
"CmdGetFeatureLogits"
,
"CmdGetFeatureNeighbors"
,
382
"CmdRunLayerAnalysis"
,
"CmdRunPerturbationSensitivity"
,
"CmdRunAttentionRouting"
,
383
"CmdSteer"
,
"CmdRunSteerAndShow"
,
"CmdRunMultiSteer"
,
"SteerFeature"
,
384
"CmdEnsureUmapLoaded"
,
385
"CmdDatasetGenerate"
,
386
"CmdRunSimulation"
,
387
"CmdListSimulationRuns"
,
"CmdLoadSimulationRun"
,
"CmdCompareSimulations"
,
388
"CmdRunRedTeam"
,
"CmdCheckWeights"
,
389
"CmdRunCustomEval"
,
390
"CmdWriteSessionMemory"
,
"CmdReadSessionMemory"
,
391
]
aquin.types.ArtifactRef
Definition
types.py:39
aquin.types.CaptureBundle
Definition
types.py:17
aquin.types.CaptureRef
Definition
types.py:34
aquin.types.CaptureSummary
Definition
types.py:44
aquin.types.CmdAbort
Definition
types.py:174
aquin.types.CmdApprove
Definition
types.py:170
aquin.types.CmdBase
Definition
types.py:161
aquin.types.CmdChat
Definition
types.py:165
aquin.types.CmdCheckWeights
Definition
types.py:330
aquin.types.CmdCompareSimulations
Definition
types.py:318
aquin.types.CmdDatasetGenerate
Definition
types.py:280
aquin.types.CmdEnsureUmapLoaded
Definition
types.py:276
aquin.types.CmdGetFeatureLogits
Definition
types.py:221
aquin.types.CmdGetFeatureNeighbors
Definition
types.py:226
aquin.types.CmdInspect
Definition
types.py:192
aquin.types.CmdListSimulationRuns
Definition
types.py:311
aquin.types.CmdLoadSimulationRun
Definition
types.py:314
aquin.types.CmdReadSessionMemory
Definition
types.py:350
aquin.types.CmdRunAttentionRouting
Definition
types.py:244
aquin.types.CmdRunAudit
Definition
types.py:205
aquin.types.CmdRunBenchmarksOnTopFeature
Definition
types.py:201
aquin.types.CmdRunBoundaryEval
Definition
types.py:217
aquin.types.CmdRunConsistencyEval
Definition
types.py:208
aquin.types.CmdRunCustomEval
Definition
types.py:334
aquin.types.CmdRunFullInspection
Definition
types.py:197
aquin.types.CmdRunLayerAnalysis
Definition
types.py:231
aquin.types.CmdRunMultiSteer
Definition
types.py:269
aquin.types.CmdRunPerturbationSensitivity
Definition
types.py:238
aquin.types.CmdRunRedTeam
Definition
types.py:326
aquin.types.CmdRunSimulation
Definition
types.py:287
aquin.types.CmdRunSteerAndShow
Definition
types.py:256
aquin.types.CmdRunSuppressionEval
Definition
types.py:213
aquin.types.CmdSetDataset
Definition
types.py:182
aquin.types.CmdSetModel
Definition
types.py:178
aquin.types.CmdSteer
Definition
types.py:250
aquin.types.CmdUI
Definition
types.py:186
aquin.types.CmdWriteSessionMemory
Definition
types.py:345
aquin.types.EngineRegistration
Definition
types.py:52
aquin.types.SessionState
Definition
types.py:64
aquin.types.SteerFeature
Definition
types.py:264
aquin.types.SyncEventArtifactReady
Definition
types.py:98
aquin.types.SyncEventCaptureReady
Definition
types.py:92
aquin.types.SyncEventCommandAck
Definition
types.py:131
aquin.types.SyncEventEngineDisconnect
Definition
types.py:124
aquin.types.SyncEventEngineHeartbeat
Definition
types.py:119
aquin.types.SyncEventEngineLog
Definition
types.py:127
aquin.types.SyncEventMessageAppend
Definition
types.py:74
aquin.types.SyncEventMessagePatch
Definition
types.py:78
aquin.types.SyncEventPanelPatch
Definition
types.py:87
aquin.types.SyncEventPanelUpsert
Definition
types.py:83
aquin.types.SyncEventSessionMeta
Definition
types.py:115
aquin.types.SyncEventToolResult
Definition
types.py:109
aquin.types.SyncEventToolStart
Definition
types.py:103
aquin.types.parse_web_command
WebCommand parse_web_command(dict[str, Any] data)
Definition
types.py:371
aquin.types.parse_sync_event
SyncEvent parse_sync_event(dict[str, Any] data)
Definition
types.py:154
aquin
types.py
AQIT · Aquin Labs Private Limited · Apache 2.0 · Generated by
1.18.0