NERDDISCO commited on
Commit
2aa79c0
•
1 Parent(s): dfc29c8

feat: use constants for COMMAND and renamed the package

Browse files
package-lock.json CHANGED
The diff for this file is too large to render. See raw diff
 
package.json CHANGED
@@ -63,6 +63,7 @@
63
  "jotai": "2.0.4",
64
  "monaco-editor": "0.37.1",
65
  "monaco-themes": "0.4.4",
 
66
  "nanoid": "4.0.2",
67
  "next": "13.2.4",
68
  "openai": "^3.2.1",
@@ -75,9 +76,11 @@
75
  },
76
  "devDependencies": {
77
  "@semantic-release/git": "^10.0.1",
 
78
  "@types/node": "18.15.11",
79
  "@types/react-syntax-highlighter": "^15.5.6",
80
- "husky": "^8.0.3"
 
81
  },
82
  "engines": {
83
  "node": ">= 18"
 
63
  "jotai": "2.0.4",
64
  "monaco-editor": "0.37.1",
65
  "monaco-themes": "0.4.4",
66
+ "mousetrap": "^1.6.5",
67
  "nanoid": "4.0.2",
68
  "next": "13.2.4",
69
  "openai": "^3.2.1",
 
76
  },
77
  "devDependencies": {
78
  "@semantic-release/git": "^10.0.1",
79
+ "@types/mousetrap": "^1.6.11",
80
  "@types/node": "18.15.11",
81
  "@types/react-syntax-highlighter": "^15.5.6",
82
+ "husky": "^8.0.3",
83
+ "typescript": "5.0.4"
84
  },
85
  "engines": {
86
  "node": ">= 18"
src/constants/index.ts CHANGED
@@ -7,10 +7,16 @@ function draw(){
7
  const FPS = 60;
8
 
9
  // TODO: Add drawing logic here
10
-
11
  // NEVER stop the loop
12
  setTimeout(requestAnimationFrame(draw),1000/FPS)
13
  }
14
  draw();
15
  `.trim(),
16
  };
 
 
 
 
 
 
 
7
  const FPS = 60;
8
 
9
  // TODO: Add drawing logic here
10
+
11
  // NEVER stop the loop
12
  setTimeout(requestAnimationFrame(draw),1000/FPS)
13
  }
14
  draw();
15
  `.trim(),
16
  };
17
+
18
+ export const COMMAND_CREATE_GAME = "CREATE_GAME";
19
+ export const COMMAND_ADD_FEATURE = "ADD";
20
+ export const COMMAND_REMOVE_FEATURE = "REMOVE";
21
+ export const COMMAND_EXTEND_FEATURE = "EXTEND";
22
+ export const COMMAND_FIX_BUG = "FIX";
src/pages/index.tsx CHANGED
@@ -46,7 +46,14 @@ import MenuItem from "@mui/material/MenuItem";
46
  import { useColorScheme } from "@mui/material/styles";
47
  import { getTheme, prettify } from "@/utils";
48
  import { answersAtom, showCodeAtom } from "@/store/atoms";
49
- import { base } from "@/constants";
 
 
 
 
 
 
 
50
  import { EditTitle } from "@/components/EditTitle";
51
  import Link from "next/link";
52
  import { fontMono } from "@/lib/theme";
@@ -239,7 +246,7 @@ export default function Home() {
239
  <Box
240
  component="form"
241
  id="gpt-form"
242
- sx={{ p: 1 }}
243
  onSubmit={async event => {
244
  event.preventDefault();
245
  const formData = new FormData(event.target as HTMLFormElement);
@@ -289,22 +296,24 @@ export default function Home() {
289
  labelId="gpt-command-select-label"
290
  id="gpt-command-select"
291
  name="command"
292
- defaultValue="CREATE_GAME"
293
  label="Command"
294
  >
295
- <MenuItem value="CREATE_GAME">
296
  create game
297
  </MenuItem>
298
- <MenuItem value="ADD_FEATURE">
299
  add feature
300
  </MenuItem>
301
- <MenuItem value="REMOVE_FEATURE">
302
  remove feature
303
  </MenuItem>
304
- <MenuItem value="UPDATE_FEATURE">
305
  update feature
306
  </MenuItem>
307
- <MenuItem value="FIX_BUG">fix bug</MenuItem>
 
 
308
  </Select>
309
  </FormControl>
310
 
@@ -356,6 +365,17 @@ export default function Home() {
356
  }
357
  onClick={setPrompt}
358
  />
 
 
 
 
 
 
 
 
 
 
 
359
  </Stack>
360
  </Stack>
361
  </Paper>
@@ -387,18 +407,6 @@ export default function Home() {
387
  style: fontMono.style,
388
  }}
389
  />
390
- <TextField
391
- multiline
392
- fullWidth
393
- id="negativePrompt"
394
- name="negativePrompt"
395
- label="Negative Prompt"
396
- placeholder="images, audio files"
397
- maxRows={6}
398
- InputProps={{
399
- style: fontMono.style,
400
- }}
401
- />
402
  <FormControl
403
  fullWidth
404
  variant="outlined"
@@ -453,7 +461,7 @@ export default function Home() {
453
  id="maxTokens"
454
  name="maxTokens"
455
  min={1024}
456
- max={8000}
457
  defaultValue={2048}
458
  step={256}
459
  valueLabelDisplay="auto"
 
46
  import { useColorScheme } from "@mui/material/styles";
47
  import { getTheme, prettify } from "@/utils";
48
  import { answersAtom, showCodeAtom } from "@/store/atoms";
49
+ import {
50
+ COMMAND_ADD_FEATURE,
51
+ COMMAND_CREATE_GAME,
52
+ COMMAND_EXTEND_FEATURE,
53
+ COMMAND_FIX_BUG,
54
+ COMMAND_REMOVE_FEATURE,
55
+ base,
56
+ } from "@/constants";
57
  import { EditTitle } from "@/components/EditTitle";
58
  import Link from "next/link";
59
  import { fontMono } from "@/lib/theme";
 
246
  <Box
247
  component="form"
248
  id="gpt-form"
249
+ sx={{ p: 1, pt: 0 }}
250
  onSubmit={async event => {
251
  event.preventDefault();
252
  const formData = new FormData(event.target as HTMLFormElement);
 
296
  labelId="gpt-command-select-label"
297
  id="gpt-command-select"
298
  name="command"
299
+ defaultValue={COMMAND_CREATE_GAME}
300
  label="Command"
301
  >
302
+ <MenuItem value={COMMAND_CREATE_GAME}>
303
  create game
304
  </MenuItem>
305
+ <MenuItem value={COMMAND_ADD_FEATURE}>
306
  add feature
307
  </MenuItem>
308
+ <MenuItem value={COMMAND_REMOVE_FEATURE}>
309
  remove feature
310
  </MenuItem>
311
+ <MenuItem value={COMMAND_EXTEND_FEATURE}>
312
  update feature
313
  </MenuItem>
314
+ <MenuItem value={COMMAND_FIX_BUG}>
315
+ fix bug
316
+ </MenuItem>
317
  </Select>
318
  </FormControl>
319
 
 
365
  }
366
  onClick={setPrompt}
367
  />
368
+
369
+ <ExampleButton
370
+ title="Asteroids"
371
+ text={
372
+ "Asteroids. Control spaceship-movement using arrow keys. Fire bullets with space key to destroy asteroids, breaking them into smaller pieces. Earn points for destroying asteroids, with higher scores for smaller ones. Collision detection when spaceship hits asteroid, collision reduces spaceship health, game over when health is 0."
373
+ }
374
+ // text={
375
+ // "Asteroids. Space ship can fly around in space using the arrow keys. Irregular shaped objects called asteroids flying around the space ship. The space ship can shoot bullets using the space key. When a bullet hits an asteroid, it splits in smaller irregular shaped objects; when asteroid is completely destroyed, the player scores one point. When the space ship collides with an asteroid, it looses 1 health; when the health is 0, the game is over. Restart the game via pressing space key."
376
+ // }
377
+ onClick={setPrompt}
378
+ />
379
  </Stack>
380
  </Stack>
381
  </Paper>
 
407
  style: fontMono.style,
408
  }}
409
  />
 
 
 
 
 
 
 
 
 
 
 
 
410
  <FormControl
411
  fullWidth
412
  variant="outlined"
 
461
  id="maxTokens"
462
  name="maxTokens"
463
  min={1024}
464
+ max={4096}
465
  defaultValue={2048}
466
  step={256}
467
  valueLabelDisplay="auto"
src/pages/live.tsx CHANGED
@@ -1,5 +1,6 @@
1
  import Script from "next/script";
2
  import TWEEN from "@tweenjs/tween.js";
 
3
 
4
  const styles = (
5
  <style>
 
1
  import Script from "next/script";
2
  import TWEEN from "@tweenjs/tween.js";
3
+ import Mousetrap from "mousetrap";
4
 
5
  const styles = (
6
  <style>
src/services/api/index.ts CHANGED
@@ -2,17 +2,22 @@ import { ChatCompletionRequestMessage } from "openai";
2
  import { nanoid } from "nanoid";
3
  import { openai } from "@/services/api/openai";
4
  import { extractCode, miniPrompt } from "@/utils/prompt";
 
 
 
 
 
 
 
5
 
6
  export async function toOpenAI({
7
  command = "CREATE_GAME",
8
  prompt = "extend the code",
9
- negativePrompt = "",
10
  temperature = "0.2",
11
  template = "",
12
  model = "gpt-3.5-turbo",
13
  maxTokens = "2048",
14
  }) {
15
- const negativePrompt_ = negativePrompt.trim();
16
  const prompt_ = prompt.trim();
17
 
18
  const nextMessage: ChatCompletionRequestMessage = {
@@ -26,47 +31,37 @@ export async function toOpenAI({
26
  `,
27
  };
28
 
29
- const task = `${prompt_}${negativePrompt_ ? ` | not(${negativePrompt_})` : ""}`;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  try {
32
  const response = await openai.createChatCompletion({
33
  model,
 
34
  max_tokens: Number.parseInt(maxTokens),
35
  temperature: Number.parseFloat(temperature),
36
- messages: [
37
- {
38
- role: "system",
39
- content: miniPrompt`
40
- You are a skilled 2D game developer working with JavaScript on Canvas2D.
41
- You understand and follow a set of "COMMANDS" to build and modify games.
42
-
43
- - "CREATE_GAME": You initiate the development of a game. You consider the game type, environment, basic mechanics and extend the "TEMPLATE".
44
- - "ADD_FEATURE": You add new features to the game like power-ups, enemies, or levels.
45
- - "REMOVE_FEATURE": You can remove any existing feature from the game.
46
- - "UPDATE_FEATURE": You can modify an existing feature in the game, altering its behavior or properties.
47
- - "FIX_BUG": You debug and fix problems in the game, ensuring everything functions as intended.
48
-
49
- You NEVER use any (external) assets: image, base64, sprite or audio.
50
- You can use these globally available libraries without importing them: TWEEN.
51
- Never use alert! Write your message on Canvas directly.
52
- You aim for high performance.
53
- Your "OUTPUT FORMAT" must be valid JavaScript code within a markdown code block.
54
- It's crucial to follow these "COMMANDS" and "OUTPUT FORMAT" for the desired results.
55
- `,
56
- // content: miniPrompt`
57
- // You are a 2D Game developer and use JavaScript to create full games on Canvas2D.
58
- // You can choose to add highscore, levels, player life, power ups, enemies.
59
- // You NEVER add assets like images or audio, everything you use is generated.
60
- // You use space key for jumping or shooting; arrow left, bottom, right for movement
61
- // You have a keen eye for performance optimization and are highly skilled in creating interactive experiences.
62
- // When working on new features, you follow the "ADD" guidelines, and when necessary, remove or exclude elements using "REMOVE".
63
- // You also pay close attention to "TEMPLATE" code, extending or fixing it as needed.
64
- // Your "OUTPUT FORMAT" must be exclusively valid JavaScript in a markdown code block, which you achieve by using the provided "TEMPLATE".
65
- // And remember, the "ADD", "REMOVE", "TEMPLATE", and "OUTPUT FORMAT" guidelines are crucial to follow for optimal results.
66
- // `,
67
- },
68
- nextMessage,
69
- ],
70
  });
71
 
72
  const { message } = response.data.choices[0];
 
2
  import { nanoid } from "nanoid";
3
  import { openai } from "@/services/api/openai";
4
  import { extractCode, miniPrompt } from "@/utils/prompt";
5
+ import {
6
+ COMMAND_ADD_FEATURE,
7
+ COMMAND_CREATE_GAME,
8
+ COMMAND_EXTEND_FEATURE,
9
+ COMMAND_FIX_BUG,
10
+ COMMAND_REMOVE_FEATURE,
11
+ } from "@/constants";
12
 
13
  export async function toOpenAI({
14
  command = "CREATE_GAME",
15
  prompt = "extend the code",
 
16
  temperature = "0.2",
17
  template = "",
18
  model = "gpt-3.5-turbo",
19
  maxTokens = "2048",
20
  }) {
 
21
  const prompt_ = prompt.trim();
22
 
23
  const nextMessage: ChatCompletionRequestMessage = {
 
31
  `,
32
  };
33
 
34
+ const task = `${prompt_}`;
35
+
36
+ const messages: ChatCompletionRequestMessage[] = [
37
+ {
38
+ role: "system",
39
+ content: miniPrompt`
40
+ You are a skilled 2D game developer working with JavaScript on Canvas2D and aim for high performance
41
+ You understand and follow a set of "COMMANDS" to build games:
42
+
43
+ "${COMMAND_CREATE_GAME}": Initiate the development. Consider the game type, environment, basic mechanics and extend the "TEMPLATE"
44
+ "${COMMAND_ADD_FEATURE}": Add the new feature
45
+ "${COMMAND_REMOVE_FEATURE}": Remove the existing feature
46
+ "${COMMAND_EXTEND_FEATURE}": Modify an existing feature, altering its behavior or properties
47
+ "${COMMAND_FIX_BUG}": Debug and fix problems, ensuring everything functions as intended
48
+
49
+ NEVER use any external assets: image, base64, sprite or audio
50
+ You can use these libraries without importing them: TWEEN, Mousetrap
51
+ NEVER use alert! Write your message on Canvas directly
52
+ Your "OUTPUT FORMAT" must be valid JavaScript code within a markdown code block
53
+ It's crucial to follow these "COMMANDS" and "OUTPUT FORMAT" for the desired results
54
+ `,
55
+ },
56
+ nextMessage,
57
+ ];
58
 
59
  try {
60
  const response = await openai.createChatCompletion({
61
  model,
62
+ messages,
63
  max_tokens: Number.parseInt(maxTokens),
64
  temperature: Number.parseFloat(temperature),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  });
66
 
67
  const { message } = response.data.choices[0];