Skip to content

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

Python

Refine prompt policies for image gen

Abi Raja41092a73a6f1
diff --git a/backend/prompts/create/image.py b/backend/prompts/create/image.py
index 0bed6900..12aad9b2 100644
--- a/backend/prompts/create/image.py
+++ b/backend/prompts/create/image.py
@@ -2,7 +2,7 @@ from openai.types.chat import ChatCompletionContentPartParam, ChatCompletionMess
from prompts.prompt_types import Stack
from prompts import system_prompt
-from prompts.policies import build_user_image_policy
+from prompts.policies import build_selected_stack_policy, build_user_image_policy
def build_image_prompt_messages(
image_data_urls: list[str],
@@ -11,10 +11,11 @@ def build_image_prompt_messages(
image_generation_enabled: bool,
) -> list[ChatCompletionMessageParam]:
image_policy = build_user_image_policy(image_generation_enabled)
+ selected_stack = build_selected_stack_policy(stack)
user_prompt = f"""
Generate code for a web page that looks exactly like the provided screenshot(s).
-Selected stack: {stack}
+{selected_stack}
## Replication instructions
diff --git a/backend/prompts/create/text.py b/backend/prompts/create/text.py
index 419e49c6..0dce5913 100644
--- a/backend/prompts/create/text.py
+++ b/backend/prompts/create/text.py
@@ -2,7 +2,7 @@ from openai.types.chat import ChatCompletionMessageParam
from prompts.prompt_types import Stack
from prompts import system_prompt
-from prompts.policies import build_user_image_policy
+from prompts.policies import build_selected_stack_policy, build_user_image_policy
def build_text_prompt_messages(
@@ -11,10 +11,11 @@ def build_text_prompt_messages(
image_generation_enabled: bool,
) -> list[ChatCompletionMessageParam]:
image_policy = build_user_image_policy(image_generation_enabled)
+ selected_stack = build_selected_stack_policy(stack)
USER_PROMPT = f"""
Generate UI for {text_prompt}.
-Selected stack: {stack}.
+{selected_stack}
# Instructions
diff --git a/backend/prompts/create/video.py b/backend/prompts/create/video.py
index 26b4ee4e..b346f14d 100644
--- a/backend/prompts/create/video.py
+++ b/backend/prompts/create/video.py
@@ -1,7 +1,7 @@
from openai.types.chat import ChatCompletionContentPartParam, ChatCompletionMessageParam
from prompts.prompt_types import Stack
from prompts import system_prompt
-from prompts.policies import build_user_image_policy
+from prompts.policies import build_selected_stack_policy, build_user_image_policy
def build_video_prompt_messages(
@@ -11,6 +11,7 @@ def build_video_prompt_messages(
image_generation_enabled: bool,
) -> list[ChatCompletionMessageParam]:
image_policy = build_user_image_policy(image_generation_enabled)
+ selected_stack = build_selected_stack_policy(stack)
user_text = f"""
You have been given a video of a user interacting with a web app. You need to re-create the same app exactly such that the same user interactions will produce the same results in the app you build.
@@ -25,7 +26,7 @@ def build_video_prompt_messages(
Analyze this video and generate the code.
- Selected stack: {stack}.
+ {selected_stack}
"""
if text_prompt.strip():
user_text = user_text + "\n\nAdditional instructions: " + text_prompt
diff --git a/backend/prompts/policies.py b/backend/prompts/policies.py
index 2d71fe85..bc9486a0 100644
--- a/backend/prompts/policies.py
+++ b/backend/prompts/policies.py
@@ -1,3 +1,10 @@
+from prompts.prompt_types import Stack
+
+
+def build_selected_stack_policy(stack: Stack) -> str:
+ return f"Selected stack: {stack}."
+
+
def build_user_image_policy(image_generation_enabled: bool) -> str:
if image_generation_enabled:
return (
diff --git a/backend/prompts/update/from_file_snapshot.py b/backend/prompts/update/from_file_snapshot.py
index 276c437c..0ad931ee 100644
--- a/backend/prompts/update/from_file_snapshot.py
+++ b/backend/prompts/update/from_file_snapshot.py
@@ -3,7 +3,7 @@ from typing import cast
from openai.types.chat import ChatCompletionMessageParam
from prompts import system_prompt
-from prompts.policies import build_user_image_policy
+from prompts.policies import build_selected_stack_policy, build_user_image_policy
from prompts.prompt_types import Stack, UserTurnInput
from prompts.message_builder import Prompt, build_history_message
@@ -16,8 +16,9 @@ def build_update_prompt_from_file_snapshot(
) -> Prompt:
path = file_state.get("path", "index.html")
request_text = prompt.get("text", "").strip() or "Apply the requested update."
+ selected_stack = build_selected_stack_policy(stack)
image_policy = build_user_image_policy(image_generation_enabled)
- bootstrap_text = f"""Selected stack: {stack}.
+ bootstrap_text = f"""{selected_stack}
{image_policy}
diff --git a/backend/prompts/update/from_history.py b/backend/prompts/update/from_history.py
index 8329989d..4fab1129 100644
--- a/backend/prompts/update/from_history.py
+++ b/backend/prompts/update/from_history.py
@@ -3,7 +3,7 @@ from typing import cast
from openai.types.chat import ChatCompletionMessageParam
from prompts import system_prompt
-from prompts.policies import build_user_image_policy
+from prompts.policies import build_selected_stack_policy, build_user_image_policy
from prompts.prompt_types import PromptHistoryMessage, Stack
from prompts.message_builder import Prompt, build_history_message
@@ -29,10 +29,11 @@ def build_update_prompt_from_history(
},
)
]
+ selected_stack = build_selected_stack_policy(stack)
image_policy = build_user_image_policy(image_generation_enabled)
for index, item in enumerate(history):
if index == first_user_index:
- stack_prefix = f"""Selected stack: {stack}.
+ stack_prefix = f"""{selected_stack}
{image_policy}"""
user_text = item.get("text", "")