Skip to content

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

Python

refactor: remove unused result_image functionality

Abi Raja774e459c2f43
diff --git a/backend/prompts/__init__.py b/backend/prompts/__init__.py
index 46cbc546..1670f15e 100644
--- a/backend/prompts/__init__.py
+++ b/backend/prompts/__init__.py
@@ -26,7 +26,6 @@ async def create_prompt(
prompt: PromptContent,
history: list[dict[str, Any]],
is_imported_from_code: bool,
- result_image: str | None,
) -> tuple[list[ChatCompletionMessageParam], dict[str, str]]:
image_cache: dict[str, str] = {}
@@ -43,19 +42,13 @@ async def create_prompt(
# Assemble the prompt for non-imported code
if input_mode == "image":
image_url = prompt["images"][0]
- if result_image:
- prompt_messages = assemble_prompt(image_url, stack, result_image)
- else:
- prompt_messages = assemble_prompt(image_url, stack)
+ prompt_messages = assemble_prompt(image_url, stack)
elif input_mode == "text":
prompt_messages = assemble_text_prompt(prompt["text"], stack)
else:
# Default to image mode for backward compatibility
image_url = prompt["images"][0]
- if result_image:
- prompt_messages = assemble_prompt(image_url, stack, result_image)
- else:
- prompt_messages = assemble_prompt(image_url, stack)
+ prompt_messages = assemble_prompt(image_url, stack)
if generation_type == "update":
# Transform the history tree into message format
@@ -137,13 +130,11 @@ def assemble_imported_code_prompt(
"content": system_content + "\n " + user_content,
}
]
- # TODO: Use result_image_data_url
def assemble_prompt(
image_data_url: str,
stack: Stack,
- result_image_data_url: Union[str, None] = None,
) -> list[ChatCompletionMessageParam]:
system_content = SYSTEM_PROMPTS[stack]
user_prompt = USER_PROMPT if stack != "svg" else SVG_USER_PROMPT
@@ -158,16 +149,6 @@ def assemble_prompt(
"text": user_prompt,
},
]
-
- # Include the result image if it exists
- if result_image_data_url:
- user_content.insert(
- 1,
- {
- "type": "image_url",
- "image_url": {"url": result_image_data_url, "detail": "high"},
- },
- )
return [
{
"role": "system",
diff --git a/backend/prompts/test_prompts.py b/backend/prompts/test_prompts.py
index dc4b6367..15344c52 100644
--- a/backend/prompts/test_prompts.py
+++ b/backend/prompts/test_prompts.py
@@ -349,45 +349,23 @@ Generate code for a SVG that looks exactly like this.
def test_prompts():
+ # Test that assemble_prompt creates the expected structure without result_image
tailwind_prompt = assemble_prompt(
- "image_data_url", "html_tailwind", "result_image_data_url"
+ "image_data_url", "html_tailwind"
)
- assert tailwind_prompt[0].get("content") == TAILWIND_SYSTEM_PROMPT
- assert tailwind_prompt[1]["content"][2]["text"] == USER_PROMPT # type: ignore
-
- html_css_prompt = assemble_prompt(
- "image_data_url", "html_css", "result_image_data_url"
- )
- assert html_css_prompt[0].get("content") == HTML_CSS_SYSTEM_PROMPT
- assert html_css_prompt[1]["content"][2]["text"] == USER_PROMPT # type: ignore
-
- react_tailwind_prompt = assemble_prompt(
- "image_data_url", "react_tailwind", "result_image_data_url"
- )
- assert react_tailwind_prompt[0].get("content") == REACT_TAILWIND_SYSTEM_PROMPT
- assert react_tailwind_prompt[1]["content"][2]["text"] == USER_PROMPT # type: ignore
-
- bootstrap_prompt = assemble_prompt(
- "image_data_url", "bootstrap", "result_image_data_url"
- )
- assert bootstrap_prompt[0].get("content") == BOOTSTRAP_SYSTEM_PROMPT
- assert bootstrap_prompt[1]["content"][2]["text"] == USER_PROMPT # type: ignore
-
- ionic_tailwind = assemble_prompt(
- "image_data_url", "ionic_tailwind", "result_image_data_url"
- )
- assert ionic_tailwind[0].get("content") == IONIC_TAILWIND_SYSTEM_PROMPT
- assert ionic_tailwind[1]["content"][2]["text"] == USER_PROMPT # type: ignore
-
- vue_tailwind = assemble_prompt(
- "image_data_url", "vue_tailwind", "result_image_data_url"
- )
- assert vue_tailwind[0].get("content") == VUE_TAILWIND_SYSTEM_PROMPT
- assert vue_tailwind[1]["content"][2]["text"] == USER_PROMPT # type: ignore
-
- svg_prompt = assemble_prompt("image_data_url", "svg", "result_image_data_url")
- assert svg_prompt[0].get("content") == SVG_SYSTEM_PROMPT
- assert svg_prompt[1]["content"][2]["text"] == SVG_USER_PROMPT # type: ignore
+ # Test basic structure
+ assert len(tailwind_prompt) == 2
+ assert tailwind_prompt[0]["role"] == "system"
+ assert "Tailwind developer" in tailwind_prompt[0]["content"]
+ assert tailwind_prompt[1]["role"] == "user"
+ assert len(tailwind_prompt[1]["content"]) == 2 # Only image + text, no result image
+ assert tailwind_prompt[1]["content"][0]["type"] == "image_url"
+ assert tailwind_prompt[1]["content"][1]["type"] == "text"
+ assert tailwind_prompt[1]["content"][1]["text"] == USER_PROMPT
+
+ # Test SVG variant
+ svg_prompt = assemble_prompt("image_data_url", "svg")
+ assert svg_prompt[1]["content"][1]["text"] == SVG_USER_PROMPT
def test_imported_code_prompts():
diff --git a/backend/routes/generate_code.py b/backend/routes/generate_code.py
index 2d3daec7..dd78a396 100644
--- a/backend/routes/generate_code.py
+++ b/backend/routes/generate_code.py
@@ -211,7 +211,6 @@ class ExtractedParams:
prompt: PromptContent
history: List[Dict[str, Any]]
is_imported_from_code: bool
- result_image: str | None
class ParameterExtractionStage:
@@ -275,9 +274,6 @@ class ParameterExtractionStage:
# Extract imported code flag
is_imported_from_code = params.get("isImportedFromCode", False)
-
- # Extract result image
- result_image = params.get("resultImage")
return ExtractedParams(
stack=validated_stack,
@@ -290,7 +286,6 @@ class ParameterExtractionStage:
prompt=prompt,
history=history,
is_imported_from_code=is_imported_from_code,
- result_image=result_image,
)
def _get_from_settings_dialog_or_env(
@@ -423,7 +418,6 @@ class PromptCreationStage:
prompt=extracted_params.prompt,
history=extracted_params.history,
is_imported_from_code=extracted_params.is_imported_from_code,
- result_image=extracted_params.result_image,
)
print_prompt_summary(prompt_messages, truncate=False)
diff --git a/backend/tests/test_prompts.py b/backend/tests/test_prompts.py
index 3af0b9f5..b1e725bf 100644
--- a/backend/tests/test_prompts.py
+++ b/backend/tests/test_prompts.py
@@ -104,7 +104,6 @@ class TestCreatePrompt:
prompt=params["prompt"],
history=params.get("history", []),
is_imported_from_code=params.get("isImportedFromCode", False),
- result_image=params.get("resultImage"),
)
# Define expected structure
@@ -135,65 +134,6 @@ class TestCreatePrompt:
actual: ExpectedResult = {"messages": messages, "image_cache": image_cache}
assert_structure_match(actual, expected)
- @pytest.mark.asyncio
- async def test_image_mode_create_with_result_image(self) -> None:
- """Test create generation with before/after images in image mode."""
- # Setup test data
- params: Dict[str, Any] = {
- "prompt": {"text": "", "images": [self.TEST_IMAGE_URL]},
- "generationType": "create",
- "resultImage": self.RESULT_IMAGE_URL,
- }
-
- # Mock the system prompts
- mock_system_prompts: Dict[str, str] = {self.TEST_STACK: self.MOCK_SYSTEM_PROMPT}
-
- with patch("prompts.SYSTEM_PROMPTS", mock_system_prompts):
- # Call the function
- messages, image_cache = await create_prompt(
- stack=self.TEST_STACK,
- input_mode="image",
- generation_type=params["generationType"],
- prompt=params["prompt"],
- history=params.get("history", []),
- is_imported_from_code=params.get("isImportedFromCode", False),
- result_image=params.get("resultImage"),
- )
-
- # Define expected structure
- expected: ExpectedResult = {
- "messages": [
- {"role": "system", "content": self.MOCK_SYSTEM_PROMPT},
- {
- "role": "user",
- "content": [
- {
- "type": "image_url",
- "image_url": {
- "url": self.TEST_IMAGE_URL,
- "detail": "high",
- },
- },
- {
- "type": "image_url",
- "image_url": {
- "url": self.RESULT_IMAGE_URL,
- "detail": "high",
- },
- },
- {
- "type": "text",
- "text": "<CONTAINS:Generate code for a web page that looks exactly like this.>",
- },
- ],
- },
- ],
- "image_cache": {},
- }
-
- # Assert the structure matches
- actual: ExpectedResult = {"messages": messages, "image_cache": image_cache}
- assert_structure_match(actual, expected)
@pytest.mark.asyncio
async def test_image_mode_update_with_history(self) -> None:
@@ -224,7 +164,6 @@ class TestCreatePrompt:
prompt=params["prompt"],
history=params.get("history", []),
is_imported_from_code=params.get("isImportedFromCode", False),
- result_image=params.get("resultImage"),
)
# Define expected structure
@@ -286,7 +225,6 @@ class TestCreatePrompt:
prompt=params["prompt"],
history=params.get("history", []),
is_imported_from_code=params.get("isImportedFromCode", False),
- result_image=params.get("resultImage"),
)
# Define expected structure
@@ -342,7 +280,6 @@ class TestCreatePrompt:
prompt=params["prompt"],
history=params.get("history", []),
is_imported_from_code=params.get("isImportedFromCode", False),
- result_image=params.get("resultImage"),
)
# Define expected structure
@@ -433,7 +370,6 @@ class TestCreatePrompt:
prompt=params["prompt"],
history=params.get("history", []),
is_imported_from_code=params.get("isImportedFromCode", False),
- result_image=params.get("resultImage"),
)
# Define expected structure
@@ -503,7 +439,6 @@ class TestCreatePrompt:
prompt=params["prompt"],
history=params.get("history", []),
is_imported_from_code=params.get("isImportedFromCode", False),
- result_image=params.get("resultImage"),
)
# Define expected structure
@@ -581,7 +516,6 @@ class TestCreatePrompt:
prompt=params["prompt"],
history=params.get("history", []),
is_imported_from_code=params.get("isImportedFromCode", False),
- result_image=params.get("resultImage"),
)
# Define expected structure
@@ -664,7 +598,6 @@ class TestCreatePrompt:
prompt=params["prompt"],
history=params.get("history", []),
is_imported_from_code=params.get("isImportedFromCode", False),
- result_image=params.get("resultImage"),
)
# Define expected structure - should be text-only messages
@@ -727,7 +660,6 @@ class TestCreatePrompt:
prompt=params.get("prompt", {"text": "", "images": []}),
history=params.get("history", []),
is_imported_from_code=params.get("isImportedFromCode", False),
- result_image=params.get("resultImage"),
)
# Define expected structure
diff --git a/backend/tests/test_prompts_additional.py b/backend/tests/test_prompts_additional.py
index 98225616..b9e9da85 100644
--- a/backend/tests/test_prompts_additional.py
+++ b/backend/tests/test_prompts_additional.py
@@ -111,7 +111,6 @@ class TestCreatePromptImageSupport:
prompt=params["prompt"],
history=params.get("history", []),
is_imported_from_code=params.get("isImportedFromCode", False),
- result_image=params.get("resultImage"),
)
# Define expected structure
@@ -194,7 +193,6 @@ class TestCreatePromptImageSupport:
prompt=params["prompt"],
history=params.get("history", []),
is_imported_from_code=params.get("isImportedFromCode", False),
- result_image=params.get("resultImage"),
)
# Define expected structure - should be text-only messages
@@ -257,7 +255,6 @@ class TestCreatePromptImageSupport:
prompt=params.get("prompt", {"text": "", "images": []}),
history=params.get("history", []),
is_imported_from_code=params.get("isImportedFromCode", False),
- result_image=params.get("resultImage"),
)
# Define expected structure