Simplified the json schema passed to the LLM, and implemented more forgiving error handling for LLM proposed corrections
This commit is contained in:
@@ -20,69 +20,95 @@ def test_apply_corrections_uses_threshold_and_sorts_chronologically():
|
||||
transcript = _transcript()
|
||||
corrections = [
|
||||
CorrectionCandidate(
|
||||
segment_index=0,
|
||||
speaker="Eric",
|
||||
start=10.0,
|
||||
end=11.0,
|
||||
segment_id=0,
|
||||
original_text="I ask Chontia.",
|
||||
corrected_text="I ask Chauntea.",
|
||||
confidence=0.8,
|
||||
)
|
||||
]
|
||||
|
||||
revised = apply_corrections(transcript, corrections, confidence_threshold=0.8)
|
||||
result = apply_corrections(transcript, corrections, confidence_threshold=0.8)
|
||||
|
||||
assert [segment.speaker for segment in revised] == ["Mike", "Eric"]
|
||||
assert revised[1].text == "I ask Chauntea."
|
||||
assert [segment.speaker for segment in result.transcript] == ["Mike", "Eric"]
|
||||
assert result.transcript[1].text == "I ask Chauntea."
|
||||
assert result.skipped == []
|
||||
|
||||
|
||||
def test_apply_corrections_ignores_below_threshold():
|
||||
transcript = _transcript()
|
||||
corrections = [
|
||||
CorrectionCandidate(
|
||||
segment_index=0,
|
||||
speaker="Eric",
|
||||
start=10.0,
|
||||
end=11.0,
|
||||
segment_id=0,
|
||||
original_text="I ask Chontia.",
|
||||
corrected_text="I ask Chauntea.",
|
||||
confidence=0.79,
|
||||
)
|
||||
]
|
||||
|
||||
revised = apply_corrections(transcript, corrections, confidence_threshold=0.8)
|
||||
result = apply_corrections(transcript, corrections, confidence_threshold=0.8)
|
||||
|
||||
assert revised[1].text == "I ask Chontia."
|
||||
assert result.transcript[1].text == "I ask Chontia."
|
||||
assert result.skipped == []
|
||||
|
||||
|
||||
def test_apply_corrections_rejects_duplicate_targets():
|
||||
def test_apply_corrections_skips_duplicate_targets():
|
||||
transcript = _transcript()
|
||||
correction = CorrectionCandidate(
|
||||
segment_index=0,
|
||||
speaker="Eric",
|
||||
start=10.0,
|
||||
end=11.0,
|
||||
first = CorrectionCandidate(
|
||||
segment_id=0,
|
||||
original_text="I ask Chontia.",
|
||||
corrected_text="I ask Chauntea.",
|
||||
confidence=0.8,
|
||||
)
|
||||
second = CorrectionCandidate(
|
||||
segment_id=0,
|
||||
original_text="I ask Chontia.",
|
||||
corrected_text="I ask Something Else.",
|
||||
confidence=0.9,
|
||||
)
|
||||
|
||||
with pytest.raises(AuditaValidationError):
|
||||
apply_corrections(transcript, [correction, correction], confidence_threshold=0.8)
|
||||
result = apply_corrections(transcript, [first, second], confidence_threshold=0.8)
|
||||
|
||||
assert result.transcript[1].text == "I ask Chauntea."
|
||||
assert len(result.skipped) == 1
|
||||
assert result.skipped[0].segment_id == 0
|
||||
assert "duplicate" in result.skipped[0].reason
|
||||
|
||||
|
||||
def test_apply_corrections_rejects_mismatched_original_text():
|
||||
def test_apply_corrections_skips_mismatched_original_text():
|
||||
transcript = _transcript()
|
||||
correction = CorrectionCandidate(
|
||||
segment_index=0,
|
||||
speaker="Eric",
|
||||
start=10.0,
|
||||
end=11.0,
|
||||
segment_id=0,
|
||||
original_text="Different text.",
|
||||
corrected_text="I ask Chauntea.",
|
||||
confidence=0.8,
|
||||
)
|
||||
|
||||
with pytest.raises(AuditaValidationError):
|
||||
apply_corrections(transcript, [correction], confidence_threshold=0.8)
|
||||
result = apply_corrections(transcript, [correction], confidence_threshold=0.8)
|
||||
|
||||
assert result.transcript[1].text == "I ask Chontia."
|
||||
assert len(result.skipped) == 1
|
||||
assert result.skipped[0].segment_id == 0
|
||||
assert result.skipped[0].actual_text == "I ask Chontia."
|
||||
assert "original_text" in result.skipped[0].reason
|
||||
|
||||
|
||||
def test_apply_corrections_skips_missing_segment_id():
|
||||
transcript = _transcript()
|
||||
correction = CorrectionCandidate(
|
||||
segment_id=99,
|
||||
original_text="Missing.",
|
||||
corrected_text="Still missing.",
|
||||
confidence=0.8,
|
||||
)
|
||||
|
||||
result = apply_corrections(transcript, [correction], confidence_threshold=0.8)
|
||||
|
||||
assert [segment.text for segment in result.transcript] == ["Then Lyra.", "I ask Chontia."]
|
||||
assert len(result.skipped) == 1
|
||||
assert result.skipped[0].segment_id == 99
|
||||
assert "does not exist" in result.skipped[0].reason
|
||||
|
||||
|
||||
def test_apply_corrections_rejects_invalid_threshold():
|
||||
with pytest.raises(AuditaValidationError):
|
||||
apply_corrections(_transcript(), [], confidence_threshold=1.1)
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import json
|
||||
|
||||
from audita.config import AuditaConfig
|
||||
from audita.errors import AuditaValidationError
|
||||
from audita.pipeline import process_transcript
|
||||
from audita.schemas import CorrectionCandidate, CorrectionSet, parse_glossary_yaml, parse_transcript_json
|
||||
|
||||
@@ -51,10 +48,7 @@ def _transcript():
|
||||
|
||||
def test_pipeline_processes_with_fake_llm_and_cleans_work_dir(tmp_path):
|
||||
correction = CorrectionCandidate(
|
||||
segment_index=0,
|
||||
speaker="Eric",
|
||||
start=0.0,
|
||||
end=1.0,
|
||||
segment_id=0,
|
||||
original_text="I ask Chontia.",
|
||||
corrected_text="I ask Chauntea.",
|
||||
confidence=0.95,
|
||||
@@ -73,27 +67,30 @@ def test_pipeline_processes_with_fake_llm_and_cleans_work_dir(tmp_path):
|
||||
assert list((tmp_path / "work").iterdir()) == []
|
||||
|
||||
|
||||
def test_pipeline_preserves_work_dir_on_failure(tmp_path):
|
||||
def test_pipeline_skips_bad_correction_and_preserves_diagnostics(tmp_path):
|
||||
correction = CorrectionCandidate(
|
||||
segment_index=0,
|
||||
speaker="Eric",
|
||||
start=0.0,
|
||||
end=1.0,
|
||||
segment_id=0,
|
||||
original_text="Different text.",
|
||||
corrected_text="I ask Chauntea.",
|
||||
confidence=0.95,
|
||||
)
|
||||
fake_client = FakeLLMClient([CorrectionSet(corrections=[correction])])
|
||||
progress = []
|
||||
|
||||
with pytest.raises(AuditaValidationError):
|
||||
process_transcript(
|
||||
_transcript(),
|
||||
_glossary(),
|
||||
_config(tmp_path),
|
||||
llm_client=fake_client,
|
||||
)
|
||||
revised = process_transcript(
|
||||
_transcript(),
|
||||
_glossary(),
|
||||
_config(tmp_path),
|
||||
llm_client=fake_client,
|
||||
progress=progress.append,
|
||||
)
|
||||
|
||||
assert revised[0].text == "I ask Chontia."
|
||||
assert any("Skipping correction for segment 0" in message for message in progress)
|
||||
preserved = list((tmp_path / "work").iterdir())
|
||||
assert len(preserved) == 1
|
||||
assert (Path(preserved[0]) / "section-0000.json").exists()
|
||||
|
||||
skipped_path = preserved[0] / "skipped-corrections.json"
|
||||
assert skipped_path.exists()
|
||||
diagnostics = json.loads(skipped_path.read_text(encoding="utf-8"))
|
||||
assert diagnostics["skipped_corrections"][0]["segment_id"] == 0
|
||||
assert "original_text" in diagnostics["skipped_corrections"][0]["reason"]
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import json
|
||||
|
||||
from audita.chunking import chunk_transcript
|
||||
from audita.prompts import build_glossary_correction_messages
|
||||
from audita.schemas import parse_glossary_yaml, parse_transcript_json
|
||||
@@ -32,3 +34,31 @@ def test_prompt_requires_acoustically_plausible_transcription_errors():
|
||||
assert '"gestures" to "Jesters"' in prompt_text
|
||||
assert '"Lyra" to "Jesters"' in prompt_text
|
||||
assert "should be omitted" in prompt_text
|
||||
|
||||
|
||||
def test_prompt_uses_simplified_segment_payload():
|
||||
transcript = parse_transcript_json(
|
||||
"""
|
||||
[
|
||||
{"speaker": "Eric", "start": 0.0, "end": 1.0, "text": "The gestures are nearby."}
|
||||
]
|
||||
"""
|
||||
)
|
||||
glossary = parse_glossary_yaml(
|
||||
"""
|
||||
glossary:
|
||||
- name: "Jesters"
|
||||
category: faction
|
||||
summary: "The Jesters are a local faction."
|
||||
"""
|
||||
)
|
||||
section = chunk_transcript(transcript, max_section_tokens=16000)[0]
|
||||
|
||||
messages = build_glossary_correction_messages(section, glossary)
|
||||
transcript_json = messages[1]["content"].split("Transcript section:\n", maxsplit=1)[1]
|
||||
prompt_segments = json.loads(transcript_json)
|
||||
|
||||
assert prompt_segments == [{"segment_id": 0, "original_text": "The gestures are nearby."}]
|
||||
assert "speaker" not in prompt_segments[0]
|
||||
assert "start" not in prompt_segments[0]
|
||||
assert "end" not in prompt_segments[0]
|
||||
|
||||
Reference in New Issue
Block a user