Replaced the deterministic GrammarOnlyValidator with an LLM-backed grammar_only_guard
This commit is contained in:
@@ -603,6 +603,16 @@ def test_process_transcript_result_runs_grammar_module_with_full_validator_chain
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"validations": [
|
||||
{
|
||||
"correction_index": 0,
|
||||
"approved": True,
|
||||
"confidence": 0.98,
|
||||
"reason": "Conservative grammar cleanup.",
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"validations": [
|
||||
{
|
||||
@@ -627,6 +637,7 @@ def test_process_transcript_result_runs_grammar_module_with_full_validator_chain
|
||||
assert result.transcript[0].text == "Hello world."
|
||||
assert [call["stage_name"] for call in client.calls] == [
|
||||
"grammar:proposal",
|
||||
"grammar:grammar_only_guard",
|
||||
"grammar:meaning_reversal_review",
|
||||
]
|
||||
assert [validator["name"] for validator in result.report.modules[0].to_dict()["validators"]] == [
|
||||
@@ -678,6 +689,16 @@ def test_process_transcript_result_grammar_module_applies_indefinite_article_cle
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"validations": [
|
||||
{
|
||||
"correction_index": 0,
|
||||
"approved": True,
|
||||
"confidence": 0.97,
|
||||
"reason": "Allowed article cleanup.",
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"validations": [
|
||||
{
|
||||
@@ -702,6 +723,7 @@ def test_process_transcript_result_grammar_module_applies_indefinite_article_cle
|
||||
assert result.transcript[0].text == "Give me an intelligence saving throw."
|
||||
assert [call["stage_name"] for call in client.calls] == [
|
||||
"grammar:proposal",
|
||||
"grammar:grammar_only_guard",
|
||||
"grammar:meaning_reversal_review",
|
||||
]
|
||||
|
||||
@@ -798,6 +820,16 @@ def test_process_transcript_result_grammar_module_still_rejects_homophone_style_
|
||||
"confidence": 0.95,
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"validations": [
|
||||
{
|
||||
"correction_index": 0,
|
||||
"approved": False,
|
||||
"confidence": 0.99,
|
||||
"reason": "Free-standing homophone rewrite rather than conservative grammar cleanup.",
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
)
|
||||
@@ -811,9 +843,94 @@ def test_process_transcript_result_grammar_module_still_rejects_homophone_style_
|
||||
)
|
||||
|
||||
assert result.transcript[0].text == "ChatGPT still can't really do that with a dam."
|
||||
assert [call["stage_name"] for call in client.calls] == ["grammar:proposal"]
|
||||
assert [call["stage_name"] for call in client.calls] == [
|
||||
"grammar:proposal",
|
||||
"grammar:grammar_only_guard",
|
||||
]
|
||||
assert result.report.skipped_corrections[0].source == "validator:grammar_only_guard"
|
||||
assert result.report.skipped_corrections[0].reason == "correction is not limited to punctuation, capitalization, and spacing"
|
||||
assert "grammar cleanup" in result.report.skipped_corrections[0].reason
|
||||
|
||||
|
||||
def test_process_transcript_result_grammar_module_allows_embedded_homophone_fix_with_grammar_cleanup(tmp_path):
|
||||
transcript = parse_source_transcript_json(
|
||||
"""
|
||||
[
|
||||
{"speaker": "Eric", "start": 0.0, "end": 1.0, "text": "question. if he dies does he stay there the way that yeah the way that it's written it's like so if it stops that he goes down but what if it doesn't"}
|
||||
]
|
||||
"""
|
||||
)
|
||||
base_config = AuditaConfig.from_sources(env={})
|
||||
config = AuditaConfig(
|
||||
api_key=base_config.api_key,
|
||||
llm_concurrency=base_config.llm_concurrency,
|
||||
module_keys=base_config.module_keys,
|
||||
model=base_config.model,
|
||||
base_url=base_config.base_url,
|
||||
max_retries=base_config.max_retries,
|
||||
max_section_tokens=base_config.max_section_tokens,
|
||||
glossary_confidence_threshold=base_config.glossary_confidence_threshold,
|
||||
grammar_confidence_threshold=base_config.grammar_confidence_threshold,
|
||||
homophones_confidence_threshold=base_config.homophones_confidence_threshold,
|
||||
spoken_word_confidence_threshold=base_config.spoken_word_confidence_threshold,
|
||||
normalize_max_segment_gap=base_config.normalize_max_segment_gap,
|
||||
normalize_ellipsis_gap=base_config.normalize_ellipsis_gap,
|
||||
normalize_max_segment_duration=base_config.normalize_max_segment_duration,
|
||||
normalize_max_segment_tokens=base_config.normalize_max_segment_tokens,
|
||||
work_dir=tmp_path / "work",
|
||||
work_dir_retention="always",
|
||||
)
|
||||
client = FakeStructuredLLMClient(
|
||||
[
|
||||
{
|
||||
"corrections": [
|
||||
{
|
||||
"id": 1,
|
||||
"original_text": "question. if he dies does he stay there the way that yeah the way that it's written it's like so if it stops that he goes down but what if it doesn't",
|
||||
"corrected_text": "question: If he dies, does he stay there? The way that, yeah, the way that it's written, it's like, so if it stops, then he goes down; but what if it doesn't?",
|
||||
"confidence": 0.95,
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"validations": [
|
||||
{
|
||||
"correction_index": 0,
|
||||
"approved": True,
|
||||
"confidence": 0.95,
|
||||
"reason": "Primarily a grammatical revision with an embedded likely mistranscription recovery.",
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"validations": [
|
||||
{
|
||||
"correction_index": 0,
|
||||
"approved": True,
|
||||
"confidence": 0.99,
|
||||
"reason": "Does not reverse the segment meaning.",
|
||||
}
|
||||
]
|
||||
},
|
||||
]
|
||||
)
|
||||
|
||||
result = process_transcript_result(
|
||||
transcript,
|
||||
_glossary(),
|
||||
config,
|
||||
module_keys=["grammar"],
|
||||
llm_client=client,
|
||||
)
|
||||
|
||||
assert result.transcript[0].text == (
|
||||
"question: If he dies, does he stay there? The way that, yeah, the way that it's written, "
|
||||
"it's like, so if it stops, then he goes down; but what if it doesn't?"
|
||||
)
|
||||
assert [call["stage_name"] for call in client.calls] == [
|
||||
"grammar:proposal",
|
||||
"grammar:grammar_only_guard",
|
||||
"grammar:meaning_reversal_review",
|
||||
]
|
||||
|
||||
|
||||
def test_process_transcript_result_rejects_spoken_word_whole_segment_deletion_before_llm_validators(tmp_path):
|
||||
|
||||
Reference in New Issue
Block a user