Skip to content

Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)

Python

include models in eval

Abi Raja65bf3a2dbc45
diff --git a/backend/evals/core.py b/backend/evals/core.py
index dcd27335..b928b498 100644
--- a/backend/evals/core.py
+++ b/backend/evals/core.py
@@ -1,6 +1,10 @@
from config import ANTHROPIC_API_KEY, GEMINI_API_KEY, OPENAI_API_KEY
from llm import Llm
-from models import stream_claude_response, stream_openai_response, stream_gemini_response
+from models import (
+ stream_claude_response,
+ stream_gemini_response,
+ stream_openai_response,
+)
from prompts import assemble_prompt
from prompts.types import Stack
from openai.types.chat import ChatCompletionMessageParam
@@ -23,6 +27,8 @@ async def generate_code_core(
or model == Llm.CLAUDE_3_5_SONNET_2024_06_20
or model == Llm.CLAUDE_3_5_SONNET_2024_10_22
or model == Llm.CLAUDE_3_7_SONNET_2025_02_19
+ or model == Llm.CLAUDE_4_SONNET_2025_05_14
+ or model == Llm.CLAUDE_4_OPUS_2025_05_14
):
if not ANTHROPIC_API_KEY:
raise Exception("Anthropic API key not found")
diff --git a/frontend/src/components/evals/BestOfNEvalsPage.tsx b/frontend/src/components/evals/BestOfNEvalsPage.tsx
index 9800a513..e6710b45 100644
--- a/frontend/src/components/evals/BestOfNEvalsPage.tsx
+++ b/frontend/src/components/evals/BestOfNEvalsPage.tsx
@@ -1,4 +1,4 @@
-import React, { useState } from "react";
+import React, { useState, useEffect, useRef } from "react";
import { HTTP_BACKEND_URL } from "../../config";
import { Dialog, DialogContent, DialogTrigger } from "../ui/dialog";
import EvalNavigation from "./EvalNavigation";
@@ -24,6 +24,112 @@ function BestOfNEvalsPage() {
const [folderPaths, setFolderPaths] = useState<string[]>([""]);
const [isLoading, setIsLoading] = useState(false);
const [selectedHtml, setSelectedHtml] = useState<string>("");
+
+ // Navigation state
+ const [currentComparisonIndex, setCurrentComparisonIndex] = useState(0);
+
+ // Refs for synchronized scrolling
+ const iframeRefs = useRef<(HTMLIFrameElement | null)[]>([]);
+
+ // Synchronized scrolling effect
+ useEffect(() => {
+ const setupSyncScrolling = () => {
+ const iframes = iframeRefs.current.filter(Boolean);
+ if (iframes.length < 2) return;
+
+ const syncScroll = (sourceIframe: HTMLIFrameElement) => {
+ try {
+ const sourceDocument = sourceIframe.contentDocument || sourceIframe.contentWindow?.document;
+ if (!sourceDocument) return;
+
+ const syncHandler = () => {
+ const scrollTop = sourceDocument.documentElement.scrollTop || sourceDocument.body.scrollTop;
+ const scrollLeft = sourceDocument.documentElement.scrollLeft || sourceDocument.body.scrollLeft;
+
+ iframes.forEach(iframe => {
+ if (!iframe || iframe === sourceIframe) return;
+ try {
+ const targetDocument = iframe.contentDocument || iframe.contentWindow?.document;
+ if (targetDocument) {
+ targetDocument.documentElement.scrollTop = scrollTop;
+ targetDocument.body.scrollTop = scrollTop;
+ targetDocument.documentElement.scrollLeft = scrollLeft;
+ targetDocument.body.scrollLeft = scrollLeft;
+ }
+ } catch (e) {
+ // Ignore cross-origin errors
+ }
+ });
+ };
+
+ sourceDocument.addEventListener('scroll', syncHandler);
+ return () => sourceDocument.removeEventListener('scroll', syncHandler);
+ } catch (e) {
+ // Ignore cross-origin errors
+ }
+ };
+
+ const cleanupFunctions = iframes.map(iframe => iframe ? syncScroll(iframe) : null).filter(Boolean);
+ return () => cleanupFunctions.forEach(cleanup => cleanup?.());
+ };
+
+ // Wait for iframes to load
+ const timer = setTimeout(setupSyncScrolling, 1000);
+ return () => clearTimeout(timer);
+ }, [currentComparisonIndex, evals]);
+
+ // Navigation functions
+ const goToPrevious = () => {
+ setCurrentComparisonIndex(prev => Math.max(0, prev - 1));
+ };
+
+ const goToNext = () => {
+ setCurrentComparisonIndex(prev => Math.min(evals.length - 1, prev + 1));
+ };
+
+ const goToComparison = (index: number) => {
+ setCurrentComparisonIndex(Math.max(0, Math.min(evals.length - 1, index)));
+ };
+
+ // Keyboard shortcuts
+ useEffect(() => {
+ const handleKeyPress = (e: KeyboardEvent) => {
+ if (evals.length === 0) return;
+
+ switch (e.key) {
+ case 'ArrowLeft':
+ e.preventDefault();
+ goToPrevious();
+ break;
+ case 'ArrowRight':
+ e.preventDefault();
+ goToNext();
+ break;
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ e.preventDefault();
+ const modelIndex = parseInt(e.key) - 1;
+ if (modelIndex < folderNames.length) {
+ handleVote(currentComparisonIndex, modelIndex);
+ }
+ break;
+ case 't':
+ e.preventDefault();
+ handleVote(currentComparisonIndex, 'tie');
+ break;
+ }
+ };
+
+ window.addEventListener('keydown', handleKeyPress);
+ return () => window.removeEventListener('keydown', handleKeyPress);
+ }, [currentComparisonIndex, evals.length, folderNames.length]);
// Add/remove folder input fields
const addFolderInput = () => {
@@ -84,6 +190,9 @@ function BestOfNEvalsPage() {
setEvals(data.evals);
setOutcomes(new Array(data.evals.length).fill(null));
setFolderNames(data.folder_names);
+ setCurrentComparisonIndex(0);
+ // Reset iframe refs
+ iframeRefs.current = [];
} catch (error) {
console.error("Error loading evals:", error);
alert(
@@ -101,6 +210,7 @@ function BestOfNEvalsPage() {
};
const stats = calculateStats();
+ const currentEval = evals[currentComparisonIndex];
return (
<div className="mx-auto">
@@ -145,107 +255,148 @@ function BestOfNEvalsPage() {
{evals.length > 0 && (
<>
- <span className="text-2xl font-semibold">
- Total votes: {stats.totalVotes}
- </span>
- <div className="text-lg mt-2">
- {stats.stats.map((stat, i) => (
- <span key={i}>
- {stat.name}: {stat.wins} ({stat.percentage}%) |{" "}
+ <div className="text-center mb-4">
+ <div className="text-2xl font-semibold mb-2">
+ Comparison {currentComparisonIndex + 1} of {evals.length}
+ </div>
+ <div className="text-lg">
+ Total votes: {stats.totalVotes} | Progress: {Math.round((stats.totalVotes / evals.length) * 100)}%
+ </div>
+ <div className="text-sm mt-1">
+ {stats.stats.map((stat, i) => (
+ <span key={i}>
+ {stat.name}: {stat.wins} ({stat.percentage}%) |{" "}
+ </span>
+ ))}
+ <span>
+ Ties: {stats.ties} ({stats.tiePercentage}%)
</span>
- ))}
- <span>
- Ties: {stats.ties} ({stats.tiePercentage}%)
- </span>
+ </div>
+ </div>
+
+ {/* Navigation Controls */}
+ <div className="flex items-center gap-4 mb-4">
+ <button
+ onClick={goToPrevious}
+ disabled={currentComparisonIndex === 0}
+ className="bg-gray-600 hover:bg-gray-700 disabled:bg-gray-800 text-white px-4 py-2 rounded"
+ >
+ ← Previous
+ </button>
+
+ <select
+ value={currentComparisonIndex}
+ onChange={(e) => goToComparison(parseInt(e.target.value))}
+ className="bg-gray-700 text-white px-3 py-2 rounded"
+ >
+ {evals.map((_, index) => (
+ <option key={index} value={index}>
+ Comparison {index + 1} {outcomes[index] !== null ? '✓' : ''}
+ </option>
+ ))}
+ </select>
+
+ <button
+ onClick={goToNext}
+ disabled={currentComparisonIndex === evals.length - 1}
+ className="bg-gray-600 hover:bg-gray-700 disabled:bg-gray-800 text-white px-4 py-2 rounded"
+ >
+ Next →
+ </button>
+ </div>
+
+ {/* Keyboard shortcuts help */}
+ <div className="text-xs text-gray-400 mb-4">
+ Use ← → arrows to navigate, number keys 1-{folderNames.length} to vote, 't' for tie
</div>
</>
)}
</div>
- <div className="flex flex-col gap-y-8 mt-4 mx-auto justify-center">
- {evals.map((e, index) => (
- <div className="flex flex-col justify-center" key={index}>
- <h2 className="font-bold text-lg ml-4 mb-2">
- Comparison {index + 1}
- </h2>
-
- <div className="w-full flex justify-center mb-4">
- <div className="w-1/2 max-w-2xl p-1 border">
- <img src={e.input} alt={`Input for comparison ${index}`} />
- </div>
+ {/* Single Comparison View */}
+ {currentEval && (
+ <div className="flex flex-col gap-y-4 mt-4 mx-auto justify-center max-w-7xl px-4">
+ {/* Input Image */}
+ <div className="w-full flex justify-center mb-4">
+ <div className="w-1/2 max-w-md p-1 border">
+ <img src={currentEval.input} alt={`Input for comparison ${currentComparisonIndex + 1}`} />
</div>
+ </div>
- <div className="flex flex-wrap gap-4 justify-center px-4">
- {e.outputs.map((output, outputIndex) => (
- <div
- className={`w-full sm:w-[calc(50%-1rem)] p-1 border ${
- outcomes[index] === outputIndex
- ? "border-green-500 border-4"
- : ""
- }`}
- key={outputIndex}
- >
- <div className="relative">
- <div className="absolute top-0 left-0 bg-black text-white px-2 py-1 z-10">
- {folderNames[outputIndex]}
- </div>
- <iframe
- srcDoc={output}
- className="w-full aspect-[3/2] transform scale-100"
- style={{ minHeight: "400px" }}
- ></iframe>
- <Dialog>
- <DialogTrigger asChild>
- <button
- className="absolute top-2 right-2 bg-blue-500 text-white px-2 py-1 rounded text-sm"
- onClick={() => setSelectedHtml(output)}
- >
- Full Screen
- </button>
- </DialogTrigger>
- <DialogContent className="w-[95vw] max-w-[95vw] h-[95vh] max-h-[95vh]">
- <div className="absolute top-2 left-2 bg-black text-white px-2 py-1 z-10">
- {folderNames[outputIndex]}
- </div>
- <iframe
- srcDoc={selectedHtml}
- className="w-full h-full"
- ></iframe>
- </DialogContent>
- </Dialog>
+ {/* Side-by-side outputs */}
+ <div className="grid grid-cols-1 lg:grid-cols-2 gap-4">
+ {currentEval.outputs.map((output, outputIndex) => (
+ <div
+ className={`p-1 border ${
+ outcomes[currentComparisonIndex] === outputIndex
+ ? "border-green-500 border-4"
+ : "border-gray-300"
+ }`}
+ key={outputIndex}
+ >
+ <div className="relative">
+ <div className="absolute top-0 left-0 bg-black text-white px-3 py-2 z-10 font-semibold">
+ {folderNames[outputIndex]} (Press {outputIndex + 1})
</div>
+ <iframe
+ ref={(el) => {
+ iframeRefs.current[outputIndex] = el;
+ }}
+ srcDoc={output}
+ className="w-full h-[600px] transform scale-100"
+ ></iframe>
+ <Dialog>
+ <DialogTrigger asChild>
+ <button
+ className="absolute top-2 right-2 bg-blue-500 text-white px-2 py-1 rounded text-sm z-10"
+ onClick={() => setSelectedHtml(output)}
+ >
+ Full Screen
+ </button>
+ </DialogTrigger>
+ <DialogContent className="w-[95vw] max-w-[95vw] h-[95vh] max-h-[95vh]">
+ <div className="absolute top-2 left-2 bg-black text-white px-2 py-1 z-10">
+ {folderNames[outputIndex]}
+ </div>
+ <iframe
+ srcDoc={selectedHtml}
+ className="w-full h-full"
+ ></iframe>
+ </DialogContent>
+ </Dialog>
</div>
- ))}
- </div>
+ </div>
+ ))}
+ </div>
- <div className="flex flex-wrap justify-center gap-2 mt-4 px-4">
- {folderNames.map((name, i) => (
- <button
- key={i}
- className={`px-4 py-2 rounded ${
- outcomes[index] === i
- ? "bg-green-500 text-white"
- : "bg-gray-200 hover:bg-gray-300"
- }`}
- onClick={() => handleVote(index, i)}
- >
- {name} Wins
- </button>
- ))}
+ {/* Voting buttons */}
+ <div className="flex flex-wrap justify-center gap-2 mt-4">
+ {folderNames.map((name, i) => (
<button
- className={`px-4 py-2 rounded ${
- outcomes[index] === "tie"
+ key={i}
+ className={`px-6 py-3 rounded text-lg font-semibold ${
+ outcomes[currentComparisonIndex] === i
? "bg-green-500 text-white"
- : "bg-gray-200 hover:bg-gray-300"
+ : "bg-gray-200 hover:bg-gray-300 text-black"
}`}
- onClick={() => handleVote(index, "tie")}
+ onClick={() => handleVote(currentComparisonIndex, i)}
>
- Tie
+ {name} Wins ({i + 1})
</button>
- </div>
+ ))}
+ <button
+ className={`px-6 py-3 rounded text-lg font-semibold ${
+ outcomes[currentComparisonIndex] === "tie"
+ ? "bg-green-500 text-white"
+ : "bg-gray-200 hover:bg-gray-300 text-black"
+ }`}
+ onClick={() => handleVote(currentComparisonIndex, "tie")}
+ >
+ Tie (T)
+ </button>
</div>
- ))}
- </div>
+ </div>
+ )}
</div>
);
}