Skip to content

Commit

Permalink
fix: handle unknown id property
Browse files Browse the repository at this point in the history
  • Loading branch information
devniel committed Aug 26, 2024
1 parent 8168440 commit 48aca4f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 47 deletions.
41 changes: 18 additions & 23 deletions packages/app/src/app/api/resolve/providers/comfyui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ComfyUIWorkflowApiGraph,
createPromptBuilder,
} from './utils'
import { ClapInputValueObject } from '@aitube/clap/dist/types'

export async function resolveSegment(
request: ResolveRequest
Expand Down Expand Up @@ -72,33 +73,27 @@ export async function resolveSegment(
)
})

// Set main inputs
comfyApiWorkflowPromptBuilder
.input(
(inputValues[ClapperComfyUiInputIds.PROMPT] as any).id,
request.prompts.image.positive
)
.input(
(inputValues[ClapperComfyUiInputIds.NEGATIVE_PROMPT] as any).id,
request.prompts.image.negative
)
.input(
(inputValues[ClapperComfyUiInputIds.WIDTH] as any).id,
request.meta.width
)
.input(
(inputValues[ClapperComfyUiInputIds.HEIGHT] as any).id,
request.meta.height
)
.input(
(inputValues[ClapperComfyUiInputIds.SEED] as any).id,
generateSeed()
)
const mainInputs = [
[ClapperComfyUiInputIds.PROMPT, request.prompts.image.positive],
[ClapperComfyUiInputIds.NEGATIVE_PROMPT, request.prompts.image.negative],
[ClapperComfyUiInputIds.WIDTH, request.meta.width],
[ClapperComfyUiInputIds.HEIGHT, request.meta.height],
[ClapperComfyUiInputIds.SEED, generateSeed()],
]

mainInputs.forEach((mainInput) => {
const inputId = (inputValues[mainInput[0]] as ClapInputValueObject).id
const inputValue = mainInput[1]
if (inputId) {
comfyApiWorkflowPromptBuilder.input(inputId, inputValue)
}
})

// Set output
comfyApiWorkflowPromptBuilder.setOutputNode(
ClapperComfyUiInputIds.OUTPUT,
(inputValues[ClapperComfyUiInputIds.OUTPUT] as any).id
(inputValues[ClapperComfyUiInputIds.OUTPUT] as ClapInputValueObject)
.id as string
)

const pipeline = new CallWrapper(api, comfyApiWorkflowPromptBuilder)
Expand Down
60 changes: 36 additions & 24 deletions packages/app/src/app/api/resolve/providers/comfyui/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,30 +563,42 @@ export function getInputsFromComfyUiWorkflow(workflowString: string): {
const outputNode = workflowGraph.getOutputNode()

const inputValues = {
[ClapperComfyUiInputIds.PROMPT]: {
id: promptNodeInputs?.[0].id,
label: `${promptNodeInputs?.[0].id} (from node ${promptNodeInputs?.[0].nodeId})`,
},
[ClapperComfyUiInputIds.NEGATIVE_PROMPT]: {
id: negativePromptNodeInputs?.[0].id,
label: `${negativePromptNodeInputs?.[0].id} (from node ${negativePromptNodeInputs?.[0].nodeId})`,
},
[ClapperComfyUiInputIds.WIDTH]: {
id: widthNodeInputs?.[0].id,
label: `${widthNodeInputs?.[0].id} (from node ${widthNodeInputs?.[0].nodeId})`,
},
[ClapperComfyUiInputIds.HEIGHT]: {
id: heightNodeInputs?.[0].id,
label: `${heightNodeInputs?.[0].id} (from node ${heightNodeInputs?.[0].nodeId})`,
},
[ClapperComfyUiInputIds.SEED]: {
id: seedNodeInputs?.[0].id,
label: `${seedNodeInputs?.[0].id} (from node ${seedNodeInputs?.[0].nodeId})`,
},
[ClapperComfyUiInputIds.OUTPUT]: {
id: outputNode?.id,
label: `${outputNode?._meta?.title} (id: ${outputNode?.id})`,
},
[ClapperComfyUiInputIds.PROMPT]: promptNodeInputs?.[0]
? {
id: promptNodeInputs?.[0].id,
label: `${promptNodeInputs?.[0].id} (from node ${promptNodeInputs?.[0].nodeId})`,
}
: undefined,
[ClapperComfyUiInputIds.NEGATIVE_PROMPT]: negativePromptNodeInputs?.[0]
? {
id: negativePromptNodeInputs?.[0].id,
label: `${negativePromptNodeInputs?.[0].id} (from node ${negativePromptNodeInputs?.[0].nodeId})`,
}
: undefined,
[ClapperComfyUiInputIds.WIDTH]: widthNodeInputs?.[0]
? {
id: widthNodeInputs?.[0].id,
label: `${widthNodeInputs?.[0].id} (from node ${widthNodeInputs?.[0].nodeId})`,
}
: undefined,
[ClapperComfyUiInputIds.HEIGHT]: heightNodeInputs?.[0]
? {
id: heightNodeInputs?.[0].id,
label: `${heightNodeInputs?.[0].id} (from node ${heightNodeInputs?.[0].nodeId})`,
}
: undefined,
[ClapperComfyUiInputIds.SEED]: seedNodeInputs?.[0]
? {
id: seedNodeInputs?.[0].id,
label: `${seedNodeInputs?.[0].id} (from node ${seedNodeInputs?.[0].nodeId})`,
}
: undefined,
[ClapperComfyUiInputIds.OUTPUT]: outputNode
? {
id: outputNode?.id,
label: `${outputNode?._meta?.title} (id: ${outputNode?.id})`,
}
: undefined,
}

const inputLabels = {
Expand Down

0 comments on commit 48aca4f

Please sign in to comment.