Added a configuration flag to set the target number of sections, and updated default min and max section token limits

This commit is contained in:
2026-04-29 20:10:00 -05:00
parent f841f7eb71
commit 4c899122d9
9 changed files with 312 additions and 7 deletions

View File

@@ -1,4 +1,7 @@
import pytest
from audita.core.chunking import TokenEstimatorProtocol, chunk_transcript
from audita.core.errors import AuditaValidationError
from audita.core.schemas import parse_transcript_json
@@ -100,6 +103,93 @@ def test_chunk_transcript_reduces_section_count_when_target_sections_fall_below_
assert sections[0].token_count >= 8
def test_chunk_transcript_exact_target_sections_returns_exact_count_when_feasible():
transcript = parse_transcript_json(
"""
[
{"id": 1, "speaker": "A", "start": 0.0, "end": 1.0, "text": "one"},
{"id": 2, "speaker": "A", "start": 1.0, "end": 2.0, "text": "two"},
{"id": 3, "speaker": "A", "start": 2.0, "end": 3.0, "text": "three"},
{"id": 4, "speaker": "A", "start": 3.0, "end": 4.0, "text": "four"}
]
"""
)
sections = chunk_transcript(
transcript,
max_section_tokens=8,
min_section_tokens=4,
exact_target_section_count=2,
estimator=FakeEstimator(),
)
assert len(sections) == 2
assert [segment.segment.id for segment in sections[0].segments] == [1, 2]
assert [segment.segment.id for segment in sections[1].segments] == [3, 4]
def test_chunk_transcript_exact_target_sections_errors_when_target_exceeds_segment_count():
transcript = parse_transcript_json(
"""
[
{"id": 1, "speaker": "A", "start": 0.0, "end": 1.0, "text": "one"},
{"id": 2, "speaker": "A", "start": 1.0, "end": 2.0, "text": "two"}
]
"""
)
with pytest.raises(AuditaValidationError, match="Target section count exceeds the number of transcript segments"):
chunk_transcript(
transcript,
max_section_tokens=8,
min_section_tokens=4,
exact_target_section_count=3,
estimator=FakeEstimator(),
)
def test_chunk_transcript_exact_target_sections_errors_when_section_would_exceed_max():
transcript = parse_transcript_json(
"""
[
{"id": 1, "speaker": "A", "start": 0.0, "end": 1.0, "text": "one"},
{"id": 2, "speaker": "A", "start": 1.0, "end": 2.0, "text": "two"},
{"id": 3, "speaker": "A", "start": 2.0, "end": 3.0, "text": "three"}
]
"""
)
with pytest.raises(AuditaValidationError, match="AUDITA_TARGET_SECTIONS cannot produce contiguous transcript sections"):
chunk_transcript(
transcript,
max_section_tokens=8,
min_section_tokens=4,
exact_target_section_count=1,
estimator=FakeEstimator(),
)
def test_chunk_transcript_exact_target_sections_errors_when_section_would_fall_below_min():
transcript = parse_transcript_json(
"""
[
{"id": 1, "speaker": "A", "start": 0.0, "end": 1.0, "text": "one"},
{"id": 2, "speaker": "A", "start": 1.0, "end": 2.0, "text": "two"},
{"id": 3, "speaker": "A", "start": 2.0, "end": 3.0, "text": "three"}
]
"""
)
with pytest.raises(AuditaValidationError, match="AUDITA_TARGET_SECTIONS cannot produce contiguous transcript sections"):
chunk_transcript(
transcript,
max_section_tokens=12,
min_section_tokens=8,
exact_target_section_count=3,
estimator=FakeEstimator(),
)
def test_chunk_transcript_prompt_payload_includes_categories_when_present():
transcript = parse_transcript_json(
"""