Spaces:
Runtime error
Runtime error
File size: 2,464 Bytes
f0dc1c3 ab75c71 f0dc1c3 ab75c71 b1ecc22 f0dc1c3 b1ecc22 ab75c71 b1ecc22 f0dc1c3 e62f50c f0dc1c3 e66b0b0 f0dc1c3 e62f50c f0dc1c3 a44c1b5 f0dc1c3 a44c1b5 f0dc1c3 e62f50c f0dc1c3 |
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 |
import { Game } from "@/app/games/types"
import { createLlamaPrompt } from "@/lib/createLlamaPrompt"
import { getBase } from "./getBase"
import { predict } from "./predict"
export const getBackground = async ({
game,
situation = "",
lastEvent = "",
newActionnables = [],
}: {
game: Game;
situation: string;
lastEvent: string;
newActionnables: string[],
}) => {
const {
currentPrompt,
initialPrompt,
userSituationPrompt
} = getBase({
game,
situation,
lastEvent
})
const basePrompt = initialPrompt !== currentPrompt
? `You must imagine a very short caption for a background photo image, based on current and past situation.
Here is the original scene in which the user was located at first, which will inform you about the general game mood to follow (you must respect this): "${initialPrompt}".`
: ""
const prompt = createLlamaPrompt([
{
role: "system",
content: [
`You are a photo director.`,
basePrompt,
`You are going to receive new information about the current activity of the player.`,
`Please write in a single sentence a photo caption for the next plausible scene, using a few words for each of those categories: the environment, era, characters, objects, textures, lighting.`,
`Separate each of those category descriptions using a comma.`,
`You MUST mention the following important objects that the user can click on: ${newActionnables}.`,
`Be brief in your caption don't add your own comments. Be straight to the point, and never reply things like "As the player approaches.." or "As the player clicks.." or "the scene shifts to.." (the best is not not mention the player at all)`
].filter(item => item).join("\n")
},
{
role: "user",
content: userSituationPrompt
}
])
let result = ""
try {
result = await predict(prompt)
if (!result.trim().length) {
throw new Error("empty result!")
}
} catch (err) {
console.log(`prediction of the background failed, trying again..`)
try {
result = await predict(prompt+".")
if (!result.trim().length) {
throw new Error("empty result!")
}
} catch (err) {
console.error(`prediction of the background failed again!`)
throw new Error(`failed to generate the background ${err}`)
}
}
const tmp = result.split("Caption:").pop() || result
return tmp.replaceAll("\n", ", ")
} |