Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)
Python
fix imported code prompt for Claude which doesn't allow multiple 'user' role messages in a row
Abi Raja4288cf208871
diff --git a/backend/prompts/__init__.py b/backend/prompts/__init__.pyindex 4f2e3295..dc96ab93 100644--- a/backend/prompts/__init__.py+++ b/backend/prompts/__init__.py@@ -1,6 +1,7 @@from typing import List, NoReturn, Unionfrom openai.types.chat import ChatCompletionMessageParam, ChatCompletionContentPartParam+from llm import Llmfrom prompts.imported_code_prompts import IMPORTED_CODE_SYSTEM_PROMPTSfrom prompts.screenshot_system_prompts import SYSTEM_PROMPTS@@ -17,7 +18,7 @@ Generate code for a SVG that looks exactly like this.def assemble_imported_code_prompt(- code: str, stack: Stack, result_image_data_url: Union[str, None] = None+ code: str, stack: Stack, model: Llm) -> List[ChatCompletionMessageParam]:system_content = IMPORTED_CODE_SYSTEM_PROMPTS[stack]@@ -26,16 +27,25 @@ def assemble_imported_code_prompt(if stack != "svg"else "Here is the code of the SVG: " + code)- return [- {- "role": "system",- "content": system_content,- },- {- "role": "user",- "content": user_content,- },- ]++ if model == Llm.CLAUDE_3_5_SONNET_2024_06_20:+ return [+ {+ "role": "system",+ "content": system_content + "\n " + user_content,+ }+ ]+ else:+ return [+ {+ "role": "system",+ "content": system_content,+ },+ {+ "role": "user",+ "content": user_content,+ },+ ]# TODO: Use result_image_data_urldiff --git a/backend/routes/generate_code.py b/backend/routes/generate_code.pyindex 362f7425..d280830a 100644--- a/backend/routes/generate_code.py+++ b/backend/routes/generate_code.py@@ -20,6 +20,7 @@ from datetime import datetimeimport jsonfrom prompts.claude_prompts import VIDEO_PROMPTfrom prompts.types import Stack+from utils import pprint_prompt# from utils import pprint_promptfrom video.utils import extract_tag_content, assemble_claude_prompt_video@@ -166,7 +167,7 @@ async def stream_code(websocket: WebSocket):if params.get("isImportedFromCode") and params["isImportedFromCode"]:original_imported_code = params["history"][0]prompt_messages = assemble_imported_code_prompt(- original_imported_code, valid_stack+ original_imported_code, valid_stack, code_generation_model)for index, text in enumerate(params["history"][1:]):if index % 2 == 0: