|
import { Preset } from "../engine/presets" |
|
import { GeneratedPanel } from "@/types" |
|
import { predictNextPanels } from "./predictNextPanels" |
|
import { joinWords } from "@/lib/joinWords" |
|
|
|
export const getStoryContinuation = async ({ |
|
preset, |
|
stylePrompt = "", |
|
userStoryPrompt = "", |
|
nbPanelsToGenerate = 2, |
|
nbTotalPanels = 4, |
|
existingPanels = [], |
|
}: { |
|
preset: Preset; |
|
stylePrompt?: string; |
|
userStoryPrompt?: string; |
|
nbPanelsToGenerate?: number; |
|
nbTotalPanels?: number; |
|
existingPanels?: GeneratedPanel[]; |
|
}): Promise<GeneratedPanel[]> => { |
|
|
|
let panels: GeneratedPanel[] = [] |
|
const startAt: number = (existingPanels.length + 1) || 0 |
|
const endAt: number = startAt + nbPanelsToGenerate |
|
|
|
try { |
|
|
|
const prompt = joinWords([ userStoryPrompt ]) |
|
|
|
const panelCandidates: GeneratedPanel[] = await predictNextPanels({ |
|
preset, |
|
prompt, |
|
nbPanelsToGenerate, |
|
nbTotalPanels, |
|
existingPanels, |
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < nbPanelsToGenerate; i++) { |
|
panels.push({ |
|
panel: startAt + i, |
|
instructions: `${panelCandidates[i]?.instructions || ""}`, |
|
caption: `${panelCandidates[i]?.caption || ""}`, |
|
}) |
|
} |
|
|
|
} catch (err) { |
|
|
|
|
|
panels = [] |
|
for (let p = startAt; p < endAt && p; p++) { |
|
panels.push({ |
|
panel: p, |
|
instructions: joinWords([ |
|
stylePrompt, |
|
userStoryPrompt, |
|
`${".".repeat(p)}`, |
|
]), |
|
caption: "(Sorry, LLM generation failed: using degraded mode)" |
|
}) |
|
} |
|
|
|
} finally { |
|
return panels |
|
} |
|
} |
|
|