Jayant-Kernel commited on
fix: exponential backoff on rate limit (10 retries, 30s*attempt)
Browse files
scripts/generate_distractors.py
CHANGED
|
@@ -98,21 +98,22 @@ def main() -> None:
|
|
| 98 |
continue
|
| 99 |
|
| 100 |
distractors = None
|
| 101 |
-
for attempt in range(
|
| 102 |
try:
|
| 103 |
distractors = _generate_distractors(client, row["question"], row["ground_truth"])
|
| 104 |
break
|
| 105 |
except openai.AuthenticationError as e:
|
| 106 |
raise RuntimeError(f"Unrecoverable API error (check OPENAI_API_KEY): {e}") from e
|
| 107 |
except openai.RateLimitError as e:
|
| 108 |
-
wait =
|
| 109 |
-
print(f" Rate limit on {row['id']} (attempt {attempt + 1}/
|
| 110 |
time.sleep(wait)
|
| 111 |
except Exception as e:
|
| 112 |
print(f" ERROR on {row['id']}: {e} — skipping")
|
| 113 |
break
|
| 114 |
|
| 115 |
if distractors is None:
|
|
|
|
| 116 |
continue
|
| 117 |
|
| 118 |
output_rows.append({
|
|
|
|
| 98 |
continue
|
| 99 |
|
| 100 |
distractors = None
|
| 101 |
+
for attempt in range(10):
|
| 102 |
try:
|
| 103 |
distractors = _generate_distractors(client, row["question"], row["ground_truth"])
|
| 104 |
break
|
| 105 |
except openai.AuthenticationError as e:
|
| 106 |
raise RuntimeError(f"Unrecoverable API error (check OPENAI_API_KEY): {e}") from e
|
| 107 |
except openai.RateLimitError as e:
|
| 108 |
+
wait = 30 * (attempt + 1)
|
| 109 |
+
print(f" Rate limit on {row['id']} (attempt {attempt + 1}/10), waiting {wait}s...")
|
| 110 |
time.sleep(wait)
|
| 111 |
except Exception as e:
|
| 112 |
print(f" ERROR on {row['id']}: {e} — skipping")
|
| 113 |
break
|
| 114 |
|
| 115 |
if distractors is None:
|
| 116 |
+
print(f" GAVE UP on {row['id']} after 10 attempts — skipping")
|
| 117 |
continue
|
| 118 |
|
| 119 |
output_rows.append({
|