Spaces:
Running
Running
osanseviero
commited on
Commit
•
d81b9c1
1
Parent(s):
a94c081
Upload 10 files
Browse files- app/(main)/page.tsx +1 -18
- app/api/generateCode/route.ts +3 -35
app/(main)/page.tsx
CHANGED
@@ -35,7 +35,6 @@ export default function Home() {
|
|
35 |
}
|
36 |
];
|
37 |
let [model, setModel] = useState(models[0].value);
|
38 |
-
let [shadcn, setShadcn] = useState(false);
|
39 |
let [modification, setModification] = useState("");
|
40 |
let [generatedCode, setGeneratedCode] = useState("");
|
41 |
let [initialAppConfig, setInitialAppConfig] = useState({
|
@@ -66,7 +65,6 @@ export default function Home() {
|
|
66 |
},
|
67 |
body: JSON.stringify({
|
68 |
model,
|
69 |
-
shadcn,
|
70 |
messages: [{ role: "user", content: prompt }],
|
71 |
}),
|
72 |
});
|
@@ -93,7 +91,7 @@ export default function Home() {
|
|
93 |
}
|
94 |
|
95 |
setMessages([{ role: "user", content: prompt }]);
|
96 |
-
setInitialAppConfig({ model
|
97 |
setStatus("created");
|
98 |
}
|
99 |
|
@@ -192,21 +190,6 @@ export default function Home() {
|
|
192 |
</Select.Portal>
|
193 |
</Select.Root>
|
194 |
</div>
|
195 |
-
|
196 |
-
<div className="flex h-full items-center justify-between gap-3 sm:justify-center">
|
197 |
-
<label className="text-gray-500 sm:text-xs" htmlFor="shadcn">
|
198 |
-
shadcn/ui:
|
199 |
-
</label>
|
200 |
-
<Switch.Root
|
201 |
-
className="group flex w-20 max-w-xs items-center rounded-2xl border-[6px] border-gray-300 bg-white p-1.5 text-sm shadow-inner transition focus-visible:outline focus-visible:outline-2 focus-visible:outline-blue-500 data-[state=checked]:bg-blue-500"
|
202 |
-
id="shadcn"
|
203 |
-
name="shadcn"
|
204 |
-
checked={shadcn}
|
205 |
-
onCheckedChange={(value) => setShadcn(value)}
|
206 |
-
>
|
207 |
-
<Switch.Thumb className="size-7 rounded-lg bg-gray-200 shadow-[0_1px_2px] shadow-gray-400 transition data-[state=checked]:translate-x-7 data-[state=checked]:bg-white data-[state=checked]:shadow-gray-600" />
|
208 |
-
</Switch.Root>
|
209 |
-
</div>
|
210 |
</div>
|
211 |
</fieldset>
|
212 |
</form>
|
|
|
35 |
}
|
36 |
];
|
37 |
let [model, setModel] = useState(models[0].value);
|
|
|
38 |
let [modification, setModification] = useState("");
|
39 |
let [generatedCode, setGeneratedCode] = useState("");
|
40 |
let [initialAppConfig, setInitialAppConfig] = useState({
|
|
|
65 |
},
|
66 |
body: JSON.stringify({
|
67 |
model,
|
|
|
68 |
messages: [{ role: "user", content: prompt }],
|
69 |
}),
|
70 |
});
|
|
|
91 |
}
|
92 |
|
93 |
setMessages([{ role: "user", content: prompt }]);
|
94 |
+
setInitialAppConfig({ model });
|
95 |
setStatus("created");
|
96 |
}
|
97 |
|
|
|
190 |
</Select.Portal>
|
191 |
</Select.Root>
|
192 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
</div>
|
194 |
</fieldset>
|
195 |
</form>
|
app/api/generateCode/route.ts
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import shadcnDocs from "@/utils/shadcn-docs";
|
2 |
import dedent from "dedent";
|
3 |
import { z } from "zod";
|
4 |
import { GoogleGenerativeAI } from "@google/generative-ai";
|
@@ -11,7 +10,6 @@ export async function POST(req: Request) {
|
|
11 |
let result = z
|
12 |
.object({
|
13 |
model: z.string(),
|
14 |
-
shadcn: z.boolean().default(false),
|
15 |
messages: z.array(
|
16 |
z.object({
|
17 |
role: z.enum(["user", "assistant"]),
|
@@ -25,8 +23,8 @@ export async function POST(req: Request) {
|
|
25 |
return new Response(result.error.message, { status: 422 });
|
26 |
}
|
27 |
|
28 |
-
let { model, messages
|
29 |
-
let systemPrompt = getSystemPrompt(
|
30 |
|
31 |
const geminiModel = genAI.getGenerativeModel({model: model});
|
32 |
|
@@ -47,7 +45,7 @@ export async function POST(req: Request) {
|
|
47 |
return new Response(readableStream);
|
48 |
}
|
49 |
|
50 |
-
function getSystemPrompt(
|
51 |
let systemPrompt =
|
52 |
`You are an expert frontend React engineer who is also a great UI/UX designer. Follow the instructions carefully, I will tip you $1 million if you do a good job:
|
53 |
|
@@ -63,36 +61,6 @@ function getSystemPrompt(shadcn: boolean) {
|
|
63 |
- For placeholder images, please use a <div className="bg-gray-200 border-2 border-dashed rounded-xl w-16 h-16" />
|
64 |
`;
|
65 |
|
66 |
-
// - The lucide-react library is also available to be imported IF NECCESARY ONLY FOR THE FOLLOWING ICONS: Heart, Shield, Clock, Users, Play, Home, Search, Menu, User, Settings, Mail, Bell, Calendar, Clock, Heart, Star, Upload, Download, Trash, Edit, Plus, Minus, Check, X, ArrowRight.
|
67 |
-
// - Here's an example of importing and using one: import { Heart } from "lucide-react"\` & \`<Heart className="" />\`.
|
68 |
-
// - PLEASE ONLY USE THE ICONS LISTED ABOVE IF AN ICON IS NEEDED IN THE USER'S REQUEST. Please DO NOT use the lucide-react library if it's not needed.
|
69 |
-
|
70 |
-
if (shadcn) {
|
71 |
-
systemPrompt += `
|
72 |
-
There are some prestyled components available for use. Please use your best judgement to use any of these components if the app calls for one.
|
73 |
-
|
74 |
-
Here are the components that are available, along with how to import them, and how to use them:
|
75 |
-
|
76 |
-
${shadcnDocs
|
77 |
-
.map(
|
78 |
-
(component) => `
|
79 |
-
<component>
|
80 |
-
<name>
|
81 |
-
${component.name}
|
82 |
-
</name>
|
83 |
-
<import-instructions>
|
84 |
-
${component.importDocs}
|
85 |
-
</import-instructions>
|
86 |
-
<usage-instructions>
|
87 |
-
${component.usageDocs}
|
88 |
-
</usage-instructions>
|
89 |
-
</component>
|
90 |
-
`,
|
91 |
-
)
|
92 |
-
.join("\n")}
|
93 |
-
`;
|
94 |
-
}
|
95 |
-
|
96 |
systemPrompt += `
|
97 |
NO OTHER LIBRARIES (e.g. zod, hookform) ARE INSTALLED OR ABLE TO BE IMPORTED.
|
98 |
`;
|
|
|
|
|
1 |
import dedent from "dedent";
|
2 |
import { z } from "zod";
|
3 |
import { GoogleGenerativeAI } from "@google/generative-ai";
|
|
|
10 |
let result = z
|
11 |
.object({
|
12 |
model: z.string(),
|
|
|
13 |
messages: z.array(
|
14 |
z.object({
|
15 |
role: z.enum(["user", "assistant"]),
|
|
|
23 |
return new Response(result.error.message, { status: 422 });
|
24 |
}
|
25 |
|
26 |
+
let { model, messages } = result.data;
|
27 |
+
let systemPrompt = getSystemPrompt();
|
28 |
|
29 |
const geminiModel = genAI.getGenerativeModel({model: model});
|
30 |
|
|
|
45 |
return new Response(readableStream);
|
46 |
}
|
47 |
|
48 |
+
function getSystemPrompt() {
|
49 |
let systemPrompt =
|
50 |
`You are an expert frontend React engineer who is also a great UI/UX designer. Follow the instructions carefully, I will tip you $1 million if you do a good job:
|
51 |
|
|
|
61 |
- For placeholder images, please use a <div className="bg-gray-200 border-2 border-dashed rounded-xl w-16 h-16" />
|
62 |
`;
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
systemPrompt += `
|
65 |
NO OTHER LIBRARIES (e.g. zod, hookform) ARE INSTALLED OR ABLE TO BE IMPORTED.
|
66 |
`;
|