|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Script to combine per-instance details from info_for_leaderboard.json |
| 4 | +into the leaderboards.json file for all model entries. |
| 5 | +""" |
| 6 | + |
| 7 | +import json |
| 8 | +import sys |
| 9 | +from pathlib import Path |
| 10 | + |
| 11 | + |
| 12 | +# Mapping from info_for_leaderboard.json keys to leaderboard entry names |
| 13 | +MODEL_MAPPING = { |
| 14 | + 'gpt-5': 'GPT-5 (2025-08-07) (medium reasoning)', |
| 15 | + 'gpt-5-mini': 'GPT-5 mini (2025-08-07) (medium reasoning)', |
| 16 | + 'sonnet-4': 'Claude 4 Sonnet (20250514)', |
| 17 | + 'sonnet-4-5': 'Claude 4.5 Sonnet (20250929)', |
| 18 | +} |
| 19 | + |
| 20 | + |
| 21 | +def main(): |
| 22 | + # Define file paths |
| 23 | + script_dir = Path(__file__).parent |
| 24 | + info_file = script_dir / "info_for_leaderboard.json" |
| 25 | + leaderboards_file = script_dir / "leaderboards.json" |
| 26 | + backup_file = script_dir / "leaderboards.json.backup" |
| 27 | + |
| 28 | + # Check files exist |
| 29 | + if not info_file.exists(): |
| 30 | + print(f"Error: {info_file} not found") |
| 31 | + return 1 |
| 32 | + |
| 33 | + if not leaderboards_file.exists(): |
| 34 | + print(f"Error: {leaderboards_file} not found") |
| 35 | + return 1 |
| 36 | + |
| 37 | + # Load the info file |
| 38 | + print(f"Loading {info_file}...") |
| 39 | + with open(info_file, 'r') as f: |
| 40 | + info_data = json.load(f) |
| 41 | + |
| 42 | + print(f"Found {len(info_data)} model entries in info file") |
| 43 | + print(f"Available models: {list(info_data.keys())}") |
| 44 | + |
| 45 | + # Load leaderboards |
| 46 | + print(f"\nLoading {leaderboards_file}...") |
| 47 | + with open(leaderboards_file, 'r') as f: |
| 48 | + leaderboards_data = json.load(f) |
| 49 | + |
| 50 | + # Find bash-only leaderboard |
| 51 | + bash_only = None |
| 52 | + bash_only_idx = None |
| 53 | + for idx, lb in enumerate(leaderboards_data['leaderboards']): |
| 54 | + if lb.get('name') == 'bash-only': |
| 55 | + bash_only = lb |
| 56 | + bash_only_idx = idx |
| 57 | + break |
| 58 | + |
| 59 | + if bash_only is None: |
| 60 | + print("Error: 'bash-only' leaderboard not found") |
| 61 | + return 1 |
| 62 | + |
| 63 | + print(f"Found 'bash-only' leaderboard with {len(bash_only['results'])} entries") |
| 64 | + |
| 65 | + # Track which models will be updated |
| 66 | + models_to_update = [] |
| 67 | + for info_key, leaderboard_name in MODEL_MAPPING.items(): |
| 68 | + if info_key not in info_data: |
| 69 | + print(f"\nWarning: '{info_key}' not found in info file, skipping...") |
| 70 | + continue |
| 71 | + |
| 72 | + # Find the entry in leaderboard |
| 73 | + entry_idx = None |
| 74 | + for idx, result in enumerate(bash_only['results']): |
| 75 | + if result.get('name') == leaderboard_name: |
| 76 | + entry_idx = idx |
| 77 | + break |
| 78 | + |
| 79 | + if entry_idx is None: |
| 80 | + print(f"\nWarning: '{leaderboard_name}' not found in leaderboard, skipping...") |
| 81 | + continue |
| 82 | + |
| 83 | + # Check if already has per_instance_details |
| 84 | + has_details = 'per_instance_details' in bash_only['results'][entry_idx] |
| 85 | + num_instances = len(info_data[info_key]) |
| 86 | + |
| 87 | + models_to_update.append({ |
| 88 | + 'info_key': info_key, |
| 89 | + 'leaderboard_name': leaderboard_name, |
| 90 | + 'entry_idx': entry_idx, |
| 91 | + 'num_instances': num_instances, |
| 92 | + 'has_details': has_details, |
| 93 | + }) |
| 94 | + |
| 95 | + status = "(will overwrite)" if has_details else "(new)" |
| 96 | + print(f"\n - {leaderboard_name} {status}") |
| 97 | + print(f" {num_instances} instances from '{info_key}'") |
| 98 | + |
| 99 | + if not models_to_update: |
| 100 | + print("\nError: No models to update") |
| 101 | + return 1 |
| 102 | + |
| 103 | + # Ask for confirmation |
| 104 | + print(f"\n{'='*60}") |
| 105 | + print(f"Will update {len(models_to_update)} model(s)") |
| 106 | + |
| 107 | + overwrite_count = sum(1 for m in models_to_update if m['has_details']) |
| 108 | + if overwrite_count > 0: |
| 109 | + print(f"Warning: {overwrite_count} model(s) already have per_instance_details") |
| 110 | + |
| 111 | + response = input("\nContinue? (yes/no): ").strip().lower() |
| 112 | + if response != 'yes': |
| 113 | + print("Aborted.") |
| 114 | + return 0 |
| 115 | + |
| 116 | + # Create backup |
| 117 | + print(f"\nCreating backup at {backup_file}...") |
| 118 | + with open(backup_file, 'w') as f: |
| 119 | + json.dump(leaderboards_data, f, indent=2) |
| 120 | + |
| 121 | + # Update all models |
| 122 | + print("\nUpdating models...") |
| 123 | + for model in models_to_update: |
| 124 | + info_key = model['info_key'] |
| 125 | + entry_idx = model['entry_idx'] |
| 126 | + leaderboard_name = model['leaderboard_name'] |
| 127 | + |
| 128 | + per_instance_details = info_data[info_key] |
| 129 | + leaderboards_data['leaderboards'][bash_only_idx]['results'][entry_idx]['per_instance_details'] = per_instance_details |
| 130 | + |
| 131 | + print(f" ✓ {leaderboard_name}: {len(per_instance_details)} instances") |
| 132 | + |
| 133 | + # Write updated data |
| 134 | + print(f"\nWriting updated data to {leaderboards_file}...") |
| 135 | + with open(leaderboards_file, 'w') as f: |
| 136 | + json.dump(leaderboards_data, f, indent=2) |
| 137 | + |
| 138 | + print("\n" + "="*60) |
| 139 | + print("✓ Success! All models updated") |
| 140 | + print(f" - Backup saved to: {backup_file}") |
| 141 | + print(f" - Models updated: {len(models_to_update)}") |
| 142 | + |
| 143 | + # Show sample of added data for first model |
| 144 | + if models_to_update: |
| 145 | + first_model = models_to_update[0] |
| 146 | + print(f"\nSample instances from {first_model['leaderboard_name']}:") |
| 147 | + sample_data = info_data[first_model['info_key']] |
| 148 | + for i, (key, value) in enumerate(list(sample_data.items())[:3]): |
| 149 | + print(f" - {key}: resolved={value.get('resolved')}, cost={value.get('cost')}") |
| 150 | + |
| 151 | + return 0 |
| 152 | + |
| 153 | + |
| 154 | +if __name__ == '__main__': |
| 155 | + sys.exit(main()) |
0 commit comments