mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-11 17:26:32 +02:00
fix(ai): throttle now applies on ALL chunk iterations (incl. errors), delay bumped to 20s
This commit is contained in:
1 parent
bcbea69d0a
commit
163d80dfe2
1 file changed
+9
-12
@@ -56,24 +56,18 @@ export function BulkAiAnalyzer() {
|
||||
marge: r.totalMarge ? parseFloat(((r.totalMarge / (r.totalCa || 1)) * 100).toFixed(1)) : 0,
|
||||
}));
|
||||
|
||||
try {
|
||||
const res = await fetch("/api/ai/batch-analyze", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
rayon: chunk.rayon,
|
||||
products: payloadProducts
|
||||
})
|
||||
body: JSON.stringify({ rayon: chunk.rayon, products: payloadProducts })
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const errText = await res.text();
|
||||
console.error(`[BulkAiAnalyzer] Erreur HTTP ${res.status} sur le lot ${chunk.rayon}:`, errText);
|
||||
setProgress(prev => ({ ...prev, errors: prev.errors + 1 }));
|
||||
completed++;
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
} else {
|
||||
const data = await res.json();
|
||||
console.log(`[BulkAiAnalyzer] Response for ${chunk.rayon}:`, data);
|
||||
|
||||
@@ -92,15 +86,18 @@ export function BulkAiAnalyzer() {
|
||||
} else {
|
||||
console.warn(`[BulkAiAnalyzer] Unexpected response shape for ${chunk.rayon}:`, data);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`[BulkAiAnalyzer] Failed to parse JSON for chunk ${chunk.rayon}:`, e);
|
||||
console.error(`[BulkAiAnalyzer] Failed fetch for chunk ${chunk.rayon}:`, e);
|
||||
setProgress(prev => ({ ...prev, errors: prev.errors + 1 }));
|
||||
}
|
||||
|
||||
completed++;
|
||||
|
||||
// Respect OpenRouter free-tier rate limits — pause 3s before next chunk
|
||||
// Always wait 20s between chunks — free tier allows ~3 req/min
|
||||
if (completed < chunks.length) {
|
||||
await new Promise(resolve => setTimeout(resolve, 3000));
|
||||
setProgress(prev => ({ ...prev, current: completed, message: `En attente... (lot ${completed}/${chunks.length})` }));
|
||||
await new Promise(resolve => setTimeout(resolve, 20000));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user