From 505167e1190c334fb6d37bfdeaf106e2403c4bc5 Mon Sep 17 00:00:00 2001 From: Julian Bilcke Date: Sat, 10 Aug 2024 19:11:41 +0200 Subject: [PATCH] improving workflows --- .../resolve/providers/comfy-comfyicu/index.ts | 45 ++++++++++--------- .../resolve/providers/comfy-comfyicu/types.ts | 1 - src/app/api/resolve/providers/falai/index.ts | 10 ++--- .../providers/getWorkflowInputValues.ts | 12 +++-- .../workflows/comfyicu/index.ts | 1 - 5 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/app/api/resolve/providers/comfy-comfyicu/index.ts b/src/app/api/resolve/providers/comfy-comfyicu/index.ts index 1b1f06da..217848d2 100644 --- a/src/app/api/resolve/providers/comfy-comfyicu/index.ts +++ b/src/app/api/resolve/providers/comfy-comfyicu/index.ts @@ -16,30 +16,33 @@ export async function resolveSegment( } if (request.segment.category === ClapSegmentCategory.STORYBOARD) { - - const workflowId = request.settings.imageGenerationWorkflow.id.split('://').pop() || '' + const workflowId = + request.settings.imageGenerationWorkflow.id.split('://').pop() || '' if (!workflowId) { throw new Error(`The ComfyICU workflow ID is missing`) } - const inputFields = request.settings.imageGenerationWorkflow.inputFields || [] + const inputFields = + request.settings.imageGenerationWorkflow.inputFields || [] // since this is a random "wild" workflow, it is possible // that the field name is a bit different // we try to look into the workflow input fields // to find the best match const promptFields = [ - inputFields.find(f => f.id === 'prompt'),// exactMatch, - inputFields.find(f => f.id.includes('prompt')), // similarName, - inputFields.find(f => f.type === 'string') // similarType - ].filter(x => typeof x !== 'undefined') + inputFields.find((f) => f.id === 'prompt'), // exactMatch, + inputFields.find((f) => f.id.includes('prompt')), // similarName, + inputFields.find((f) => f.type === 'string'), // similarType + ].filter((x) => typeof x !== 'undefined') const promptField = promptFields[0] if (!promptField) { - throw new Error(`this workflow doesn't seem to have a parameter called "prompt"`) + throw new Error( + `this workflow doesn't seem to have a parameter called "prompt"` + ) } - + // TODO: modify the serialized workflow payload // to inject our params: // ...getWorkflowInputValues(request.settings.imageGenerationWorkflow), @@ -51,20 +54,22 @@ export async function resolveSegment( files: {}, } - - const rawResponse = await fetch(`https://comfy.icu/api/v1/workflows/${workflowId}/runs`, { - headers: { - accept: "application/json", - "content-type": "application/json", - authorization: `Bearer ${request.settings.comfyIcuApiKey}`, - }, - body: JSON.stringify(payload), - method: "POST", - }); + const rawResponse = await fetch( + `https://comfy.icu/api/v1/workflows/${workflowId}/runs`, + { + headers: { + accept: 'application/json', + 'content-type': 'application/json', + authorization: `Bearer ${request.settings.comfyIcuApiKey}`, + }, + body: JSON.stringify(payload), + method: 'POST', + } + ) const response = await rawResponse.json() - if (response.status === "error") { + if (response.status === 'error') { throw new Error(response.message) } diff --git a/src/app/api/resolve/providers/comfy-comfyicu/types.ts b/src/app/api/resolve/providers/comfy-comfyicu/types.ts index cbf30888..6bf505a6 100644 --- a/src/app/api/resolve/providers/comfy-comfyicu/types.ts +++ b/src/app/api/resolve/providers/comfy-comfyicu/types.ts @@ -21,4 +21,3 @@ export type ComfyIcuWorkflowOutput = { url: string thumbnail_url: string } - diff --git a/src/app/api/resolve/providers/falai/index.ts b/src/app/api/resolve/providers/falai/index.ts index 72f15ef2..957d597f 100644 --- a/src/app/api/resolve/providers/falai/index.ts +++ b/src/app/api/resolve/providers/falai/index.ts @@ -50,11 +50,10 @@ export async function resolveSegment( } } - const { - workflowDefaultValues, - workflowValues - } = getWorkflowInputValues(request.settings.imageGenerationWorkflow) - + const { workflowDefaultValues, workflowValues } = getWorkflowInputValues( + request.settings.imageGenerationWorkflow + ) + // for the moment let's use FAL's predefined sizes const imageSize = request.meta.orientation === ClapMediaOrientation.SQUARE @@ -184,7 +183,6 @@ export async function resolveSegment( } else if (request.segment.category === ClapSegmentCategory.DIALOGUE) { model = request.settings.voiceGenerationWorkflow.data || '' - let voiceIdentity = request.prompts.voice.identity || // TODO for the default we should use one of our own voices instea diff --git a/src/app/api/resolve/providers/getWorkflowInputValues.ts b/src/app/api/resolve/providers/getWorkflowInputValues.ts index c579c917..2521c02d 100644 --- a/src/app/api/resolve/providers/getWorkflowInputValues.ts +++ b/src/app/api/resolve/providers/getWorkflowInputValues.ts @@ -1,11 +1,10 @@ -import { ClapInputValues, ClapWorkflow } from "@aitube/clap" +import { ClapInputValues, ClapWorkflow } from '@aitube/clap' export function getWorkflowInputValues(workflow: ClapWorkflow): { workflowDefaultValues: ClapInputValues workflowValues: ClapInputValues } { - const workflowDefaultValues = - workflow.inputFields.reduce( + const workflowDefaultValues = workflow.inputFields.reduce( (acc, field) => ({ ...acc, [field.id]: field.defaultValue, @@ -13,11 +12,10 @@ export function getWorkflowInputValues(workflow: ClapWorkflow): { {} as ClapInputValues ) -const workflowValues = workflow - .inputValues as ClapInputValues + const workflowValues = workflow.inputValues as ClapInputValues return { workflowDefaultValues, - workflowValues + workflowValues, } -} \ No newline at end of file +} diff --git a/src/services/editors/workflow-editor/workflows/comfyicu/index.ts b/src/services/editors/workflow-editor/workflows/comfyicu/index.ts index 71ac0ee8..a0d1ca4a 100644 --- a/src/services/editors/workflow-editor/workflows/comfyicu/index.ts +++ b/src/services/editors/workflow-editor/workflows/comfyicu/index.ts @@ -11,7 +11,6 @@ import { } from '../common/defaultValues' export const comfyicuWorkflows: ClapWorkflow[] = [ - /* Unfortunately Comfy.icu doesn't support: