Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 6,214 Bytes
a86c1f9 81e0b0c a86c1f9 81e0b0c a86c1f9 81e0b0c a86c1f9 81e0b0c a86c1f9 81e0b0c a86c1f9 81e0b0c a86c1f9 81e0b0c a86c1f9 81e0b0c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
import React, { useState, useEffect, useRef } from "react";
import { Box, Typography, CircularProgress, Alert, Paper } from "@mui/material";
import { useNavigate, useSearchParams } from "react-router-dom";
import ErrorOutlineIcon from "@mui/icons-material/ErrorOutline";
import { useTimer } from "./hooks/useTimer";
import { useEvaluation } from "./hooks/useEvaluation";
import ErrorDisplay from "../common/ErrorDisplay";
// Messages de simulation pour les documents par défaut avec timing personnalisé
const SIMULATION_MESSAGES = [
{
message: "Initializing evaluation environment",
step: 1,
totalSteps: 5,
timing: 0,
}, // Immédiat
{
message: "Finding available model providers",
step: 2,
totalSteps: 5,
timing: 1500,
}, // Après 1.5s
{
message: "Starting evaluation process",
step: 3,
totalSteps: 5,
timing: 3000,
}, // Après 3s
{ message: "Evaluating models", step: 4, totalSteps: 5, timing: 5000 }, // Après 5s
{
message: "Storing evaluation results",
step: 5,
totalSteps: 5,
timing: 7000,
}, // Après 7s
];
// Durée totale pour rediriger à la fin de la simulation
const TOTAL_SIMULATION_DURATION = 8000; // 8 secondes
const BenchmarkEvaluation = ({ sessionId, isDefaultDocument, onComplete }) => {
const [searchParams] = useSearchParams();
const isDefault =
isDefaultDocument ||
["the-bitter-lesson", "hurricane-faq", "pokemon-guide"].includes(sessionId);
const navigate = useNavigate();
const simulationTimeoutsRef = useRef([]);
// États pour la simulation
const [simulationStep, setSimulationStep] = useState(0);
const [simulationComplete, setSimulationComplete] = useState(false);
// Use our custom hooks
const { formatElapsedTime, stopTimer } = useTimer();
const {
error,
evaluationComplete: realComplete,
currentStep,
evaluationStarted,
startEvaluation,
currentStepLabel,
totalSteps,
} = useEvaluation(sessionId, () => {
if (onComplete) {
onComplete();
}
});
// Gérer la simulation pour les documents par défaut
useEffect(() => {
// Seulement exécuter pour les documents par défaut et seulement une fois
if (!isDefault || simulationTimeoutsRef.current.length > 0) return;
console.log("Starting simulation for default document:", sessionId);
// Créer des timeouts pour chaque étape avec les timings personnalisés
for (let i = 1; i < SIMULATION_MESSAGES.length; i++) {
const messageData = SIMULATION_MESSAGES[i];
const timeout = setTimeout(() => {
console.log(`Simulation step ${i + 1}: ${messageData.message}`);
setSimulationStep(i);
}, messageData.timing);
simulationTimeoutsRef.current.push(timeout);
}
// Timeout final pour terminer la simulation
const finalTimeout = setTimeout(() => {
console.log("Simulation complete, redirecting");
setSimulationComplete(true);
if (onComplete) {
onComplete();
}
}, TOTAL_SIMULATION_DURATION);
simulationTimeoutsRef.current.push(finalTimeout);
// Nettoyage au démontage
return () => {
simulationTimeoutsRef.current.forEach(clearTimeout);
};
}, [isDefault, sessionId, onComplete]);
// Handle automatic redirection when evaluation is complete
useEffect(() => {
if (realComplete || simulationComplete) {
navigate(`/evaluation-display?session=${sessionId}`);
}
}, [realComplete, simulationComplete, sessionId, navigate]);
// Start evaluation if not default and not started
useEffect(() => {
if (!isDefault && !evaluationStarted) {
startEvaluation();
}
}, [isDefault, evaluationStarted, startEvaluation]);
// Stop timer when complete
useEffect(() => {
if (realComplete || simulationComplete) {
stopTimer();
}
}, [realComplete, simulationComplete, stopTimer]);
const isComplete = realComplete || simulationComplete;
const currentStepInfo = isDefault
? `${SIMULATION_MESSAGES[simulationStep].message} (${SIMULATION_MESSAGES[simulationStep].step}/${SIMULATION_MESSAGES[simulationStep].totalSteps})`
: `${currentStepLabel} (${currentStep + 1}/${totalSteps})`;
return (
<Paper
elevation={3}
sx={{
p: 4,
mt: 3,
mb: 3,
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
minHeight: 200,
position: "relative",
}}
>
{/* Temps estimé */}
<Box
sx={{
position: "absolute",
top: 12,
right: 12,
backgroundColor: "rgba(0, 0, 0, 0.04)",
borderRadius: "4px",
px: 1,
py: 0.5,
display: "inline-flex",
alignItems: "center",
}}
>
<Typography
variant="caption"
sx={{
fontSize: "0.675rem",
color: "text.secondary",
fontWeight: 500,
}}
>
Estimated time ~ 1m30s
</Typography>
</Box>
{error ? (
<ErrorDisplay error={error} />
) : (
<>
{isComplete ? (
<Alert severity="success" sx={{ width: "100%", mb: 3 }}>
Evaluation completed successfully!
</Alert>
) : (
<>
<CircularProgress size={60} sx={{ mb: 2 }} />
<Typography variant="h6" component="div" gutterBottom>
Benchmark evaluation...
</Typography>
{/* Step progress indicator */}
<Typography variant="body1" color="text.secondary">
{currentStepInfo}
</Typography>
{/* Timer display */}
<Box
sx={{
display: "flex",
alignItems: "center",
mt: 1,
color: "text.secondary",
opacity: 0.5,
}}
>
<Typography variant="body2">{formatElapsedTime()}</Typography>
</Box>
</>
)}
</>
)}
</Paper>
);
};
export default BenchmarkEvaluation;
|