Spaces:
Running
Running
fix: make AI API calls sequential with delay to prevent rate limiting
Browse files- Changed from parallel Promise.all to sequential calls
- Added 1 second delay between word selection and contextualization
- This prevents immediate rate limiting when both calls hit OpenRouter simultaneously
- Applied to both initial passage load and second passage load
- src/clozeGameEngine.js +14 -10
src/clozeGameEngine.js
CHANGED
@@ -55,11 +55,13 @@ class ClozeGame {
|
|
55 |
this.currentBook = book1;
|
56 |
this.originalText = this.passages[0];
|
57 |
|
58 |
-
// Run AI calls
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
63 |
|
64 |
return {
|
65 |
title: this.currentBook.title,
|
@@ -480,11 +482,13 @@ class ClozeGame {
|
|
480 |
// Clear last results
|
481 |
this.lastResults = null;
|
482 |
|
483 |
-
// Generate new cloze text and contextualization for second passage
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
|
|
|
|
488 |
|
489 |
return {
|
490 |
title: this.currentBook.title,
|
|
|
55 |
this.currentBook = book1;
|
56 |
this.originalText = this.passages[0];
|
57 |
|
58 |
+
// Run AI calls sequentially to avoid rate limiting
|
59 |
+
await this.createClozeText();
|
60 |
+
|
61 |
+
// Add small delay between API calls to avoid rate limiting
|
62 |
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
63 |
+
|
64 |
+
await this.generateContextualization();
|
65 |
|
66 |
return {
|
67 |
title: this.currentBook.title,
|
|
|
482 |
// Clear last results
|
483 |
this.lastResults = null;
|
484 |
|
485 |
+
// Generate new cloze text and contextualization for second passage sequentially
|
486 |
+
await this.createClozeText();
|
487 |
+
|
488 |
+
// Add small delay between API calls to avoid rate limiting
|
489 |
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
490 |
+
|
491 |
+
await this.generateContextualization();
|
492 |
|
493 |
return {
|
494 |
title: this.currentBook.title,
|