Strengthen H3 reference prompt placement
This commit is contained in:
+7
-11
@@ -4416,19 +4416,15 @@ def _inject_reference_context(block, context):
|
|||||||
text = str(block or "").strip()
|
text = str(block or "").strip()
|
||||||
if not text:
|
if not text:
|
||||||
return context
|
return context
|
||||||
match = re.match(r"^(\[Generation \d+\]\s*)(.*)$", text, re.S)
|
match = re.match(r"^(\[Generation \d+\]\s*)", text)
|
||||||
if not match:
|
if not match:
|
||||||
return f"{context} {text}".strip()
|
return f"{context} {text}".strip()
|
||||||
prefix, body = match.groups()
|
return re.sub(
|
||||||
body = body.strip()
|
r"^(\[Generation \d+\]\s*)",
|
||||||
split_at = body.find(". ")
|
lambda m: m.group(1) + context + " ",
|
||||||
if split_at == -1:
|
text,
|
||||||
return f"{prefix}{body} {context}".strip()
|
count=1,
|
||||||
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):
|
||||||
|
|||||||
@@ -536,7 +536,7 @@ 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):
|
def test_reference_context_injects_immediately_after_generation_label(self):
|
||||||
block = (
|
block = (
|
||||||
"[Generation 1] Classic sitcom lighting and staging. "
|
"[Generation 1] Classic sitcom lighting and staging. "
|
||||||
"Duke walks into the room."
|
"Duke walks into the room."
|
||||||
@@ -547,8 +547,8 @@ class DumasH3LongVideosHelperTests(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
result,
|
result,
|
||||||
"[Generation 1] Classic sitcom lighting and staging. "
|
"[Generation 1] Character facts for Duke: female, 25 years old. "
|
||||||
"Character facts for Duke: female, 25 years old. "
|
"Classic sitcom lighting and staging. "
|
||||||
"Duke walks into the room.",
|
"Duke walks into the room.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user