-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschemas.py
More file actions
361 lines (283 loc) · 9.26 KB
/
Copy pathschemas.py
File metadata and controls
361 lines (283 loc) · 9.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
from __future__ import annotations
from datetime import datetime
from typing import Literal, cast
from uuid import UUID
from pydantic import BaseModel, ConfigDict, Field
from app.runtime_config import AUTO_ENGINE
MAXIMUM_LANGUAGE_TAG_LENGTH = 20
MINIMUM_CUSTOM_MODEL_URL_LENGTH = 12
MAXIMUM_CUSTOM_MODEL_URL_LENGTH = 2_000
MAXIMUM_CPU_THREADS = 256
FORBID_EXTRA_FIELDS: Literal["forbid"] = "forbid"
class CreateSessionRequest(BaseModel):
model_config = ConfigDict(extra=FORBID_EXTRA_FIELDS)
client_session_id: UUID
language: str = Field(
default=AUTO_ENGINE,
max_length=MAXIMUM_LANGUAGE_TAG_LENGTH,
pattern=r"^(?:[A-Za-z-]+|hinglish_roman)$",
)
style: Literal[
"raw",
"clean",
"formal",
"casual",
"very_casual",
"excited",
] = "casual"
class SessionResponse(BaseModel):
session_id: UUID
job_id: str
state: str
language: str
style: str
transcript: str | None = None
error_code: str | None = None
created_at: datetime
updated_at: datetime
class HealthResponse(BaseModel):
status: Literal["ok"] = "ok"
engine_ready: bool
engine: str
streaming_supported: bool
# What the loaded model can actually do with the `language` field, so a client
# can stop offering choices it cannot honour. An empty list means "unknown" —
# an older gateway, no model selected, or a user's own imported model — and
# clients must keep every language available rather than locking the picker.
languages: list[str] = []
# True when the model picks the language itself. `languages` then describes
# what it transcribes well, not what a client may ask for.
detects_language_automatically: bool = False
class LivenessResponse(BaseModel):
status: Literal["ok"] = "ok"
uptime_seconds: int
class ReadinessResponse(BaseModel):
status: Literal["ready", "not_ready"]
engine_ready: bool
engine: str
probe_age_seconds: float
warmup_state: Literal["pending", "warming", "complete", "unsupported", "unavailable", "failed"]
class ModelResponse(BaseModel):
id: str
ready: bool
local: Literal[True] = True
class DeleteResponse(BaseModel):
deleted: bool
class DependencyStatus(BaseModel):
name: str
available: bool
path: str | None = None
install_hint: str | None = None
class SystemStatus(BaseModel):
os: str
arch: str
chip: str
ram_gb: float
is_apple_silicon: bool
logical_cpus: int
effective_cpus: float
containerized: bool
accelerators: list[str]
cpu_features: list[str]
class EngineStatus(BaseModel):
id: str
name: str
ready: bool
class PathStatus(BaseModel):
"""On-disk locations the gateway owns.
``data_dir`` holds sessions, device tokens, and gateway-owned on-disk
data/logs. Desktop embedders must not place that tree under the host
app's Application Support (or equivalent) directory.
"""
data_dir: str
models_dir: str
config_file: str
token_file: str
class SetupChecklist(BaseModel):
token_configured: bool
ffmpeg_available: bool
engine_binary_available: bool
model_installed: bool
engine_ready: bool
class MetricsHistoryPoint(BaseModel):
"""One Live-operations sample for sparklines (in-process ring buffer)."""
uptime_seconds: int
queue_depth: int
active_transcriptions: int
last_latency_ms: int | None = None
successful_transcriptions: int = 0
failed_transcriptions: int = 0
class OperationalMetricsStatus(BaseModel):
uptime_seconds: int
queue_depth: int
active_transcriptions: int
concurrency_limit: int
successful_transcriptions: int
failed_transcriptions: int
rejected_transcriptions: int
average_latency_ms: int | None
last_latency_ms: int | None
normalization_ms: int | None = None
model_load_ms: int | None = None
inference_ms: int | None = None
audio_duration_ms: int | None = None
real_time_factor: float | None = None
peak_memory_mb: float | None = None
history: list[MetricsHistoryPoint] = []
class ReadinessStatus(BaseModel):
probe_age_seconds: float
warmup_state: Literal["pending", "warming", "complete", "unsupported", "unavailable", "failed"]
warmed_bytes: int
class CommitStatus(BaseModel):
"""The source commit the running gateway was built from."""
sha: str
short_sha: str
subject: str
committed_at: datetime | None = None
class AdminStatusResponse(BaseModel):
status: Literal["ok"] = "ok"
version: str
commit: CommitStatus | None = None
engine: EngineStatus
system: SystemStatus
dependencies: list[DependencyStatus]
paths: PathStatus
bind_host: str
port: int
setup: SetupChecklist
metrics: OperationalMetricsStatus
readiness: ReadinessStatus
# Desktop embed: Pairable when a phone-reachable pairing URL exists;
# Ready-for-dictation when the engine can transcribe. Never includes the
# bearer token; clients decode that from GET /v1/admin/pairing's payload.
pairable: bool
pairing_url: str | None = None
ready_for_dictation: bool
class AdminModelEntry(BaseModel):
id: str
engine: str
label: str
size_bytes: int
languages: str
quality: str
family: str
description: str
source: str
source_url: str | None = None
supports_streaming: bool = False
license_name: str = "See model source"
commercial_use: bool = True
detects_language_automatically: bool = False
# Named languages behind the `languages` summary, and the codes the filter
# matches on. Empty codes mean "matches any language" rather than none.
language_names: list[str] = []
language_codes: list[str] = []
state: Literal["installed", "downloading", "not_installed"]
active: bool
recommended: bool
progress: float | None = None
downloaded_bytes: int | None = None
total_bytes: int | None = None
error: str | None = None
retired: bool = False
replacement_id: str | None = None
retirement_reason: str | None = None
class CustomDownloadRequest(BaseModel):
model_config = ConfigDict(extra=FORBID_EXTRA_FIELDS)
url: str = Field(
min_length=MINIMUM_CUSTOM_MODEL_URL_LENGTH,
max_length=MAXIMUM_CUSTOM_MODEL_URL_LENGTH,
)
# Optional: a model card's published SHA-256. When given, the download is
# discarded unless it matches, which is the only integrity guarantee
# available for a URL the catalog does not vouch for.
sha256: str | None = Field(default=None, max_length=100)
class DeviceTokenEntry(BaseModel):
id: str
label: str
created_at: datetime | None
revocable: bool
class DeviceTokenCreateRequest(BaseModel):
model_config = ConfigDict(extra=FORBID_EXTRA_FIELDS)
label: str = Field(min_length=1, max_length=100)
class DeviceTokenCreateResponse(BaseModel):
id: str
label: str
token: str
created_at: datetime
class DeviceTokenRevokeResponse(BaseModel):
revoked: bool
class DownloadResponse(BaseModel):
model_id: str
status: str
class ConfigResponse(BaseModel):
engine: str
available_engines: list[str]
whisper_model: str | None = None
whisperkit_model: str | None = None
faster_whisper_model: str | None = None
moonshine_model: str = "moonshine:en"
moonshine_language: str = "en"
sherpa_model: str | None = None
mlx_audio_model: str | None = None
compute_device: str = AUTO_ENGINE
compute_type: str = AUTO_ENGINE
cpu_threads: int = 0
class ConfigUpdateRequest(BaseModel):
model_config = ConfigDict(extra=FORBID_EXTRA_FIELDS)
engine: Literal[
"auto",
"vocamac",
"handy",
"whisper.cpp",
"whisperkit",
"faster-whisper",
"moonshine",
"sherpa-onnx",
"mlx-audio",
]
compute_device: Literal["auto", "cpu", "cuda"] = cast(Literal["auto"], AUTO_ENGINE)
compute_type: Literal["auto", "int8", "int8_float16", "float16", "float32"] = cast(
Literal["auto"], AUTO_ENGINE
)
cpu_threads: int = Field(default=0, ge=0, le=MAXIMUM_CPU_THREADS)
class SelectModelResponse(BaseModel):
engine: EngineStatus
class TestTranscriptionResponse(BaseModel):
transcript: str
engine: str
duration_ms: int
normalization_ms: int
model_load_ms: int
inference_ms: int
audio_duration_ms: int
real_time_factor: float | None
peak_memory_mb: float | None
class OpenAITranscriptionResponse(BaseModel):
text: str
class ErrorDetail(BaseModel):
code: str
message: str
recoverable: bool
class ErrorEnvelope(BaseModel):
error: ErrorDetail
class DiagnosticsBundle(BaseModel):
"""A redacted operational snapshot, safe to attach to a bug report.
Never contains the bearer token, recording audio, transcript text, or
session identifiers — only setup, dependency, hardware, and counter data
already shown in the authenticated WebUI.
"""
generated_at: datetime
version: str
commit: CommitStatus | None = None
engine: EngineStatus
system: SystemStatus
dependencies: list[DependencyStatus]
paths: PathStatus
bind_host: str
port: int
setup: SetupChecklist
metrics: OperationalMetricsStatus
readiness: ReadinessStatus
config: ConfigResponse
never_included: list[str]