Jayant-Kernel commited on
Commit
b7f42c1
·
unverified ·
1 Parent(s): 1c6af55

fix: sleep after error path, print progress every 10 iterations

Browse files
Files changed (1) hide show
  1. scripts/generate_distractors.py +9 -4
scripts/generate_distractors.py CHANGED
@@ -84,15 +84,20 @@ def main() -> None:
84
 
85
  output_rows: list[dict] = list(existing.values())
86
  new_count = 0
 
87
 
88
  for i, row in enumerate(level1_rows):
89
  if row["id"] in existing:
90
  continue
91
 
 
 
92
  try:
93
  distractors = _generate_distractors(client, row["question"], row["ground_truth"])
94
  except Exception as e:
95
  print(f" ERROR on {row['id']}: {e} — skipping")
 
 
96
  continue
97
 
98
  output_rows.append({
@@ -104,12 +109,12 @@ def main() -> None:
104
  })
105
  new_count += 1
106
 
107
- # Save every 10 new entries
108
- if new_count % 10 == 0:
109
  _save_rows(output_rows, LEVEL2_PATH)
110
- print(f" Progress: {new_count} new / {len(output_rows)} total saved")
111
 
112
- # Rate-limit sleep
113
  time.sleep(1)
114
 
115
  # Final save
 
84
 
85
  output_rows: list[dict] = list(existing.values())
86
  new_count = 0
87
+ iteration_count = 0
88
 
89
  for i, row in enumerate(level1_rows):
90
  if row["id"] in existing:
91
  continue
92
 
93
+ iteration_count += 1
94
+
95
  try:
96
  distractors = _generate_distractors(client, row["question"], row["ground_truth"])
97
  except Exception as e:
98
  print(f" ERROR on {row['id']}: {e} — skipping")
99
+ # Rate-limit sleep after failed API call
100
+ time.sleep(1)
101
  continue
102
 
103
  output_rows.append({
 
109
  })
110
  new_count += 1
111
 
112
+ # Save and print progress every 10 loop iterations
113
+ if iteration_count % 10 == 0:
114
  _save_rows(output_rows, LEVEL2_PATH)
115
+ print(f" Progress: {iteration_count} processed / {new_count} new / {len(output_rows)} total saved")
116
 
117
+ # Rate-limit sleep after successful API call
118
  time.sleep(1)
119
 
120
  # Final save