Spaces:
Runtime error
Runtime error
Gregor Adams
commited on
feat: better prompt (#3)
Browse files- public/assets/rick-sanchez.png +0 -0
- src/pages/index.tsx +1 -1
- src/services/api/index.ts +26 -20
public/assets/rick-sanchez.png
DELETED
|
Binary file (162 kB)
|
|
|
src/pages/index.tsx
CHANGED
|
@@ -187,7 +187,7 @@ export default function Home() {
|
|
| 187 |
Run
|
| 188 |
</Button>
|
| 189 |
<Typography sx={{ flex: 1, pl: 1 }}>
|
| 190 |
-
{current?.task} -
|
| 191 |
</Typography>
|
| 192 |
<IconButton
|
| 193 |
edge="end"
|
|
|
|
| 187 |
Run
|
| 188 |
</Button>
|
| 189 |
<Typography sx={{ flex: 1, pl: 1 }}>
|
| 190 |
+
{current?.task} - {current?.id ?? ""}
|
| 191 |
</Typography>
|
| 192 |
<IconButton
|
| 193 |
edge="end"
|
src/services/api/index.ts
CHANGED
|
@@ -40,10 +40,15 @@ export async function toOpenAI({
|
|
| 40 |
content: miniPrompt`
|
| 41 |
ADD: ${prompt_}
|
| 42 |
${negativePrompt_ ? `REMOVE: ${negativePrompt_}` : ""}
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
| 46 |
};
|
|
|
|
|
|
|
|
|
|
| 47 |
const task = `${prompt_}${negativePrompt_ ? ` | not(${negativePrompt_})` : ""}`;
|
| 48 |
|
| 49 |
try {
|
|
@@ -54,21 +59,14 @@ export async function toOpenAI({
|
|
| 54 |
{
|
| 55 |
role: "system",
|
| 56 |
content: miniPrompt`
|
| 57 |
-
|
| 58 |
-
You
|
| 59 |
-
You
|
| 60 |
-
|
| 61 |
-
You
|
| 62 |
-
|
| 63 |
-
You NEVER add KEYWORDS to the OUTPUT
|
| 64 |
-
|
| 65 |
-
DOCS:
|
| 66 |
-
"ADD" is a set of features that You write code for
|
| 67 |
-
"REMOVE" is a set of things that should be removed or changed to something else
|
| 68 |
-
"INPUT" is the code that should be EXTENDED, ADJUSTED or FIXED
|
| 69 |
-
"OUTPUT FORMAT" is always pure valid JavaScript. the output should always be just JavaScript and NOTHING ELSE
|
| 70 |
|
| 71 |
-
|
| 72 |
`,
|
| 73 |
},
|
| 74 |
nextMessage,
|
|
@@ -79,9 +77,17 @@ You EXCLUSIVELY answer in the requested "OUTPUT FORMAT" and NOTHING ELSE
|
|
| 79 |
const { message } = response.data.choices[0];
|
| 80 |
|
| 81 |
if (message) {
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
return {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
}
|
| 86 |
|
| 87 |
// Something broke
|
|
|
|
| 40 |
content: miniPrompt`
|
| 41 |
ADD: ${prompt_}
|
| 42 |
${negativePrompt_ ? `REMOVE: ${negativePrompt_}` : ""}
|
| 43 |
+
TEMPLATE:
|
| 44 |
+
\`\`\`js
|
| 45 |
+
${template.trim().replace(/^\s+/gm, "").replace(/^\n+/g, "").replace(/\s+/, " ")}
|
| 46 |
+
\`\`\`
|
| 47 |
+
`,
|
| 48 |
};
|
| 49 |
+
console.log("<<< INPUT Message >>>");
|
| 50 |
+
console.log(nextMessage.content);
|
| 51 |
+
|
| 52 |
const task = `${prompt_}${negativePrompt_ ? ` | not(${negativePrompt_})` : ""}`;
|
| 53 |
|
| 54 |
try {
|
|
|
|
| 59 |
{
|
| 60 |
role: "system",
|
| 61 |
content: miniPrompt`
|
| 62 |
+
You are an expert JavaScript developer with a creative mindset and a specialization in Canvas-2d.
|
| 63 |
+
You have a keen eye for performance optimization and are highly skilled in creating interactive experiences.
|
| 64 |
+
You always adhere to documentation and meticulously extend the "CHANGELOG" and code.
|
| 65 |
+
When working on new features, you follow the "ADD" guidelines, and when necessary, remove or exclude elements using "REMOVE".
|
| 66 |
+
You also pay close attention to "TEMPLATE" code, extending or fixing it as needed.
|
| 67 |
+
Your "OUTPUT FORMAT" must be exclusively valid JavaScript in a markdown code block, which you achieve by using the provided "TEMPLATE".
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
+
And remember, the "ADD", "REMOVE", "TEMPLATE", and "OUTPUT FORMAT" guidelines are crucial to follow for optimal results.
|
| 70 |
`,
|
| 71 |
},
|
| 72 |
nextMessage,
|
|
|
|
| 77 |
const { message } = response.data.choices[0];
|
| 78 |
|
| 79 |
if (message) {
|
| 80 |
+
console.log("<<< OUTPUT Message >>>");
|
| 81 |
+
console.log(message.content);
|
| 82 |
+
return {
|
| 83 |
+
...message,
|
| 84 |
+
content: extractCode(message.content).replace(
|
| 85 |
+
/(ADD|TEMPLATE|OUTPUT FORMAT|REMOVE).*\n/,
|
| 86 |
+
""
|
| 87 |
+
),
|
| 88 |
+
task,
|
| 89 |
+
id: nanoid(),
|
| 90 |
+
};
|
| 91 |
}
|
| 92 |
|
| 93 |
// Something broke
|