Add hotwords form field to whisper service

Hotwords give per-request logit boosts to specified terms throughout
decoding (not just as prefix context like initial_prompt). Measured on
a cardiology dictation: 8/8 correct fachbegriffe vs. 3/8 without.
This commit is contained in:
2026-04-14 00:22:36 +02:00
parent 8a19fc370d
commit 83d3a52df7
+2
View File
@@ -61,6 +61,7 @@ async def asr(
output: str = Query("txt"), output: str = Query("txt"),
language: Optional[str] = Query(None), language: Optional[str] = Query(None),
initial_prompt: Optional[str] = Form(None), initial_prompt: Optional[str] = Form(None),
hotwords: Optional[str] = Form(None),
): ):
suffix = os.path.splitext(audio_file.filename or "")[1] or ".bin" suffix = os.path.splitext(audio_file.filename or "")[1] or ".bin"
tmp = tempfile.NamedTemporaryFile(suffix=suffix, delete=False) tmp = tempfile.NamedTemporaryFile(suffix=suffix, delete=False)
@@ -85,6 +86,7 @@ async def asr(
log_prob_threshold=-1.0, log_prob_threshold=-1.0,
compression_ratio_threshold=2.4, compression_ratio_threshold=2.4,
initial_prompt=initial_prompt, initial_prompt=initial_prompt,
hotwords=hotwords,
) )
segments = list(segments_gen) segments = list(segments_gen)
infer_secs = time.monotonic() - t0 infer_secs = time.monotonic() - t0