mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-24 15:38:09 +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,
|
marge: r.totalMarge ? parseFloat(((r.totalMarge / (r.totalCa || 1)) * 100).toFixed(1)) : 0,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
try {
|
||||||
const res = await fetch("/api/ai/batch-analyze", {
|
const res = await fetch("/api/ai/batch-analyze", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({ rayon: chunk.rayon, products: payloadProducts })
|
||||||
rayon: chunk.rayon,
|
|
||||||
products: payloadProducts
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const errText = await res.text();
|
const errText = await res.text();
|
||||||
console.error(`[BulkAiAnalyzer] Erreur HTTP ${res.status} sur le lot ${chunk.rayon}:`, errText);
|
console.error(`[BulkAiAnalyzer] Erreur HTTP ${res.status} sur le lot ${chunk.rayon}:`, errText);
|
||||||
setProgress(prev => ({ ...prev, errors: prev.errors + 1 }));
|
setProgress(prev => ({ ...prev, errors: prev.errors + 1 }));
|
||||||
completed++;
|
} else {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
console.log(`[BulkAiAnalyzer] Response for ${chunk.rayon}:`, data);
|
console.log(`[BulkAiAnalyzer] Response for ${chunk.rayon}:`, data);
|
||||||
|
|
||||||
@@ -92,15 +86,18 @@ export function BulkAiAnalyzer() {
|
|||||||
} else {
|
} else {
|
||||||
console.warn(`[BulkAiAnalyzer] Unexpected response shape for ${chunk.rayon}:`, data);
|
console.warn(`[BulkAiAnalyzer] Unexpected response shape for ${chunk.rayon}:`, data);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (e) {
|
} 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++;
|
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) {
|
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