From a53651496c17599be50c49efb79ea1e1cba430ae Mon Sep 17 00:00:00 2001 From: Chris Dumas Date: Thu, 15 Oct 2026 09:19:13 +0000 Subject: [PATCH] Repeat shared context in every chunk --- README.md | 7 ++++--- prompt_builder.py | 12 +++++++----- tests/test_sequence_prompt_builder.py | 6 +++++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 58ca21b..96db53b 100644 --- a/README.md +++ b/README.md @@ -29,16 +29,17 @@ is unavailable. Example output: ```text -Preserve the same character and environment. - [0-4s] +Preserve the same character and environment. 0-2s: The character walks forward and looks toward the light. 2-4s: The character stops and looks toward the light. +overall_soundscape: Quiet room tone and footsteps. +non_diegetic_music: Low cinematic pulse. [4-8s] +Preserve the same character and environment. 0-2s: Continue seamlessly as the character raises one hand. 2-4s: The character looks toward the camera. - overall_soundscape: Quiet room tone and footsteps. non_diegetic_music: Low cinematic pulse. ``` diff --git a/prompt_builder.py b/prompt_builder.py index 2d96721..fdd561c 100644 --- a/prompt_builder.py +++ b/prompt_builder.py @@ -106,22 +106,24 @@ def format_sequence_prompt( ``start-end s:`` lines rather than creating additional Timeline sections. """ - sections: list[str] = [] directive = str(shared_directive or "").strip() - if directive: - sections.append(directive) + sound = str(soundscape or "").strip() or "N/A" + music_text = str(music or "").strip() or "N/A" + sections: list[str] = [] cursor = 0.0 for clip in sequence["clips"]: duration = float(clip["duration"]) chunk_lines = [f"[{cursor:g}-{cursor + duration:g}s]"] + if directive: + chunk_lines.append(directive) for slot in clip["slots"]: start = float(slot["start"]) end = float(slot["end"]) chunk_lines.append(f"{start:g}-{end:g}s: {slot['text']}") + chunk_lines.append(f"overall_soundscape: {sound}") + chunk_lines.append(f"non_diegetic_music: {music_text}") sections.append("\n".join(chunk_lines)) cursor += duration - sections.append(f"overall_soundscape: {str(soundscape or '').strip() or 'N/A'}") - sections.append(f"non_diegetic_music: {str(music or '').strip() or 'N/A'}") return "\n\n".join(sections).strip() diff --git a/tests/test_sequence_prompt_builder.py b/tests/test_sequence_prompt_builder.py index 0f6f87d..cedbe87 100644 --- a/tests/test_sequence_prompt_builder.py +++ b/tests/test_sequence_prompt_builder.py @@ -33,6 +33,9 @@ def test_builder_emits_one_absolute_timeline_prompt_from_clip_local_slots(): assert "[5-9s]" not in result assert "overall_soundscape: Quiet street ambience." in result assert "non_diegetic_music: Low cinematic pulse." in result + assert result.count("Preserve the same character and environment.") == 2 + assert result.count("overall_soundscape: Quiet street ambience.") == 2 + assert result.count("non_diegetic_music: Low cinematic pulse.") == 2 def test_normalizer_orders_slots_fills_missing_clips_and_shares_duration(): @@ -63,4 +66,5 @@ def test_node_schema_has_single_string_output_and_serialized_editor_state(): assert DumasH3SequencePromptBuilder.RETURN_TYPES == ("STRING",) assert schema["timeline_json"][1]["multiline"] is True result = DumasH3SequencePromptBuilder().build(1, 4, "Directive", json.dumps(default_sequence(1, 4)), "N/A", "N/A") - assert result[0].startswith("Directive\n\noverall_soundscape:") + assert result[0].startswith("[0-4s]\nDirective") + assert result[0].count("overall_soundscape:") == 1