Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)
Python
Explicitly map models to providers
Abi Raja1cb76e96afc0
diff --git a/backend/evals/core.py b/backend/evals/core.pyindex b928b498..f85fff00 100644--- a/backend/evals/core.py+++ b/backend/evals/core.py@@ -1,5 +1,5 @@from config import ANTHROPIC_API_KEY, GEMINI_API_KEY, OPENAI_API_KEY-from llm import Llm+from llm import Llm, OPENAI_MODELS, ANTHROPIC_MODELS, GEMINI_MODELSfrom models import (stream_claude_response,stream_gemini_response,@@ -22,14 +22,7 @@ async def generate_code_core(async def process_chunk(_: str):pass- if (- model == Llm.CLAUDE_3_SONNET- 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 model in ANTHROPIC_MODELS:if not ANTHROPIC_API_KEY:raise Exception("Anthropic API key not found")@@ -39,13 +32,7 @@ async def generate_code_core(callback=lambda x: process_chunk(x),model_name=model.value,)- elif (- model == Llm.GEMINI_2_0_FLASH_EXP- or model == Llm.GEMINI_2_0_PRO_EXP- or model == Llm.GEMINI_2_0_FLASH- or model == Llm.GEMINI_2_5_FLASH_PREVIEW_05_20- or model == Llm.GEMINI_2_5_PRO_PREVIEW_05_06- ):+ elif model in GEMINI_MODELS:if not GEMINI_API_KEY:raise Exception("Gemini API key not found")diff --git a/backend/llm.py b/backend/llm.pyindex 73c9262e..4ece26ee 100644--- a/backend/llm.py+++ b/backend/llm.py@@ -33,3 +33,44 @@ class Llm(Enum):class Completion(TypedDict):duration: floatcode: str+++# Explicitly map each model to the provider backing it. This keeps provider+# groupings authoritative and avoids relying on name conventions when checking+# models elsewhere in the codebase.+MODEL_PROVIDER: dict[Llm, str] = {+ # OpenAI models+ Llm.GPT_4_VISION: "openai",+ Llm.GPT_4_TURBO_2024_04_09: "openai",+ Llm.GPT_4O_2024_05_13: "openai",+ Llm.GPT_4O_2024_08_06: "openai",+ Llm.GPT_4O_2024_11_20: "openai",+ Llm.GPT_4_1_2025_04_14: "openai",+ Llm.GPT_4_1_MINI_2025_04_14: "openai",+ Llm.GPT_4_1_NANO_2025_04_14: "openai",+ Llm.O1_2024_12_17: "openai",+ Llm.O4_MINI_2025_04_16: "openai",+ Llm.O3_2025_04_16: "openai",++ # Anthropic models+ Llm.CLAUDE_3_SONNET: "anthropic",+ Llm.CLAUDE_3_OPUS: "anthropic",+ Llm.CLAUDE_3_HAIKU: "anthropic",+ Llm.CLAUDE_3_5_SONNET_2024_06_20: "anthropic",+ Llm.CLAUDE_3_5_SONNET_2024_10_22: "anthropic",+ Llm.CLAUDE_3_7_SONNET_2025_02_19: "anthropic",+ Llm.CLAUDE_4_SONNET_2025_05_14: "anthropic",+ Llm.CLAUDE_4_OPUS_2025_05_14: "anthropic",++ # Gemini models+ Llm.GEMINI_2_0_FLASH_EXP: "gemini",+ Llm.GEMINI_2_0_FLASH: "gemini",+ Llm.GEMINI_2_0_PRO_EXP: "gemini",+ Llm.GEMINI_2_5_FLASH_PREVIEW_05_20: "gemini",+ Llm.GEMINI_2_5_PRO_PREVIEW_05_06: "gemini",+}++# Convenience sets for membership checks+OPENAI_MODELS = {m for m, p in MODEL_PROVIDER.items() if p == "openai"}+ANTHROPIC_MODELS = {m for m, p in MODEL_PROVIDER.items() if p == "anthropic"}+GEMINI_MODELS = {m for m, p in MODEL_PROVIDER.items() if p == "gemini"}diff --git a/backend/routes/generate_code.py b/backend/routes/generate_code.pyindex 0f4734c3..e3da55cf 100644--- a/backend/routes/generate_code.py+++ b/backend/routes/generate_code.py@@ -17,7 +17,13 @@ from config import (SHOULD_MOCK_AI_RESPONSE,)from custom_types import InputMode-from llm import Completion, Llm+from llm import (+ Completion,+ Llm,+ OPENAI_MODELS,+ ANTHROPIC_MODELS,+ GEMINI_MODELS,+)from models import (stream_claude_response,stream_claude_response_native,@@ -564,15 +570,7 @@ class ParallelGenerationStage:tasks: List[Coroutine[Any, Any, Completion]] = []for index, model in enumerate(variant_models):- if (- model == Llm.GPT_4O_2024_11_20- or model == Llm.O1_2024_12_17- or model == Llm.O4_MINI_2025_04_16- or model == Llm.O3_2025_04_16- or model == Llm.GPT_4_1_2025_04_14- or model == Llm.GPT_4_1_MINI_2025_04_14- or model == Llm.GPT_4_1_NANO_2025_04_14- ):+ if model in OPENAI_MODELS:if self.openai_api_key is None:raise Exception("OpenAI API key is missing.")@@ -583,13 +581,7 @@ class ParallelGenerationStage:index=index,))- elif GEMINI_API_KEY and (- model == Llm.GEMINI_2_0_PRO_EXP- or model == Llm.GEMINI_2_0_FLASH_EXP- or model == Llm.GEMINI_2_0_FLASH- or model == Llm.GEMINI_2_5_FLASH_PREVIEW_05_20- or model == Llm.GEMINI_2_5_PRO_PREVIEW_05_06- ):+ elif GEMINI_API_KEY and model in GEMINI_MODELS:tasks.append(stream_gemini_response(prompt_messages,@@ -598,13 +590,7 @@ class ParallelGenerationStage:model_name=model.value,))- elif (- 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- ):+ elif model in ANTHROPIC_MODELS:if self.anthropic_api_key is None:raise Exception("Anthropic API key is missing.")