From 9bee5c79b8d41d9b193c7cc76efdd3b6d8cf54ba Mon Sep 17 00:00:00 2001 From: dialmedu Date: Tue, 28 Nov 2023 23:50:04 -0500 Subject: [PATCH 1/2] Add prompt ionic support --- backend/main.py | 4 +++- backend/prompts.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/backend/main.py b/backend/main.py index 4b75f71..b8e3f4f 100644 --- a/backend/main.py +++ b/backend/main.py @@ -70,11 +70,13 @@ async def stream_code(websocket: WebSocket): print("Received params") # Read the output settings from the request. Fall back to default if not provided. - output_settings = {"css": "tailwind", "js": "vanilla"} + output_settings = {"css": "tailwind", "js": "vanilla" , "components" : "html"} if params["outputSettings"] and params["outputSettings"]["css"]: output_settings["css"] = params["outputSettings"]["css"] if params["outputSettings"] and params["outputSettings"]["js"]: output_settings["js"] = params["outputSettings"]["js"] + if params["outputSettings"] and params["outputSettings"]["components"]: + output_settings["components"] = params["outputSettings"]["components"] print("Using output settings:", output_settings) # Get the OpenAI API key from the request. Fall back to environment variable if not provided. diff --git a/backend/prompts.py b/backend/prompts.py index f01eb7e..fe3ba9e 100644 --- a/backend/prompts.py +++ b/backend/prompts.py @@ -77,6 +77,40 @@ Return only the full code in tags. Do not include markdown "```" or "```html" at the start or end. """ +IONIC_TAILWIND_SYSTEM_PROMPT = """ +You are an expert Ionic/Tailwind developer +You take screenshots of a reference web page from the user, and then build single page apps +using Ionic and Tailwind CSS. +You might also be given a screenshot(The second image) of a web page that you have already built, and asked to +update it to look more like the reference image(The first image). + +- Make sure the app looks exactly like the screenshot. +- Pay close attention to background color, text color, font size, font family, +padding, margin, border, etc. Match the colors and sizes exactly. +- Use the exact text from the screenshot. +- Do not add comments in the code such as "" and "" in place of writing the full code. WRITE THE FULL CODE. +- Repeat elements as needed to match the screenshot. For example, if there are 15 items, the code should have 15 items. DO NOT LEAVE comments like "" or bad things will happen. +- 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. + +In terms of libraries, + +- Use these script to include Ionic so that it can run on a standalone page: + + + +- Use this script to include Tailwind: +- You can use Google Fonts +- ionicons for icons, add the following + + + +Return only the full code in tags. +Do not include markdown "```" or "```html" at the start or end. +""" + USER_PROMPT = """ Generate code for a web page that looks exactly like this. """ @@ -92,6 +126,9 @@ def assemble_prompt(image_data_url, output_settings: dict, result_image_data_url if output_settings["js"] == "react": chosen_prompt_name = "react-tailwind" system_content = REACT_TAILWIND_SYSTEM_PROMPT + if output_settings["components"] == "ionic": + chosen_prompt_name = "ionic-tailwind" + system_content = IONIC_TAILWIND_SYSTEM_PROMPT print("Using system prompt:", chosen_prompt_name) From e13840d8e97ca0a497ec3ffca88a40dbe8699d28 Mon Sep 17 00:00:00 2001 From: dialmedu Date: Tue, 28 Nov 2023 23:56:16 -0500 Subject: [PATCH 2/2] Add Ionic support and Check Options --- frontend/src/App.tsx | 2 + .../src/components/OutputSettingsSection.tsx | 106 +++++++++++++++++- frontend/src/types.ts | 6 + 3 files changed, 112 insertions(+), 2 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 5f65f96..1cc4588 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -25,6 +25,7 @@ import { CSSOption, OutputSettings, JSFrameworkOption, + UIComponentOption, } from "./types"; import { IS_RUNNING_ON_CLOUD } from "./config"; import { PicoBadge } from "./components/PicoBadge"; @@ -57,6 +58,7 @@ function App() { const [outputSettings, setOutputSettings] = useState({ css: CSSOption.TAILWIND, js: JSFrameworkOption.VANILLA, + components: UIComponentOption.HTML, }); const [shouldIncludeResultImage, setShouldIncludeResultImage] = useState(false); diff --git a/frontend/src/components/OutputSettingsSection.tsx b/frontend/src/components/OutputSettingsSection.tsx index 2d2dfa9..7f29069 100644 --- a/frontend/src/components/OutputSettingsSection.tsx +++ b/frontend/src/components/OutputSettingsSection.tsx @@ -5,7 +5,7 @@ import { SelectItem, SelectTrigger, } from "./ui/select"; -import { CSSOption, JSFrameworkOption, OutputSettings } from "../types"; +import { CSSOption, UIComponentOption, JSFrameworkOption, OutputSettings } from "../types"; import { Accordion, AccordionContent, @@ -16,6 +16,7 @@ import { capitalize } from "../lib/utils"; import toast from "react-hot-toast"; import { IS_RUNNING_ON_CLOUD } from "../config"; import { Badge } from "./ui/badge"; +import { useEffect } from "react"; function displayCSSOption(option: CSSOption) { switch (option) { @@ -61,6 +62,7 @@ function OutputSettingsSection({ outputSettings, setOutputSettings }: Props) { return { css: CSSOption.TAILWIND, js: JSFrameworkOption.REACT, + components: UIComponentOption.HTML }; } else { return { @@ -81,6 +83,7 @@ function OutputSettingsSection({ outputSettings, setOutputSettings }: Props) { setOutputSettings(() => ({ css: CSSOption.TAILWIND, js: value as JSFrameworkOption, + components: UIComponentOption.HTML })); } else { setOutputSettings((prev) => ({ @@ -90,6 +93,85 @@ function OutputSettingsSection({ outputSettings, setOutputSettings }: Props) { } }; + const onUIComponentOptionChange = (value: string) => { + if (IS_RUNNING_ON_CLOUD) { + toast.error("Upgrade to the Business plan to change Components library."); + return; + } + + if (value === UIComponentOption.IONIC) { + setOutputSettings(() => ({ + css: CSSOption.TAILWIND, + js: JSFrameworkOption.VANILLA, + components: value as UIComponentOption + })); + } else { + setOutputSettings((prev) => ({ + ...prev, + components: value as UIComponentOption, + })); + } + }; + + + const checkUIComponentOptionOrDefault = (valueItem: UIComponentOption ) : UIComponentOption => { + switch (valueItem) { + case UIComponentOption.IONIC: + if (outputSettings.js != JSFrameworkOption.VANILLA || outputSettings.css != CSSOption.TAILWIND) { + return UIComponentOption.HTML + } + } + return valueItem; + } + + const checkCSSOptionOrDefault = (valueItem: CSSOption ) : CSSOption => { + switch (valueItem) { + default: + return valueItem; + } + } + + const checkJSFrameworkOptionOrDefault = (valueItem: JSFrameworkOption ) : JSFrameworkOption => { + switch (valueItem) { + case JSFrameworkOption.REACT: + if(outputSettings.css != CSSOption.TAILWIND) { + return JSFrameworkOption.VANILLA + } + break; + } + return valueItem; + } + + useEffect(() => { + checkOutputSettingsOptions(); + }, [outputSettings]); + + const checkOutputSettingsOptions = () => { + if ( isHiddenOption(outputSettings.css) || isHiddenOption(outputSettings.js) || isHiddenOption(outputSettings.components)) + { + setOutputSettings((prev) => { + return { + css: checkCSSOptionOrDefault(prev.css), + js: checkJSFrameworkOptionOrDefault(prev.js), + components: checkUIComponentOptionOrDefault(prev.components), + }; + }) + } + }; + + const isHiddenOption = ( option : CSSOption| JSFrameworkOption | UIComponentOption ) : boolean => { + if (Object.values(CSSOption).includes(option as CSSOption)){ + return checkCSSOptionOrDefault(option as CSSOption) != option + } + if (Object.values(JSFrameworkOption).includes(option as JSFrameworkOption)){ + return checkJSFrameworkOptionOrDefault(option as JSFrameworkOption) != option + } + if (Object.values(UIComponentOption).includes(option as UIComponentOption)){ + return checkUIComponentOptionOrDefault(option as UIComponentOption) != option + } + return true + } + return ( @@ -128,11 +210,31 @@ function OutputSettingsSection({ outputSettings, setOutputSettings }: Props) { Vanilla - React + React +
+ Component Library + +
+
+ Output: {outputSettings.js} + {outputSettings.css} + {outputSettings.components} +
diff --git a/frontend/src/types.ts b/frontend/src/types.ts index 964ad5a..0963f32 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -14,9 +14,15 @@ export enum JSFrameworkOption { VUE = "vue", } +export enum UIComponentOption { + HTML = 'HTML', + IONIC = 'ionic' +} + export interface OutputSettings { css: CSSOption; js: JSFrameworkOption; + components: UIComponentOption; } export interface Settings {