Place ref context after anchor in H3 prompts
This commit is contained in:
+22
-6
@@ -4375,6 +4375,27 @@ def _reference_context_for_text(text, ref_slots):
|
||||
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):
|
||||
lines = []
|
||||
seen = set()
|
||||
@@ -6410,12 +6431,7 @@ class H3LongVideos:
|
||||
for block in gens:
|
||||
context = _reference_context_for_text(block, ref_slots)
|
||||
if context:
|
||||
block = re.sub(
|
||||
r"^(\[Generation \d+\]\s*)",
|
||||
lambda m: m.group(1) + context + " ",
|
||||
block,
|
||||
count=1,
|
||||
)
|
||||
block = _inject_reference_context(block, context)
|
||||
enriched_gens.append(block)
|
||||
gens = enriched_gens
|
||||
|
||||
|
||||
Reference in New Issue
Block a user