Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)
Python
remove a whole bunch of code for handling older models
Abi Rajaa31d0638ad02
diff --git a/backend/llm.py b/backend/llm.pyindex 3000e711..9073a92e 100644--- a/backend/llm.py+++ b/backend/llm.py@@ -27,16 +27,6 @@ class Llm(Enum):O1_2024_12_17 = "o1-2024-12-17"-# Will throw errors if you send a garbage string-def convert_frontend_str_to_llm(frontend_str: str) -> Llm:- if frontend_str == "gpt_4_vision":- return Llm.GPT_4_VISION- elif frontend_str == "claude_3_sonnet":- return Llm.CLAUDE_3_SONNET- else:- return Llm(frontend_str)--async def stream_openai_response(messages: List[ChatCompletionMessageParam],api_key: str,diff --git a/backend/routes/generate_code.py b/backend/routes/generate_code.pyindex 4eb9928f..4837704d 100644--- a/backend/routes/generate_code.py+++ b/backend/routes/generate_code.py@@ -17,7 +17,6 @@ from config import (from custom_types import InputModefrom llm import (Llm,- convert_frontend_str_to_llm,stream_claude_response,stream_claude_response_native,stream_gemini_response,@@ -38,21 +37,6 @@ from ws.constants import APP_ERROR_WEB_SOCKET_CODE # type: ignorerouter = APIRouter()-# Auto-upgrade usage of older models-def auto_upgrade_model(code_generation_model: Llm) -> Llm:- if code_generation_model in {Llm.GPT_4_VISION, Llm.GPT_4_TURBO_2024_04_09}:- print(- f"Initial deprecated model: {code_generation_model}. Auto-updating code generation model to GPT-4O-2024-05-13"- )- return Llm.GPT_4O_2024_05_13- elif code_generation_model == Llm.CLAUDE_3_SONNET:- print(- f"Initial deprecated model: {code_generation_model}. Auto-updating code generation model to CLAUDE-3.5-SONNET-2024-06-20"- )- return Llm.CLAUDE_3_5_SONNET_2024_06_20- return code_generation_model--# Generate images, if neededasync def perform_image_generation(completion: str,@@ -92,7 +76,6 @@ async def perform_image_generation(class ExtractedParams:stack: Stackinput_mode: InputMode- code_generation_model: Llmshould_generate_images: boolopenai_api_key: str | Noneanthropic_api_key: str | None@@ -116,16 +99,6 @@ async def extract_params(raise ValueError(f"Invalid input mode: {input_mode}")validated_input_mode = cast(InputMode, input_mode)- # Read the model from the request. Fall back to default if not provided.- code_generation_model_str = params.get(- "codeGenerationModel", Llm.GPT_4O_2024_05_13.value- )- try:- code_generation_model = convert_frontend_str_to_llm(code_generation_model_str)- except ValueError:- await throw_error(f"Invalid model: {code_generation_model_str}")- raise ValueError(f"Invalid model: {code_generation_model_str}")-openai_api_key = get_from_settings_dialog_or_env(params, "openAiApiKey", OPENAI_API_KEY)@@ -151,7 +124,6 @@ async def extract_params(return ExtractedParams(stack=validated_stack,input_mode=validated_input_mode,- code_generation_model=code_generation_model,should_generate_images=should_generate_images,openai_api_key=openai_api_key,anthropic_api_key=anthropic_api_key,@@ -211,15 +183,11 @@ async def stream_code(websocket: WebSocket):extracted_params = await extract_params(params, throw_error)stack = extracted_params.stackinput_mode = extracted_params.input_mode- code_generation_model = extracted_params.code_generation_modelopenai_api_key = extracted_params.openai_api_keyopenai_base_url = extracted_params.openai_base_urlanthropic_api_key = extracted_params.anthropic_api_keyshould_generate_images = extracted_params.should_generate_images- # Auto-upgrade usage of older models- code_generation_model = auto_upgrade_model(code_generation_model)-print(f"Generating {stack} code in {input_mode} mode")for i in range(NUM_VARIANTS):diff --git a/backend/test_llm.py b/backend/test_llm.pydeleted file mode 100644index aeb02aba..00000000--- a/backend/test_llm.py+++ /dev/null@@ -1,41 +0,0 @@-import unittest-from llm import convert_frontend_str_to_llm, Llm---class TestConvertFrontendStrToLlm(unittest.TestCase):- def test_convert_valid_strings(self):- self.assertEqual(- convert_frontend_str_to_llm("gpt_4_vision"),- Llm.GPT_4_VISION,- "Should convert 'gpt_4_vision' to Llm.GPT_4_VISION",- )- self.assertEqual(- convert_frontend_str_to_llm("claude_3_sonnet"),- Llm.CLAUDE_3_SONNET,- "Should convert 'claude_3_sonnet' to Llm.CLAUDE_3_SONNET",- )- self.assertEqual(- convert_frontend_str_to_llm("claude-3-opus-20240229"),- Llm.CLAUDE_3_OPUS,- "Should convert 'claude-3-opus-20240229' to Llm.CLAUDE_3_OPUS",- )- self.assertEqual(- convert_frontend_str_to_llm("gpt-4-turbo-2024-04-09"),- Llm.GPT_4_TURBO_2024_04_09,- "Should convert 'gpt-4-turbo-2024-04-09' to Llm.GPT_4_TURBO_2024_04_09",- )- self.assertEqual(- convert_frontend_str_to_llm("gpt-4o-2024-05-13"),- Llm.GPT_4O_2024_05_13,- "Should convert 'gpt-4o-2024-05-13' to Llm.GPT_4O_2024_05_13",- )-- def test_convert_invalid_string_raises_exception(self):- with self.assertRaises(ValueError):- convert_frontend_str_to_llm("invalid_string")- with self.assertRaises(ValueError):- convert_frontend_str_to_llm("another_invalid_string")---if __name__ == "__main__":- unittest.main()