import React, { useEffect } from "react"; import { HTTP_BACKEND_URL } from "../../config"; import RatingPicker from "./RatingPicker"; interface Eval { input: string; output: string; } function EvalsPage() { const [evals, setEvals] = React.useState([]); const [ratings, setRatings] = React.useState([]); const total = ratings.reduce((a, b) => a + b, 0); const max = ratings.length * 4; const score = ((total / max) * 100 || 0).toFixed(2); useEffect(() => { if (evals.length > 0) return; fetch(`${HTTP_BACKEND_URL}/evals`) .then((res) => res.json()) .then((data) => { setEvals(data); setRatings(new Array(data.length).fill(0)); }); }, [evals]); return (
{/* Display total */}
Total: {total} out of {max} ({score}%)
{evals.map((e, index) => (
{/* Put output into an iframe */}
{ const newRatings = [...ratings]; newRatings[index] = rating; setRatings(newRatings); }} />
))}
); } export default EvalsPage;