Skip to content

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

Python

support selection of model in run evals interface

Abi Raja9d91a6b5729f
diff --git a/backend/evals/runner.py b/backend/evals/runner.py
index 178cc2bd..7f4618c4 100644
--- a/backend/evals/runner.py
+++ b/backend/evals/runner.py
@@ -1,4 +1,4 @@
-from typing import Any, Coroutine, List
+from typing import Any, Coroutine, List, Optional
import asyncio
import os
from llm import Llm
@@ -7,12 +7,19 @@ from .utils import image_to_data_url
from .config import EVALS_DIR
from typing_extensions import Literal
-Stack = Literal['html_css', 'html_tailwind', 'react_tailwind', 'bootstrap', 'ionic_tailwind', 'vue_tailwind', 'svg']
+Stack = Literal[
+ "html_css",
+ "html_tailwind",
+ "react_tailwind",
+ "bootstrap",
+ "ionic_tailwind",
+ "vue_tailwind",
+ "svg",
+]
+
async def run_image_evals(
- stack: Stack = "html_tailwind",
- model: Llm = Llm.CLAUDE_3_5_SONNET_2024_10_22,
- n: int = 1
+ stack: Stack = "html_tailwind", model: Optional[str] = None, n: int = 1
) -> List[str]:
INPUT_DIR = EVALS_DIR + "/inputs"
OUTPUT_DIR = EVALS_DIR + "/outputs"
@@ -20,6 +27,15 @@ async def run_image_evals(
# Get all the files in the directory (only grab pngs)
evals = [f for f in os.listdir(INPUT_DIR) if f.endswith(".png")]
+ print("User selected model:", model)
+
+ # If model is provided as string, convert it to Llm enum
+ if not model:
+ raise ValueError("No model was provided")
+
+ selected_model = Llm(model)
+ print(f"Running evals for {selected_model} model")
+
tasks: list[Coroutine[Any, Any, str]] = []
for filename in evals:
filepath = os.path.join(INPUT_DIR, filename)
@@ -29,7 +45,7 @@ async def run_image_evals(
task = generate_code_for_image(
image_url=data_url,
stack=stack,
- model=model,
+ model=selected_model,
)
else:
task = generate_code_for_image(
@@ -56,4 +72,4 @@ async def run_image_evals(
file.write(content)
output_files.append(output_filename)
- return output_files
+ return output_files
diff --git a/backend/routes/evals.py b/backend/routes/evals.py
index 3360e5c4..462aeb6b 100644
--- a/backend/routes/evals.py
+++ b/backend/routes/evals.py
@@ -6,7 +6,7 @@ from evals.config import EVALS_DIR
from typing import Set
from evals.runner import run_image_evals
from typing import List
-
+from llm import Llm
router = APIRouter()
@@ -137,7 +137,21 @@ async def get_pairwise_evals(
@router.post("/run_evals", response_model=List[str])
-async def run_evals():
+async def run_evals(model: str):
"""Run evaluations on all images in the inputs directory"""
- output_files = await run_image_evals()
+ output_files = await run_image_evals(model=model)
return output_files
+
+
+async def get_models():
+ current_models = [
+ model.value
+ for model in Llm
+ if model != Llm.GPT_4_TURBO_2024_04_09
+ and model != Llm.GPT_4_VISION
+ and model != Llm.CLAUDE_3_SONNET
+ and model != Llm.CLAUDE_3_OPUS
+ and model != Llm.CLAUDE_3_HAIKU
+ ]
+ return {"models": current_models}
diff --git a/frontend/src/components/evals/RunEvalsPage.tsx b/frontend/src/components/evals/RunEvalsPage.tsx
index 2ed307a1..2ec256f2 100644
--- a/frontend/src/components/evals/RunEvalsPage.tsx
+++ b/frontend/src/components/evals/RunEvalsPage.tsx
@@ -1,18 +1,41 @@
-import { useState } from "react";
+import { useState, useEffect } from "react";
import { Button } from "../ui/button";
import { HTTP_BACKEND_URL } from "../../config";
import { useNavigate } from "react-router-dom";
+interface ModelResponse {
+ models: string[];
+}
+
function RunEvalsPage() {
const [isRunning, setIsRunning] = useState(false);
const navigate = useNavigate();
+ const [models, setModels] = useState<string[]>([]);
+ const [selectedModel, setSelectedModel] = useState<string>("");
+
+ useEffect(() => {
+ console.log("fetching models");
+
+ const fetchModels = async () => {
+ const response = await fetch(`${HTTP_BACKEND_URL}/models`);
+ const data: ModelResponse = await response.json();
+ setModels(data.models);
+ if (data.models.length > 0) {
+ setSelectedModel(data.models[0]);
+ }
+ };
+ fetchModels();
+ }, []);
const runEvals = async () => {
try {
setIsRunning(true);
- const response = await fetch(`${HTTP_BACKEND_URL}/run_evals`, {
- method: "POST",
- });
+ const response = await fetch(
+ `${HTTP_BACKEND_URL}/run_evals?model=${selectedModel}`,
+ {
+ method: "POST",
+ }
+ );
if (!response.ok) {
throw new Error("Failed to run evals");
@@ -33,6 +56,23 @@ function RunEvalsPage() {
return (
<div className="flex flex-col items-center justify-center min-h-screen">
<h1 className="text-2xl font-bold mb-8">Run Evaluations</h1>
+ <div className="mb-4">
+ <label className="block text-gray-700 text-sm font-bold mb-2">
+ Select Model
+ </label>
+ <select
+ value={selectedModel}
+ onChange={(e) => setSelectedModel(e.target.value)}
+ className="shadow border rounded w-full py-2 px-3 text-gray-700"
+ required
+ >
+ {models.map((model) => (
+ <option key={model} value={model}>
+ {model}
+ </option>
+ ))}
+ </select>
+ </div>
<Button onClick={runEvals} disabled={isRunning} className="w-48">
{isRunning ? "Running Evals..." : "Run Evals"}
</Button>