Skip to content

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

Python

update model for edits and format for prompt

Abi Raja5366927ae4f0
diff --git a/backend/codegen/utils.py b/backend/codegen/utils.py
index 7bd0844a..ae46481f 100644
--- a/backend/codegen/utils.py
+++ b/backend/codegen/utils.py
@@ -1,7 +1,15 @@
import re
-def extract_html_content(text: str):
+def extract_html_content(text: str) -> str:
+ file_match = re.search(
+ r"<file\s+path=\"[^\"]+\">\s*(.*?)\s*</file>",
+ text,
+ re.DOTALL | re.IGNORECASE,
+ )
+ if file_match:
+ return extract_html_content(file_match.group(1).strip())
+
# First, strip markdown code fences if present
text = re.sub(r'^```html?\s*\n?', '', text, flags=re.MULTILINE)
text = re.sub(r'\n?```\s*$', '', text, flags=re.MULTILINE)
diff --git a/backend/prompts/message_builder.py b/backend/prompts/message_builder.py
index 986cb844..a786e2cc 100644
--- a/backend/prompts/message_builder.py
+++ b/backend/prompts/message_builder.py
@@ -7,6 +7,13 @@ from prompts.prompt_types import PromptHistoryMessage
Prompt = list[ChatCompletionMessageParam]
+def _wrap_assistant_file_content(content: str, path: str = "index.html") -> str:
+ stripped = content.strip()
+ if stripped.startswith("<file ") and stripped.endswith("</file>"):
+ return stripped
+ return f'<file path="{path}">\n{stripped}\n</file>'
+
+
def build_history_message(item: PromptHistoryMessage) -> ChatCompletionMessageParam:
role = item["role"]
image_urls = item.get("images", [])
@@ -43,6 +50,10 @@ def build_history_message(item: PromptHistoryMessage) -> ChatCompletionMessagePa
ChatCompletionMessageParam,
{
"role": role,
- "content": item.get("text", ""),
+ "content": (
+ _wrap_assistant_file_content(item.get("text", ""))
+ if role == "assistant"
+ else item.get("text", "")
+ ),
},
)
diff --git a/backend/routes/model_choice_sets.py b/backend/routes/model_choice_sets.py
index 79153e1f..7f0e2432 100644
--- a/backend/routes/model_choice_sets.py
+++ b/backend/routes/model_choice_sets.py
@@ -30,7 +30,7 @@ ALL_KEYS_MODELS_TEXT_CREATE = (
ALL_KEYS_MODELS_UPDATE = (
Llm.GEMINI_3_FLASH_PREVIEW_MINIMAL,
- Llm.GPT_5_3_CODEX_LOW,
+ Llm.GPT_5_4_2026_03_05_LOW,
)
# Key subset fallbacks.
diff --git a/backend/tests/test_codegen_utils.py b/backend/tests/test_codegen_utils.py
new file mode 100644
index 00000000..55ef12f2
--- /dev/null
+++ b/backend/tests/test_codegen_utils.py
@@ -0,0 +1,9 @@
+from codegen.utils import extract_html_content
+
+
+def test_extract_html_content_from_wrapped_file_tag() -> None:
+ text = '<file path="index.html">\n<html><body><p>Hello</p></body></html>\n</file>'
+
+ result = extract_html_content(text)
+
+ assert result == "<html><body><p>Hello</p></body></html>"
diff --git a/backend/tests/test_prompts.py b/backend/tests/test_prompts.py
index 74cdcea6..5568f700 100644
--- a/backend/tests/test_prompts.py
+++ b/backend/tests/test_prompts.py
@@ -87,6 +87,10 @@ class TestCreatePrompt:
"missing assets when needed."
)
+ @staticmethod
+ def wrapped_file(content: str) -> str:
+ return f'<file path="index.html">\n{content}\n</file>'
+
def test_plan_create_uses_create_from_input(self) -> None:
plan = derive_prompt_construction_plan(
stack=self.TEST_STACK,
@@ -238,7 +242,10 @@ class TestCreatePrompt:
"role": "system",
"content": self.MOCK_SYSTEM_PROMPT,
},
- {"role": "assistant", "content": "<html>Initial code</html>"},
+ {
+ "role": "assistant",
+ "content": self.wrapped_file("<html>Initial code</html>"),
+ },
{
"role": "user",
"content": (
@@ -247,7 +254,10 @@ class TestCreatePrompt:
"Make the background blue"
),
},
- {"role": "assistant", "content": "<html>Updated code</html>"},
+ {
+ "role": "assistant",
+ "content": self.wrapped_file("<html>Updated code</html>"),
+ },
{"role": "user", "content": "Add a header"},
],
}
@@ -365,7 +375,7 @@ class TestCreatePrompt:
},
{
"role": "assistant",
- "content": "<html>Initial dashboard</html>"
+ "content": self.wrapped_file("<html>Initial dashboard</html>")
},
{
"role": "user",
@@ -377,7 +387,9 @@ class TestCreatePrompt:
},
{
"role": "assistant",
- "content": "<html>Dashboard with sidebar</html>"
+ "content": self.wrapped_file(
+ "<html>Dashboard with sidebar</html>"
+ )
},
{
"role": "user",
@@ -496,7 +508,10 @@ class TestCreatePrompt:
"role": "system",
"content": self.MOCK_SYSTEM_PROMPT,
},
- {"role": "assistant", "content": "<html>Initial code</html>"},
+ {
+ "role": "assistant",
+ "content": self.wrapped_file("<html>Initial code</html>"),
+ },
{
"role": "user",
"content": [
@@ -517,7 +532,10 @@ class TestCreatePrompt:
},
],
},
- {"role": "assistant", "content": "<html>Code with button</html>"},
+ {
+ "role": "assistant",
+ "content": self.wrapped_file("<html>Code with button</html>"),
+ },
],
}
@@ -561,7 +579,10 @@ class TestCreatePrompt:
"role": "system",
"content": self.MOCK_SYSTEM_PROMPT,
},
- {"role": "assistant", "content": "<html>Initial code</html>"},
+ {
+ "role": "assistant",
+ "content": self.wrapped_file("<html>Initial code</html>"),
+ },
{
"role": "user",
"content": [
@@ -589,7 +610,10 @@ class TestCreatePrompt:
},
],
},
- {"role": "assistant", "content": "<html>Styled code</html>"},
+ {
+ "role": "assistant",
+ "content": self.wrapped_file("<html>Styled code</html>"),
+ },
],
}
@@ -631,7 +655,10 @@ class TestCreatePrompt:
"role": "system",
"content": self.MOCK_SYSTEM_PROMPT,
},
- {"role": "assistant", "content": "<html>Initial code</html>"},
+ {
+ "role": "assistant",
+ "content": self.wrapped_file("<html>Initial code</html>"),
+ },
{
"role": "user",
"content": (
@@ -640,7 +667,10 @@ class TestCreatePrompt:
"Make it blue"
),
}, # Text-only message
- {"role": "assistant", "content": "<html>Blue code</html>"},
+ {
+ "role": "assistant",
+ "content": self.wrapped_file("<html>Blue code</html>"),
+ },
],
}