fix(audio): detect transcript-wide hallucinations
This commit is contained in:
@@ -120,6 +120,42 @@ def test_audio_indexer_writes_timed_fts_entries_and_reconciles(tmp_path: Path, m
|
||||
assert json.loads(job["payload_json"]) == {"video_id": "video"}
|
||||
|
||||
|
||||
def test_repeated_hallucinations_are_saved_but_not_searchable(tmp_path: Path, monkeypatch):
|
||||
app = _app(tmp_path)
|
||||
service = app.state.services
|
||||
monkeypatch.setattr(service.media, "input_for", lambda _video: MediaInput("movie.mp4"))
|
||||
monkeypatch.setattr(
|
||||
service.media,
|
||||
"probe",
|
||||
lambda _media: {"raw": {"streams": [{"codec_type": "audio"}]}, "duration_ms": 30_000},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
service.speech,
|
||||
"transcribe",
|
||||
lambda *_args, **_kwargs: [
|
||||
{"text": "拜拜", "start_ms": index * 1000, "end_ms": index * 1000 + 800}
|
||||
for index in range(8)
|
||||
],
|
||||
)
|
||||
job_id = service.jobs.enqueue("transcribe_audio", {"video_id": "video"}, dedupe_key="audio:video")
|
||||
service.audio_indexer.index(job_id, "video", quality_repair=True)
|
||||
with service.db.read() as conn:
|
||||
entries = conn.execute(
|
||||
"SELECT count(*) FROM text_entries WHERE video_id='video' AND kind='audio'"
|
||||
).fetchone()[0]
|
||||
searchable = conn.execute(
|
||||
"SELECT count(*) FROM text_fts WHERE entry_id IN "
|
||||
"(SELECT id FROM text_entries WHERE video_id='video' AND kind='audio')"
|
||||
).fetchone()[0]
|
||||
video = conn.execute(
|
||||
"SELECT audio_quality_score,audio_quality_flags_json FROM videos WHERE id='video'"
|
||||
).fetchone()
|
||||
assert entries == 8
|
||||
assert searchable == 0
|
||||
assert video["audio_quality_score"] < 0.7
|
||||
assert "whole_ending_hallucination" in json.loads(video["audio_quality_flags_json"])
|
||||
|
||||
|
||||
def test_audio_indexer_retries_medium_memory_pressure(tmp_path: Path, monkeypatch):
|
||||
app = _app(tmp_path)
|
||||
service = app.state.services
|
||||
|
||||
Reference in New Issue
Block a user