Prioritize character refs over location refs

This commit is contained in:
2026-08-29 11:36:53 +00:00
parent faaeb374e0
commit e08281c12b
2 changed files with 38 additions and 5 deletions
+23 -5
View File
@@ -4486,10 +4486,20 @@ def _matched_reference_slots(text, ref_slots, normalized_refs=None):
matched = []
seen = set()
normalized_slots = normalized_refs if normalized_refs is not None else _normalized_ref_slots(ref_slots)
for slot_number, ref in (
_slot_refs_for_text(text, normalized_slots)
+ _named_refs_for_text(text, normalized_slots, kinds=("character", "location"))
):
for slot_number, ref in _slot_refs_for_text(text, normalized_slots):
if slot_number in seen:
continue
seen.add(slot_number)
matched.append((slot_number, ref))
# Character names should win before location names when a beat mentions both.
# That keeps the face conditioning in front of the scene conditioning instead
# of letting an early location slot dominate the named-ref list.
for slot_number, ref in _named_refs_for_text(text, normalized_slots, kinds=("character",)):
if slot_number in seen:
continue
seen.add(slot_number)
matched.append((slot_number, ref))
for slot_number, ref in _named_refs_for_text(text, normalized_slots, kinds=("location",)):
if slot_number in seen:
continue
seen.add(slot_number)
@@ -4624,7 +4634,15 @@ def resolve_prompt_refs(text, ref_list, include_named=True, normalized_refs=None
refs = list(tagged_refs)
seen = {id(ref) for ref in refs}
if include_named:
for _slot_number, ref in _named_refs_for_text(rewritten, normalized_refs, kinds=("character", "location")):
# Keep named character refs ahead of location refs so the identity image
# is the first named reference the model sees on untagged beats.
for _slot_number, ref in _named_refs_for_text(rewritten, normalized_refs, kinds=("character",)):
marker = id(ref)
if marker in seen:
continue
seen.add(marker)
refs.append(ref)
for _slot_number, ref in _named_refs_for_text(rewritten, normalized_refs, kinds=("location",)):
marker = id(ref)
if marker in seen:
continue