Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 1,772 Bytes
624088c |
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 |
import { createLlamaPrompt } from "@/lib/createLlamaPrompt"
import { predict } from "./predict"
import { Preset } from "../engine/presets"
export const getBackground = async ({
preset,
storyPrompt = "",
previousPanelPrompt = "",
newPanelPrompt = "",
}: {
preset: Preset;
storyPrompt: string;
previousPanelPrompt: string;
newPanelPrompt: string;
}) => {
const prompt = createLlamaPrompt([
{
role: "system",
content: [
`You are a comic book author for a ${preset.llmPrompt}`,
`Please write in a single sentence a photo caption for the next plausible page, 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.`,
`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: storyPrompt
}
])
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", ", ")
} |