Skip to content

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

Python

Update prompt configs cleanup

Abi Rajac8464a366fe5
diff --git a/backend/prompts/__init__.py b/backend/prompts/__init__.py
index eeefe4db..0ed98cad 100644
--- a/backend/prompts/__init__.py
+++ b/backend/prompts/__init__.py
@@ -4,7 +4,6 @@ from openai.types.chat import ChatCompletionMessageParam, ChatCompletionContentP
from custom_types import InputMode
from prompts.imported_code_prompts import IMPORTED_CODE_SYSTEM_PROMPTS
from prompts.screenshot_system_prompts import SYSTEM_PROMPT
-from prompts.text_prompts import SYSTEM_PROMPTS as TEXT_SYSTEM_PROMPTS
from prompts.video_prompts import GEMINI_VIDEO_PROMPT
from prompts.types import Stack, PromptContent
@@ -190,16 +189,20 @@ def assemble_text_prompt(
stack: Stack,
) -> list[ChatCompletionMessageParam]:
- system_content = TEXT_SYSTEM_PROMPTS[stack]
-
return [
{
"role": "system",
- "content": system_content,
+ "content": SYSTEM_PROMPT,
},
{
"role": "user",
- "content": "Generate UI for " + text_prompt,
+ "content": f"""
+ - Make sure to make it look modern and sleek.
+ - Use modern, professional fonts and colors.
+ - Follow UX best practices.
+ Selected stack: {stack}.
+ Generate UI for {text_prompt}.
+ """,
},
]
diff --git a/backend/prompts/text_prompts.py b/backend/prompts/text_prompts.py
deleted file mode 100644
index fe72cc48..00000000
--- a/backend/prompts/text_prompts.py
+++ /dev/null
@@ -1,113 +0,0 @@
-from prompts.types import SystemPrompts
-
-GENERAL_INSTRUCTIONS = """
-- Make sure to make it look modern and sleek.
-- Use modern, professional fonts and colors.
-- Follow UX best practices.
-- Do not add comments in the code such as "<!-- Add other navigation links as needed -->" and "<!-- ... other news items ... -->" in place of writing the full code. WRITE THE FULL CODE.
-- For images, use placeholder images from https://placehold.co and include a detailed description of the image in the alt text so that an image generation AI can generate the image later."""
-
-LIBRARY_INSTRUCTIONS = """
-- You can use Google Fonts
-- Font Awesome for icons: <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"></link>"""
-
-FORMAT_INSTRUCTIONS = """
-Follow the tool instructions in the system prompt. Do not output raw code directly.
-"""
-
-HTML_TAILWIND_SYSTEM_PROMPT = f"""
-You are an expert Tailwind developer.
-
-{GENERAL_INSTRUCTIONS}
-
-In terms of libraries,
-
-- Use this script to include Tailwind: <script src="https://cdn.tailwindcss.com"></script>
-{LIBRARY_INSTRUCTIONS}
-
-{FORMAT_INSTRUCTIONS}
-"""
-
-HTML_CSS_SYSTEM_PROMPT = f"""
-You are an expert HTML, CSS and JS developer.
-
-{GENERAL_INSTRUCTIONS}
-
-In terms of libraries,
-{LIBRARY_INSTRUCTIONS}
-
-{FORMAT_INSTRUCTIONS}
-"""
-
-REACT_TAILWIND_SYSTEM_PROMPT = f"""
-You are an expert React/Tailwind developer.
-
-{GENERAL_INSTRUCTIONS}
-
-In terms of libraries,
-- Use these script to include React so that it can run on a standalone page:
- <script src="https://cdn.jsdelivr.net/npm/[email protected]/umd/react.development.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/[email protected]/umd/react-dom.development.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/@babel/standalone/babel.js"></script>
-- Use this script to include Tailwind: <script src="https://cdn.tailwindcss.com"></script>
-{LIBRARY_INSTRUCTIONS}
-
-{FORMAT_INSTRUCTIONS}
-"""
-
-BOOTSTRAP_SYSTEM_PROMPT = f"""
-You are an expert Bootstrap, HTML and JS developer.
-
-{GENERAL_INSTRUCTIONS}
-
-In terms of libraries,
-- Use this script to include Bootstrap: <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
-{LIBRARY_INSTRUCTIONS}
-
-{FORMAT_INSTRUCTIONS}
-"""
-
-IONIC_TAILWIND_SYSTEM_PROMPT = f"""
-You are an expert Ionic/Tailwind developer.
-
-{GENERAL_INSTRUCTIONS}
-
-In terms of libraries,
-- Use these script to include Ionic so that it can run on a standalone page:
- <script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core/dist/ionic/ionic.esm.js"></script>
- <script nomodule src="https://cdn.jsdelivr.net/npm/@ionic/core/dist/ionic/ionic.js"></script>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core/css/ionic.bundle.css" />
-- Use this script to include Tailwind: <script src="https://cdn.tailwindcss.com"></script>
-- You can use Google Fonts
-- ionicons for icons, add the following <script > tags near the end of the page, right before the closing </body> tag:
- <script type="module">
- import ionicons from 'https://cdn.jsdelivr.net/npm/ionicons/+esm'
- </script>
- <script nomodule src="https://cdn.jsdelivr.net/npm/ionicons/dist/esm/ionicons.min.js"></script>
- <link href="https://cdn.jsdelivr.net/npm/ionicons/dist/collection/components/icon/icon.min.css" rel="stylesheet">
-
-{FORMAT_INSTRUCTIONS}
-"""
-
-VUE_TAILWIND_SYSTEM_PROMPT = f"""
-You are an expert Vue/Tailwind developer.
-
-{GENERAL_INSTRUCTIONS}
-
-In terms of libraries,
-- Use these script to include Vue so that it can run on a standalone page:
- <script src="https://registry.npmmirror.com/vue/3.3.11/files/dist/vue.global.js"></script>
-- Use this script to include Tailwind: <script src="https://cdn.tailwindcss.com"></script>
-{LIBRARY_INSTRUCTIONS}
-
-{FORMAT_INSTRUCTIONS}
-"""
-
-SYSTEM_PROMPTS = SystemPrompts(
- html_css=HTML_CSS_SYSTEM_PROMPT,
- html_tailwind=HTML_TAILWIND_SYSTEM_PROMPT,
- react_tailwind=REACT_TAILWIND_SYSTEM_PROMPT,
- bootstrap=BOOTSTRAP_SYSTEM_PROMPT,
- ionic_tailwind=IONIC_TAILWIND_SYSTEM_PROMPT,
- vue_tailwind=VUE_TAILWIND_SYSTEM_PROMPT,
-)
diff --git a/backend/tests/test_prompts.py b/backend/tests/test_prompts.py
index a889bed5..b0993045 100644
--- a/backend/tests/test_prompts.py
+++ b/backend/tests/test_prompts.py
@@ -199,13 +199,7 @@ class TestCreatePrompt:
},
"generationType": "create"
}
-
- # Mock the text system prompts
- mock_text_system_prompts: Dict[str, str] = {
- self.TEST_STACK: "Mock Text System Prompt"
- }
-
- with patch('prompts.TEXT_SYSTEM_PROMPTS', mock_text_system_prompts):
+ with patch('prompts.SYSTEM_PROMPT', self.MOCK_SYSTEM_PROMPT):
# Call the function
messages = await create_prompt(
stack=self.TEST_STACK,
@@ -221,7 +215,7 @@ class TestCreatePrompt:
"messages": [
{
"role": "system",
- "content": "Mock Text System Prompt"
+ "content": self.MOCK_SYSTEM_PROMPT
},
{
"role": "user",
@@ -252,13 +246,7 @@ class TestCreatePrompt:
{"text": "Now add a navigation menu"} # User's new request
]
}
-
- # Mock the text system prompts and image cache function
- mock_text_system_prompts: Dict[str, str] = {
- self.TEST_STACK: "Mock Text System Prompt"
- }
-
- with patch('prompts.TEXT_SYSTEM_PROMPTS', mock_text_system_prompts):
+ with patch('prompts.SYSTEM_PROMPT', self.MOCK_SYSTEM_PROMPT):
# Call the function
messages = await create_prompt(
stack=self.TEST_STACK,
@@ -274,7 +262,7 @@ class TestCreatePrompt:
"messages": [
{
"role": "system",
- "content": "Mock Text System Prompt"
+ "content": self.MOCK_SYSTEM_PROMPT
},
{
"role": "user",