File size: 2,010 Bytes
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
import { useRef } from "react";

const SIMULATED_LOGS = [
  "[INFO] Initializing benchmark generation...",
  "[INFO] Generating base configuration file...",
  "[SUCCESS] Stage completed: configuration",
  "[INFO] Finding available providers for models...",
  "[SUCCESS] Stage completed: provider_check",
  "[INFO] Starting ingestion process...",
  "[SUCCESS] Stage completed: ingestion",
  "[INFO] Processing document content for upload...",
  "[SUCCESS] Stage completed: upload_ingest_to_hub",
  "[INFO] Generating document summary...",
  "[SUCCESS] Stage completed: summarization",
  "[INFO] Chunking content for better analysis...",
  "[SUCCESS] Stage completed: chunking",
  "[INFO] Generating single-shot questions...",
  "[SUCCESS] Stage completed: single_shot_question_generation",
  "[SUCCESS] Benchmark process completed successfully",
];

export const useBenchmarkSimulation = (
  setGenerationLogs,
  setGenerationComplete,
  onComplete,
  sessionId
) => {
  const simulationIntervalRef = useRef(null);
  const SIMULATION_DURATION = 80000; // 20 seconds

  const startSimulation = () => {
    setGenerationLogs([]);
    let currentStep = 0;

    const addNextLog = () => {
      if (currentStep < SIMULATED_LOGS.length) {
        setGenerationLogs((prevLogs) => [
          ...prevLogs,
          SIMULATED_LOGS[currentStep],
        ]);
        currentStep++;

        if (currentStep >= SIMULATED_LOGS.length) {
          setTimeout(() => {
            setGenerationComplete(true);
            clearInterval(simulationIntervalRef.current);
            if (onComplete) {
              onComplete({
                success: true,
                sessionId,
                logs: SIMULATED_LOGS,
              });
            }
          }, 1000);
        }
      }
    };

    const totalSteps = SIMULATED_LOGS.length;
    const intervalPerStep = SIMULATION_DURATION / totalSteps;

    simulationIntervalRef.current = setInterval(addNextLog, intervalPerStep);
  };

  return { startSimulation };
};