24 lines
832 B
TypeScript
24 lines
832 B
TypeScript
import template from '../assets/workflow_vision_prompt.json'
|
|
|
|
type WorkflowNode = { class_type: string; inputs: Record<string, unknown>; _meta?: { title?: string } }
|
|
type WorkflowGraph = Record<string, WorkflowNode>
|
|
|
|
const IMAGE_NODE = '1'
|
|
const TEXT_NODE = '3'
|
|
|
|
export function buildVisionPromptWorkflow(params: {
|
|
imageName: string
|
|
draftPrompt: string
|
|
systemPrompt: string
|
|
seed?: number
|
|
}) {
|
|
const graph = structuredClone(template) as WorkflowGraph
|
|
if (graph[IMAGE_NODE]) graph[IMAGE_NODE].inputs.image = params.imageName
|
|
if (graph[TEXT_NODE]) {
|
|
graph[TEXT_NODE].inputs.system_prompt = params.systemPrompt
|
|
graph[TEXT_NODE].inputs.prompt = params.draftPrompt
|
|
graph[TEXT_NODE].inputs.seed = Number.isFinite(params.seed) ? Number(params.seed) : Math.floor(Math.random() * 2_147_483_647)
|
|
}
|
|
return graph
|
|
}
|