File size: 2,653 Bytes
ab75c71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44b9fb1
ab75c71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44b9fb1
ab75c71
 
 
44b9fb1
ab75c71
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { Game } from "@/app/games/types"
import { createLlamaPrompt } from "@/lib/createLlamaPrompt"

import { getBase } from "./getBase"
import { predict } from "./predict"


export const getSound = async ({
  game,
  situation = "",
  lastEvent = "",
}: {
  game: Game;
  situation: string;
  lastEvent: string;
}) => {

  const { currentPrompt, initialPrompt, userSituationPrompt } = getBase({ game, situation, lastEvent })

  console.log("DEBUG", {
    game, situation, lastEvent,
    currentPrompt,
    initialPrompt,
    userSituationPrompt,

  })
  /*
      const basePrompt = initialPrompt !== currentPrompt
  ? `for your information, the initial game panel and scene was: ${initialPrompt}`
  : ""
  */

  const basePrompt = initialPrompt !== currentPrompt
    ? `Here is the original scene in which the user was located at first, which will inform you about the general settings to follow (you must respect this): "${initialPrompt}".`
    : ""

  const prompt = createLlamaPrompt([
    {
      role: "system",
      content: [
        `You are the AI game master of a role video game.`,
        `You are going to receive new information about the current whereabouts and action of the player.`,
        basePrompt,
        `You must imagine a sound effect in reaction to the player action.`,
        `Here are some examples, but don't copy them verbatim:\n`,
        `- "An excited crowd cheering at a sports game"\n`,
        `- "A wooden door opens"\n`,
        `- "A cat is meowing for attention"\n`,
        `- "Birds singing sweetly in a blooming garden"\n`,
        `- "A modern synthesizer creating futuristic soundscapes"\n`,
        `- "The vibrant beat of Brazilian samba drums"\n`,
        `Here are some more instructions, to enhance the Qqality of your generated audio:`,
        `1. Try to use more adjectives to describe your sound. For example: "A man is speaking clearly and slowly in a large room" is better than "A man is speaking".\n`,
        `2. It's better to use general terms like 'man' or 'woman' instead of specific names for individuals or abstract objects that humans may not be familiar with, such as 'mummy'.\n`
      ].filter(item => item).join("\n")
    },
    {
      role: "user",
      content: userSituationPrompt
    }
  ])


  let result = ""
  try {
    result = await predict(prompt)
  } catch (err) {
    console.log(`prediction of the sound prompt failed, trying again..`)
    try {
      result = await predict(prompt)
    } catch (err) {
      console.error(`prediction of the sound prompt failed again!`)
      throw new Error(`failed to generate the dialogue ${err}`)
    }
  }

  return result
}