milwright commited on
Commit
1505067
Β·
1 Parent(s): de88fe1

Fix difficulty progression and batch processing issues

Browse files

- Fix inconsistent pass rate calculation that made Level 11 easier than Level 10
- Show pass requirements at all levels for better user feedback
- Add timeout handling to batch processing to prevent abort errors
- Improve error handling with specific abort error messaging

Files changed (3) hide show
  1. src/aiService.js +19 -0
  2. src/app.js +3 -9
  3. src/clozeGameEngine.js +6 -6
src/aiService.js CHANGED
@@ -298,6 +298,10 @@ Passage: "${passage}"`
298
  }
299
 
300
  try {
 
 
 
 
301
  const response = await fetch(this.apiUrl, {
302
  method: 'POST',
303
  headers: {
@@ -306,6 +310,7 @@ Passage: "${passage}"`
306
  'HTTP-Referer': window.location.origin,
307
  'X-Title': 'Cloze Reader'
308
  },
 
309
  body: JSON.stringify({
310
  model: this.model,
311
  messages: [{
@@ -349,6 +354,9 @@ Return as JSON: {"passage1": {...}, "passage2": {...}}`
349
  })
350
  });
351
 
 
 
 
352
  if (!response.ok) {
353
  throw new Error(`API request failed: ${response.status}`);
354
  }
@@ -502,6 +510,17 @@ Return as JSON: {"passage1": {...}, "passage2": {...}}`
502
  }
503
  }
504
  } catch (error) {
 
 
 
 
 
 
 
 
 
 
 
505
  console.error('Error processing passages:', error);
506
  throw error;
507
  }
 
298
  }
299
 
300
  try {
301
+ // Add timeout controller to prevent aborted operations
302
+ const controller = new AbortController();
303
+ const timeoutId = setTimeout(() => controller.abort(), 15000); // 15 second timeout
304
+
305
  const response = await fetch(this.apiUrl, {
306
  method: 'POST',
307
  headers: {
 
310
  'HTTP-Referer': window.location.origin,
311
  'X-Title': 'Cloze Reader'
312
  },
313
+ signal: controller.signal,
314
  body: JSON.stringify({
315
  model: this.model,
316
  messages: [{
 
354
  })
355
  });
356
 
357
+ // Clear timeout on successful response
358
+ clearTimeout(timeoutId);
359
+
360
  if (!response.ok) {
361
  throw new Error(`API request failed: ${response.status}`);
362
  }
 
510
  }
511
  }
512
  } catch (error) {
513
+ // Clear timeout in error case too
514
+ if (typeof timeoutId !== 'undefined') {
515
+ clearTimeout(timeoutId);
516
+ }
517
+
518
+ // Handle specific abort error
519
+ if (error.name === 'AbortError') {
520
+ console.error('Batch processing timed out after 15 seconds');
521
+ throw new Error('Request timed out - falling back to sequential processing');
522
+ }
523
+
524
  console.error('Error processing passages:', error);
525
  throw error;
526
  }
src/app.js CHANGED
@@ -157,10 +157,8 @@ class App {
157
  displayResults(results) {
158
  let message = `Score: ${results.correct}/${results.total} (${results.percentage}%)`;
159
 
160
- // Only show "Required" information at Level 3 and above
161
- if (this.game.currentLevel >= 3) {
162
- message += ` - Required: ${results.requiredCorrect}/${results.total}`;
163
- }
164
 
165
  if (results.passed) {
166
  // Check if this completes the requirements for level advancement
@@ -172,11 +170,7 @@ class App {
172
  }
173
  this.elements.result.className = 'mt-4 text-center font-semibold text-green-600';
174
  } else {
175
- if (this.game.currentLevel >= 3) {
176
- message += ` - Need ${results.requiredCorrect} correct to advance. Keep practicing! πŸ’ͺ`;
177
- } else {
178
- message += ` - Keep practicing! πŸ’ͺ`;
179
- }
180
  this.elements.result.className = 'mt-4 text-center font-semibold text-red-600';
181
  }
182
 
 
157
  displayResults(results) {
158
  let message = `Score: ${results.correct}/${results.total} (${results.percentage}%)`;
159
 
160
+ // Show "Required" information at all levels for consistency
161
+ message += ` - Required: ${results.requiredCorrect}/${results.total}`;
 
 
162
 
163
  if (results.passed) {
164
  // Check if this completes the requirements for level advancement
 
170
  }
171
  this.elements.result.className = 'mt-4 text-center font-semibold text-green-600';
172
  } else {
173
+ message += ` - Need ${results.requiredCorrect} correct to advance. Keep practicing! πŸ’ͺ`;
 
 
 
 
174
  this.elements.result.className = 'mt-4 text-center font-semibold text-red-600';
175
  }
176
 
src/clozeGameEngine.js CHANGED
@@ -805,14 +805,14 @@ class ClozeGame {
805
  // Calculate required correct answers based on total blanks
806
  calculateRequiredCorrect(totalBlanks) {
807
  if (totalBlanks === 1) {
808
- // Level 1: Must get the single word correct
809
  return 1;
810
- } else if (totalBlanks % 2 === 1) {
811
- // Odd number of blanks (3, 5, etc.): require all but one
812
- return totalBlanks - 1;
813
  } else {
814
- // Even number of blanks: require all correct
815
- return totalBlanks;
816
  }
817
  }
818
 
 
805
  // Calculate required correct answers based on total blanks
806
  calculateRequiredCorrect(totalBlanks) {
807
  if (totalBlanks === 1) {
808
+ // 1 blank: Must get it correct
809
  return 1;
810
+ } else if (totalBlanks === 2) {
811
+ // 2 blanks: Need both correct (keeps current Level 6-10 difficulty)
812
+ return 2;
813
  } else {
814
+ // 3+ blanks: Need all but one (fixes Level 11+ to be harder than Level 10)
815
+ return totalBlanks - 1;
816
  }
817
  }
818