Place ref context after anchor in H3 prompts

This commit is contained in:
2026-08-27 08:08:53 +00:00
parent a660919425
commit f96a3344e7
2 changed files with 38 additions and 6 deletions
+22 -6
View File
@@ -4375,6 +4375,27 @@ def _reference_context_for_text(text, ref_slots):
return " ".join(parts).strip() return " ".join(parts).strip()
def _inject_reference_context(block, context):
if not context:
return block
text = str(block or "").strip()
if not text:
return context
match = re.match(r"^(\[Generation \d+\]\s*)(.*)$", text, re.S)
if not match:
return f"{context} {text}".strip()
prefix, body = match.groups()
body = body.strip()
split_at = body.find(". ")
if split_at == -1:
return f"{prefix}{body} {context}".strip()
anchor = body[: split_at + 1]
rest = body[split_at + 2 :].strip()
if not rest:
return f"{prefix}{anchor} {context}".strip()
return f"{prefix}{anchor} {context} {rest}".strip()
def _reference_character_memory(ref_slots): def _reference_character_memory(ref_slots):
lines = [] lines = []
seen = set() seen = set()
@@ -6410,12 +6431,7 @@ class H3LongVideos:
for block in gens: for block in gens:
context = _reference_context_for_text(block, ref_slots) context = _reference_context_for_text(block, ref_slots)
if context: if context:
block = re.sub( block = _inject_reference_context(block, context)
r"^(\[Generation \d+\]\s*)",
lambda m: m.group(1) + context + " ",
block,
count=1,
)
enriched_gens.append(block) enriched_gens.append(block)
gens = enriched_gens gens = enriched_gens
+16
View File
@@ -340,6 +340,22 @@ class DumasH3LongVideosHelperTests(unittest.TestCase):
self.assertIn("Persistent appearance for Mara: silver hair.", context) self.assertIn("Persistent appearance for Mara: silver hair.", context)
self.assertIn("Persistent wardrobe/style for Mara: red jacket.", context) self.assertIn("Persistent wardrobe/style for Mara: red jacket.", context)
def test_reference_context_injects_after_anchor_sentence(self):
block = (
"[Generation 1] Classic sitcom lighting and staging. "
"Duke walks into the room."
)
context = "Character facts for Duke: female, 25 years old."
result = self.module._inject_reference_context(block, context)
self.assertEqual(
result,
"[Generation 1] Classic sitcom lighting and staging. "
"Character facts for Duke: female, 25 years old. "
"Duke walks into the room.",
)
def test_reference_character_memory_uses_character_wardrobe_only(self): def test_reference_character_memory_uses_character_wardrobe_only(self):
refs = [ refs = [
{"kind": "character", "image": "img1", "name": "Mara", "wardrobe": "red jacket, black boots"}, {"kind": "character", "image": "img1", "name": "Mara", "wardrobe": "red jacket, black boots"},