Skip to content

Commit e66df1d

Browse files
authored
Merge pull request #42 from devniel/comfyui-wf-utils
feat: auto convert workflow to PromptBuilder
2 parents 493ad11 + 559b26e commit e66df1d

File tree

3 files changed

+826
-38
lines changed

3 files changed

+826
-38
lines changed

packages/app/src/app/api/resolve/providers/comfyui/index.ts

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818

1919
import { getWorkflowInputValues } from '../getWorkflowInputValues'
2020
import { decodeOutput } from '@/lib/utils/decodeOutput'
21+
import { ComfyUIWorkflowApiUtils } from './utils'
2122

2223
export async function resolveSegment(
2324
request: ResolveRequest
@@ -54,50 +55,21 @@ export async function resolveSegment(
5455
request.settings.imageGenerationWorkflow.data
5556
)
5657

57-
const txt2ImgPrompt = new PromptBuilder(
58-
comfyApiWorkflow,
59-
// TODO: this list should be detect/filled automatically (see line 86)
60-
[
61-
'positive',
62-
'negative',
63-
'checkpoint',
64-
'seed',
65-
'batch',
66-
'step',
67-
'cfg',
68-
'sampler',
69-
'sheduler',
70-
'width',
71-
'height',
72-
],
73-
// TODO: this list should be detect/filled automatically (see line 86)
74-
['images']
75-
)
76-
// TODO: those input sets should be detect/filled automatically (see line 86)
77-
.setInputNode('checkpoint', '4.inputs.ckpt_name')
78-
.setInputNode('seed', '3.inputs.seed')
79-
.setInputNode('batch', '5.inputs.batch_size')
80-
.setInputNode('negative', '7.inputs.text')
81-
.setInputNode('positive', '6.inputs.text')
82-
.setInputNode('cfg', '3.inputs.cfg')
83-
.setInputNode('sampler', '3.inputs.sampler_name')
84-
.setInputNode('sheduler', '3.inputs.scheduler')
85-
.setInputNode('step', '3.inputs.steps')
86-
.setInputNode('width', '5.inputs.width')
87-
.setInputNode('height', '5.inputs.height')
88-
.setOutputNode('images', '9')
58+
const txt2ImgPrompt = new ComfyUIWorkflowApiUtils(
59+
comfyApiWorkflow
60+
).createPromptBuilder()
8961

9062
const workflow = txt2ImgPrompt
9163
// TODO: this mapping should be detect/filled automatically (see line 86)
92-
.input('checkpoint', 'SDXL/realvisxlV40_v40LightningBakedvae.safetensors')
64+
.input('ckpt_name', 'SDXL/realvisxlV40_v40LightningBakedvae.safetensors')
9365
.input('seed', generateSeed())
94-
.input('step', 6)
66+
.input('steps', 6)
9567
.input('cfg', 1)
96-
.input<TSamplerName>('sampler', 'dpmpp_2m_sde_gpu')
97-
.input<TSchedulerName>('sheduler', 'sgm_uniform')
68+
.input<TSamplerName>('sampler_name', 'dpmpp_2m_sde_gpu')
69+
.input<TSchedulerName>('scheduler', 'sgm_uniform')
9870
.input('width', request.meta.width)
9971
.input('height', request.meta.height)
100-
.input('batch', 1)
72+
.input('batch_size', 1)
10173
.input('positive', request.prompts.image.positive)
10274

10375
// for the moment we only have non-working "mock" sample code,
@@ -154,7 +126,7 @@ export async function resolveSegment(
154126
throw new Error(`failed to run the pipeline (no output)`)
155127
}
156128

157-
const imagePaths = rawOutput.images?.images.map((img: any) =>
129+
const imagePaths = rawOutput.output?.images.map((img: any) =>
158130
api.getPathImage(img)
159131
)
160132

0 commit comments

Comments
 (0)