Skip to content

Commit

Permalink
improving workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
jbilcke-hf committed Aug 10, 2024
1 parent 5c344b3 commit 505167e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 35 deletions.
45 changes: 25 additions & 20 deletions src/app/api/resolve/providers/comfy-comfyicu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
}

Expand Down
1 change: 0 additions & 1 deletion src/app/api/resolve/providers/comfy-comfyicu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ export type ComfyIcuWorkflowOutput = {
url: string
thumbnail_url: string
}

10 changes: 4 additions & 6 deletions src/app/api/resolve/providers/falai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions src/app/api/resolve/providers/getWorkflowInputValues.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
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,
}),
{} as ClapInputValues
)

const workflowValues = workflow
.inputValues as ClapInputValues
const workflowValues = workflow.inputValues as ClapInputValues

return {
workflowDefaultValues,
workflowValues
workflowValues,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from '../common/defaultValues'

export const comfyicuWorkflows: ClapWorkflow[] = [

/*
Unfortunately Comfy.icu doesn't support:
Expand Down

0 comments on commit 505167e

Please sign in to comment.