File size: 4,880 Bytes
ebdfd67
 
 
 
81e0b0c
d6b6619
83106dd
 
ebdfd67
 
 
 
 
 
 
 
 
83106dd
 
ebdfd67
 
 
 
 
d6f0b38
ebdfd67
 
 
 
 
 
 
d6f0b38
ebdfd67
d6b6619
d6f0b38
ebdfd67
 
d6f0b38
ebdfd67
 
 
d6f0b38
ebdfd67
 
 
d6f0b38
ebdfd67
 
 
 
 
 
d6f0b38
ebdfd67
 
d6f0b38
ebdfd67
 
d6f0b38
ebdfd67
 
 
 
 
 
 
d6f0b38
ebdfd67
 
d6f0b38
ebdfd67
 
 
 
 
 
 
 
 
 
 
ffa4ae8
 
 
 
 
 
 
 
 
 
ebdfd67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83106dd
ebdfd67
 
83106dd
ebdfd67
 
81e0b0c
ebdfd67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React, { useState, useEffect } from "react";
import { Box, CircularProgress } from "@mui/material";
import { useNavigate, useSearchParams, Navigate } from "react-router-dom";
import Intro from "../components/Intro";
import Display from "../components/Benchmark/Display";
import API_CONFIG from "../config/api";
import { useThemeMode } from "../hooks/useThemeMode";
import getTheme from "../config/theme";

function BenchmarkDisplayPage() {
  const navigate = useNavigate();
  const [searchParams] = useSearchParams();
  const sessionId = searchParams.get("session");
  const [benchmarkQuestions, setBenchmarkQuestions] = useState([]);
  const [datasetUrl, setDatasetUrl] = useState(null);
  const [isValidSession, setIsValidSession] = useState(true);
  const [isLoading, setIsLoading] = useState(true);
  const { mode } = useThemeMode();
  const theme = getTheme(mode);

  useEffect(() => {
    console.log("BenchmarkDisplayPage useEffect - sessionId:", sessionId);

    if (!sessionId) {
      console.log("Missing session ID, redirecting to home");
      setIsValidSession(false);
      return;
    }

    setIsLoading(true);

    const fetchBenchmarkQuestions = async () => {
      console.log("Attempting to fetch questions for session:", sessionId);
      try {
        const apiUrl = `${API_CONFIG.BASE_URL}/benchmark-questions/${sessionId}`;
        console.log("API call:", apiUrl);

        const response = await fetch(apiUrl);
        console.log("API response received:", response.status);

        if (!response.ok) {
          if (response.status === 404) {
            console.error("Session not found");
            setIsValidSession(false);
            return;
          } else {
            console.error(`Server error: ${response.status}`);
            setIsLoading(false);
            return;
          }
        }

        const data = await response.json();
        console.log("API data:", data);

        if (data.success && data.questions && data.questions.length > 0) {
          console.log("Questions loaded successfully:", data.questions);
          setBenchmarkQuestions(data.questions);
        } else {
          console.warn("Failed to load questions, using default values");
        }

        if (data.dataset_url) {
          setDatasetUrl(data.dataset_url);
        } else {
          const url = `https://huggingface.co/datasets/yourbench/yourbench_${sessionId}`;
          setDatasetUrl(url);
          console.log("Dataset URL generated:", url);
        }
      } catch (error) {
        console.error("Error retrieving questions:", error);
        setIsValidSession(false);
      } finally {
        setIsLoading(false);
      }
    };

    fetchBenchmarkQuestions();
  }, [sessionId]);

  const handleStartEvaluation = () => {
    console.log("Starting evaluation with session ID:", sessionId);
    const isDefault = [
      "the-bitter-lesson",
      "hurricane-faq",
      "pokemon-guide",
    ].includes(sessionId);
    navigate(
      `/benchmark-evaluation?session=${sessionId}&isDefault=${
        isDefault ? "true" : "false"
      }`
    );
  };

  const defaultSampleQuestions = [
    {
      id: 1,
      question: "What are the key features discussed in the document?",
      answer:
        "The document discusses features such as scalability, integration capabilities, and security measures that are important for enterprise solutions.",
      type: "single_shot",
    },
    {
      id: 2,
      question:
        "How does the proposed solution address the challenges mentioned in section 2 in relation to the overall market trends?",
      answer:
        "The proposed solution addresses the challenges by incorporating AI-driven analytics that adapt to changing market conditions while maintaining compliance with industry regulations, thus providing a competitive edge in the evolving marketplace.",
      type: "multi_hop",
    },
  ];

  if (!isValidSession) {
    return <Navigate to="/" />;
  }

  return (
    <>
      <Intro />
      {isLoading ? (
        <Box
          sx={{
            display: "flex",
            justifyContent: "center",
            alignItems: "center",
            mt: 8,
            mb: 8,
          }}
        >
          <CircularProgress size={60} />
        </Box>
      ) : (
        <Box
          sx={{
            border: `1px solid ${theme.palette.divider}`,
            borderRadius: 2,
            p: 4,
            bgcolor: "background.paper",
          }}
        >
          <Display
            onStartEvaluation={handleStartEvaluation}
            sessionId={sessionId}
            datasetUrl={datasetUrl}
            sampleQuestions={
              benchmarkQuestions.length > 0
                ? benchmarkQuestions
                : defaultSampleQuestions
            }
          />
        </Box>
      )}
    </>
  );
}

export default BenchmarkDisplayPage;