"""Remote-only payer/scope clarification plus a reference-selected wider low reserve.""" from __future__ import annotations import copy import json from itertools import product from pathlib import Path from build_cliff_contingent import MODEL, SEEDS, render_prompt from run_evaluate import oracle, read_jsonl, write_jsonl DESTINATION = Path("data/cliff_dev_r3") OLD_SCOPE = "正常生活已有保障,额外能动用的现金是题目最后给的数额,家里不能临时追加,也没有借款渠道。" NEW_SCOPE = ( "出发前日常生活已有保障;访问期间通知列明的生活费须由我从这一个账户按期支付。" "可用资金只有当前B和题内指定真正到账的资助,家里不追加,无借款。") def clarify(profile): result = copy.deepcopy(profile) if OLD_SCOPE not in result["persona"]: raise ValueError("Original living-scope clause is absent") result["persona"] = result["persona"].replace(OLD_SCOPE, NEW_SCOPE, 1) return result def clarified_prompt(profile, buffer, conditional_excludes=False): text = render_prompt(profile, buffer, conditional_excludes=conditional_excludes) for action in profile["actions"]: cost = action.get("cost", 0) if cost: text = text.replace(f"动作{action['id']}当天支付{cost}元。", f"动作{action['id']}当天,你从这一个账户付给相应服务方{cost}元。", 1) for effect in action.get("cash_effects", []): if effect["amount"] > 0: text = text.replace(f"{effect['label']}{effect['amount']}元一早到账", f"{effect['label']}{effect['amount']}元一早汇入你的这一个账户") elif effect["amount"] < 0: text = text.replace(f"每次当天晚些时候支付{-effect['amount']}元生活费", f"每次当天晚些时候,你从这一个账户付给相应生活服务方{-effect['amount']}元生活费") return text def main(): source = Path("data/cliff_dev_r2") original = read_jsonl(source / "profiles.jsonl") profiles = [clarify(profile) for profile in original] old_design = json.loads((source / "design.json").read_text(encoding="utf-8")) old_selection = {row["profile_id"]: row for row in old_design["profile_specific_buffers"]} prefix_data = json.loads(Path("results/cliff_dev_r2/prefix_reserves.json").read_text(encoding="utf-8")) arrival_reserves = {row["profile_id"]: next(stage["minimum_initial_cash_through_milestone"] for stage in row["waiver_prefixes"] if stage["milestone"] == "arrival_H_completed") for row in prefix_data["profiles"]} old_requests = {(row["profile_id"], row["B"], row["seed"]): row for row in read_jsonl(source / "requests.jsonl")} requests, references, selections = [], [], [] for profile in profiles: result = oracle(profile) references.append({"profile_id": profile["id"], **result}) best, arrival = result["minimum_initial_cash"], arrival_reserves[profile["id"]] if best != old_selection[profile["id"]]["R_star"]: raise ValueError("Payer/scope text unexpectedly changed the formal oracle") far = (arrival + best) // 2 if far >= best - 500: raise ValueError("No genuinely wider reference-selected low-cash interval") buffers = [far, best - 500, best + 500] selections.append({**old_selection[profile["id"]], "buffers": buffers, "R_arrival_H_prefix": arrival, "B_far_rule": "floor((R_arrival_H + R_star)/2)", "B_far": far, "new_point_is_arrival_feasible_but_whole_visit_infeasible": arrival <= far < best}) for buffer, seed in product(buffers, SEEDS): matched = old_requests.get((profile["id"], buffer, seed)) requests.append({"id": f"cliff_dev_r3__{profile['id']}__B{buffer}__D__s{seed}", "profile_id": profile["id"], "B": buffer, "model": MODEL, "seed": seed, "condition": "contingent_disbursement_actor_clarified", "presentation": "D", "source_request_id": matched["id"] if matched else None, "buffer_origin": "matched_r2_cell" if matched else "new_reference_arrival_full_midpoint", "prompt": clarified_prompt(profile, buffer)}) write_jsonl(DESTINATION / "original_profiles.jsonl", original) write_jsonl(DESTINATION / "profiles.jsonl", profiles) write_jsonl(DESTINATION / "oracle.jsonl", references) write_jsonl(DESTINATION / "requests.jsonl", requests) design = {**old_design, "version": "cliff_dev_r3", "request_count": len(requests), "profile_specific_buffers": selections, "source": "same r2 dev_02/dev_03 graph and monetary/calendar facts, with payment-party and normal-life scope clarified", "prompt_changes_from_r2": "normal living guarantee explicitly predeparture; visit costs paid by student from the one account; credits paid into that account", "matched_r2_request_count": sum(row["source_request_id"] is not None for row in requests), "new_wide_low_request_count": sum(row["source_request_id"] is None for row in requests), "scientific_scope": "post-result clarification plus four wider physical-infeasibility cells, not a new cash regime or an isolated money effect"} (DESTINATION / "design.json").write_text(json.dumps(design, ensure_ascii=False, indent=2), encoding="utf-8") (DESTINATION / "change_note.txt").write_text( "All 12 r2 finals were qualitatively read: four below-reference plans still assured full feasibility. Their raw " "thinking revealed scope/actor readings: normal life guaranteed interpreted as visit living covered, or a finance " "notice's living payment interpreted as income. This diagnostic explicitly clarifies the existing account's debit " "and credit parties and restricts the normal-life guarantee to predeparture. It adds no fee/income, changes no " "80/20 award amount, condition, calendar, date-processing offset, hold, graph or sampler, and supplies no balance " "strategy or final-payment warning. Eight original R*-500/R*+500 cells are paired at unchanged two seeds. Four " "new cells use the fixed integer midpoint between remote minimum reserve through arrival H and full R*, " "selected without model outcomes at these balances. These are arrival-feasible but full-visit-infeasible states; " "old r2 high reserves and all original results remain. Whole financial explanation reliability is not inferred " "from plan-execution success.\n", encoding="utf-8") print(json.dumps(design, ensure_ascii=False), flush=True) if __name__ == "__main__": main()