text
stringlengths
0
1.47k
"abstract rigs are legitimately empty; anything with mirrored limbs, "
"fins, wings or a head-to-tail chain is not.\n"
"The OUTPUT contract, PRIORITY order and INVARIANTS above are unchanged."
)
CORRECTION_SYSTEM_PROMPT = SYSTEM_PROMPT + "\n\n" + CORRECTION_PREAMBLE
# ─────────────────────────────────────────────────────────────────────────────
# Entry classification
# ─────────────────────────────────────────────────────────────────────────────
def _hips(entry):
if not isinstance(entry, dict):
return None, None
r, l = entry.get("r_hip", {}), entry.get("l_hip", {})
if not isinstance(r, dict) or not isinstance(l, dict):
return None, None
return r, l
def is_non_empty_entry(entry):
# type: (object) -> bool
"""True iff ``entry`` has a real (non-blank) r_hip/l_hip pair."""
r, l = _hips(entry)
return bool(r and l and r.get("raw") and l.get("raw"))
def is_empty_entry(entry):
# type: (object) -> bool
"""True for the canonical 'source==empty, both hips blank' sentinel
(and for malformed entries, which are treated as empty)."""
if not isinstance(entry, dict):
return True
if entry.get("source") != "empty":
return False
r, l = _hips(entry)
if r is None:
return True
return not r.get("raw") and not l.get("raw")
# ─────────────────────────────────────────────────────────────────────────────
# Driver
# ─────────────────────────────────────────────────────────────────────────────
def correct_all(raw_path, clean_path, face_path, client,
system_prompt=CORRECTION_SYSTEM_PROMPT,
failed_list_path=None, max_tokens=2048, max_retries=MAX_RETRIES,
timeout_seconds=60, still_empty_path=None, only_if_currently_empty=True):
# type: (...) -> Dict[str, Dict]
"""Re-run LLM face-joint selection and write results back IN-PLACE to
``face_path``.
Targets every ``source == "empty"`` rig in ``face_path``, or only the
ids in ``failed_list_path`` when given. Rigs where the LLM fails or
still returns an empty entry are left untouched. The LLM runs with the
correction system prompt and WITHOUT the rule-based hint (the hint is
the very answer that already failed).
A missing ``failed_list_path`` is a hard error: a typo must not silently
escalate a targeted repair into a full sweep.
"""
with open(raw_path, "r") as f:
raw_data = json.load(f)
with open(clean_path, "r") as f:
clean_data = json.load(f)
with open(face_path, "r") as f:
face_data = json.load(f)
if failed_list_path:
if not os.path.exists(failed_list_path):
raise FileNotFoundError(
"--failed_list {!r} does not exist. Drop the flag to re-attempt "
"every source=='empty' rig in {}.".format(failed_list_path, face_path))
target_ids = read_id_list(failed_list_path)
scope_desc = "{} rigs from {}".format(len(target_ids), failed_list_path)
else:
target_ids = sorted(k for k, v in face_data.items() if is_empty_entry(v))
scope_desc = "{} empty-source rigs in {}".format(len(target_ids), face_path)
backup = face_path + ".bak"
if not os.path.exists(backup):
shutil.copy2(face_path, backup)
logger.info("Backed up {} -> {}".format(face_path, backup))
if still_empty_path is None:
still_empty_path = os.path.join(
os.path.dirname(face_path) or ".", "still_empty_face_joints.txt")
logger.info("Re-attempting {} (in-place update of {})".format(scope_desc, face_path))
updated = skipped_not_empty = missing = kept_existing = 0
still_empty = [] # type: List[str]
pbar = tqdm(target_ids, desc="Correcting", unit="rig", dynamic_ncols=True)
for rig_id in pbar:
pbar.set_postfix_str(rig_id, refresh=False)
if rig_id not in raw_data or rig_id not in clean_data:
missing += 1