Any ComfyUI workflow runs as a job, from the inputs its catalog entry declares
CI / test (push) Successful in 9m7s
CI / test (push) Successful in 9m7s
A model's catalog entry now says what its workflow takes and makes:
comfyui.inputs, each a placeholder of its name with a type (text, int,
float, bool, choice, image, mask, audio, video, file), bounds, choices
and a default; and comfyui.output, which gains video, audio and files
beside pictures and meshes. POST /v1/workflows/runs with {model, inputs}
checks a request against them before a job is written — a required input
left out, an unknown one, a number out of bounds, a song sent as a
picture, another owner's file id are each refused with what was wrong —
and the job worker replays it to a replica, where the files go into
ComfyUI's input directory, the workflow is filled and run, and the first
file of the model's output kind is the job's result. /v1/models lists
each ComfyUI model's workflow, so a client can build its form.
A PNG result carries the licence in an iTXt chunk, as a GLB does in
asset.extras. A file whose server named no type is typed by its name
before its bytes, so a WAV is audio/wav, not audio/wave.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
b43e66c95e
commit
b6bfc33ef7
20 files changed
+1660
-44
No files matched your search
@@ -590,9 +590,13 @@ type ComfyUI struct {
|
||||
// must.
|
||||
Checkpoint string `json:"checkpoint,omitempty" koanf:"checkpoint"`
|
||||
// Output is what the workflow makes: pictures (the default), asked for
|
||||
// at /v1/images/generations, or meshes, asked for as a job at
|
||||
// /v1/3d/generations from a picture.
|
||||
// at /v1/images/generations; meshes, asked for as a job at
|
||||
// /v1/3d/generations from a picture; or video, audio or files. Every
|
||||
// kind is asked for as a job at /v1/workflows/runs too.
|
||||
Output string `json:"output,omitempty" koanf:"output"`
|
||||
// Inputs are what the workflow takes from a request at
|
||||
// /v1/workflows/runs, each the placeholder of its name.
|
||||
Inputs []Input `json:"inputs,omitempty" koanf:"inputs"`
|
||||
// Nodes are custom nodes the workflow needs, put in each replica's own
|
||||
// custom_nodes at the commit named.
|
||||
Nodes []CustomNode `json:"nodes,omitempty" koanf:"nodes"`
|
||||
@@ -705,11 +709,14 @@ func (m Model) validateComfyUI() error {
|
||||
}
|
||||
}
|
||||
}
|
||||
if out := m.comfyOutput(); out != OutputPictures && out != OutputMeshes {
|
||||
return fmt.Errorf("model %q: comfyui.output %q is not pictures or meshes", m.Name, out)
|
||||
if err := validOutput(m.Name, m.comfyOutput()); err != nil {
|
||||
return err
|
||||
}
|
||||
if m.comfyOutput() == OutputMeshes && w == "" {
|
||||
return fmt.Errorf("model %q: a model that makes meshes names its workflow: no built-in makes them", m.Name)
|
||||
if out := m.comfyOutput(); out != OutputPictures && w == "" {
|
||||
return fmt.Errorf("model %q: a model that makes %s names its workflow: no built-in makes them", m.Name, out)
|
||||
}
|
||||
if err := validateInputs(m.Name, m.ComfyInputs()); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, ckpt := m.ComfyWorkflow(); ckpt == "" {
|
||||
return fmt.Errorf("model %q: its source is a set of files, so comfyui.checkpoint must name the one the workflow loads",
|
||||
@@ -1463,11 +1470,13 @@ func (e *External) validate(model string, profiles int) error {
|
||||
if err := checkWorkflow(model, e.Workflow); err != nil {
|
||||
return err
|
||||
}
|
||||
if e.Output != "" && e.Output != OutputPictures && e.Output != OutputMeshes {
|
||||
return fmt.Errorf("model %q: external output %q is not pictures or meshes", model, e.Output)
|
||||
if e.Output != "" {
|
||||
if err := validOutput(model, e.Output); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if e.Output == OutputMeshes && e.Workflow == "" {
|
||||
return fmt.Errorf("model %q: a model that makes meshes names its workflow: no built-in makes them", model)
|
||||
if e.Output != "" && e.Output != OutputPictures && e.Workflow == "" {
|
||||
return fmt.Errorf("model %q: a model that makes %s names its workflow: no built-in makes them", model, e.Output)
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("model %q: external api %q is not openai or comfyui", model, e.API)
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
package catalog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// What a ComfyUI workflow takes and what it makes, said in the catalog so a
|
||||
// model is data rather than code: a request is checked against its inputs
|
||||
// before a job is written, a client can build a form from /v1/models, and
|
||||
// the answer is picked from the files the workflow saved by its output kind.
|
||||
|
||||
// The kinds of thing a ComfyUI model makes, beside pictures and meshes.
|
||||
const (
|
||||
OutputVideo = "video"
|
||||
OutputAudio = "audio"
|
||||
// OutputFiles is whatever the workflow saves, of any type.
|
||||
OutputFiles = "files"
|
||||
)
|
||||
|
||||
// Outputs are every output kind a ComfyUI model may name.
|
||||
var Outputs = []string{OutputPictures, OutputMeshes, OutputVideo, OutputAudio, OutputFiles}
|
||||
|
||||
// The types of a workflow's input.
|
||||
const (
|
||||
InputText = "text"
|
||||
InputInt = "int"
|
||||
InputFloat = "float"
|
||||
InputBool = "bool"
|
||||
InputChoice = "choice"
|
||||
InputImage = "image"
|
||||
InputMask = "mask"
|
||||
InputAudio = "audio"
|
||||
InputVideo = "video"
|
||||
InputFile = "file"
|
||||
)
|
||||
|
||||
// InputTypes are every type an input may have.
|
||||
var InputTypes = []string{InputText, InputInt, InputFloat, InputBool, InputChoice,
|
||||
InputImage, InputMask, InputAudio, InputVideo, InputFile}
|
||||
|
||||
// Input is one thing a workflow takes from a request: the placeholder
|
||||
// {{name}} in its graph, filled with the request's inputs.name.
|
||||
type Input struct {
|
||||
// Name is the placeholder's, and the request's key.
|
||||
Name string `json:"name" koanf:"name"`
|
||||
// Type is one of text, int, float, bool, choice, image, mask, audio,
|
||||
// video, file. The last five are files, sent as base64, a data URL, or
|
||||
// the id of a file uploaded to /v1/files, and put in ComfyUI's input
|
||||
// directory; the placeholder gets the name they were given there.
|
||||
Type string `json:"type" koanf:"type"`
|
||||
// Required inputs must be in every request; the others take Default,
|
||||
// or the workflow's own {{name|default}}.
|
||||
Required bool `json:"required,omitempty" koanf:"required"`
|
||||
Default any `json:"default,omitempty" koanf:"default"`
|
||||
// Min and Max bound a number; for text, Max bounds its length.
|
||||
Min *float64 `json:"min,omitempty" koanf:"min"`
|
||||
Max *float64 `json:"max,omitempty" koanf:"max"`
|
||||
// Choices are what a choice may be.
|
||||
Choices []string `json:"choices,omitempty" koanf:"choices"`
|
||||
// MaxMB bounds a file input; zero is the type's own bound.
|
||||
MaxMB int `json:"max_mb,omitempty" koanf:"max_mb"`
|
||||
// Doc says what the input is for, to whoever fills it in.
|
||||
Doc string `json:"doc,omitempty" koanf:"doc"`
|
||||
}
|
||||
|
||||
// IsFile reports whether the input is a file put in ComfyUI's input directory.
|
||||
func (in Input) IsFile() bool {
|
||||
switch in.Type {
|
||||
case InputImage, InputMask, InputAudio, InputVideo, InputFile:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// MaxBytes is the most a file input may be.
|
||||
func (in Input) MaxBytes() int64 {
|
||||
if in.MaxMB > 0 {
|
||||
return int64(in.MaxMB) << 20
|
||||
}
|
||||
switch in.Type {
|
||||
case InputImage, InputMask:
|
||||
return 16 << 20
|
||||
case InputVideo:
|
||||
return 256 << 20
|
||||
}
|
||||
return 64 << 20
|
||||
}
|
||||
|
||||
var inputName = regexp.MustCompile(`^[a-z][a-z0-9_]{0,63}$`)
|
||||
|
||||
func (in Input) validate(model string) error {
|
||||
if !inputName.MatchString(in.Name) {
|
||||
return fmt.Errorf("model %q: input %q is not a name of lowercase letters, digits and '_'", model, in.Name)
|
||||
}
|
||||
if !slices.Contains(InputTypes, in.Type) {
|
||||
return fmt.Errorf("model %q: input %q has type %q, not one of %s", model, in.Name, in.Type, strings.Join(InputTypes, ", "))
|
||||
}
|
||||
if in.Type == InputChoice && len(in.Choices) == 0 {
|
||||
return fmt.Errorf("model %q: input %q is a choice with no choices", model, in.Name)
|
||||
}
|
||||
if in.Type != InputChoice && len(in.Choices) > 0 {
|
||||
return fmt.Errorf("model %q: input %q has choices but is not a choice", model, in.Name)
|
||||
}
|
||||
if in.Min != nil && in.Max != nil && *in.Min > *in.Max {
|
||||
return fmt.Errorf("model %q: input %q has min above max", model, in.Name)
|
||||
}
|
||||
if in.Required && in.Default != nil {
|
||||
return fmt.Errorf("model %q: input %q is required and has a default: it is one or the other", model, in.Name)
|
||||
}
|
||||
if in.IsFile() && in.Default != nil {
|
||||
return fmt.Errorf("model %q: input %q is a file and cannot have a default", model, in.Name)
|
||||
}
|
||||
if in.MaxMB < 0 {
|
||||
return fmt.Errorf("model %q: input %q has a negative max_mb", model, in.Name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ComfyOutput is what a ComfyUI model makes: pictures unless it says.
|
||||
func (m Model) ComfyOutput() string { return m.comfyOutput() }
|
||||
|
||||
// ComfyInputs are what a ComfyUI model's workflow takes from a request.
|
||||
func (m Model) ComfyInputs() []Input {
|
||||
if m.ComfyUI == nil {
|
||||
return nil
|
||||
}
|
||||
return m.ComfyUI.Inputs
|
||||
}
|
||||
|
||||
// RunsWorkflows reports whether a model answers /v1/workflows/runs: any the
|
||||
// cluster's ComfyUI or a ComfyUI outside it serves.
|
||||
func (m Model) RunsWorkflows() bool { return m.ServesComfyUI() }
|
||||
|
||||
func validOutput(model, out string) error {
|
||||
if !slices.Contains(Outputs, out) {
|
||||
return fmt.Errorf("model %q: comfyui.output %q is not one of %s", model, out, strings.Join(Outputs, ", "))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateInputs(model string, inputs []Input) error {
|
||||
seen := map[string]bool{}
|
||||
for _, in := range inputs {
|
||||
if err := in.validate(model); err != nil {
|
||||
return err
|
||||
}
|
||||
if seen[in.Name] {
|
||||
return fmt.Errorf("model %q: input %q is declared twice", model, in.Name)
|
||||
}
|
||||
seen[in.Name] = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package catalog
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAWorkflowsInputsAreCheckedWhenTheCatalogIsBuilt(t *testing.T) {
|
||||
one := 1.0
|
||||
zero := 0.0
|
||||
run := func(out string, inputs ...Input) Model {
|
||||
return comfyModel("/w/ace.safetensors", &ComfyUI{Workflow: "w.json", Output: out, Inputs: inputs})
|
||||
}
|
||||
cat, err := New([]Model{run(OutputAudio,
|
||||
Input{Name: "tags", Type: InputText, Required: true},
|
||||
Input{Name: "strength", Type: InputFloat, Min: &zero, Max: &one, Default: 0.5},
|
||||
Input{Name: "style", Type: InputChoice, Choices: []string{"pop"}},
|
||||
Input{Name: "clip", Type: InputVideo, MaxMB: 512})})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m, _ := cat.Resolve("flux")
|
||||
if !m.RunsWorkflows() || m.MakesImages() || m.MakesMeshes() || m.ComfyOutput() != OutputAudio || len(m.ComfyInputs()) != 4 {
|
||||
t.Errorf("an audio model: runs %v pictures %v meshes %v output %q", m.RunsWorkflows(), m.MakesImages(), m.MakesMeshes(), m.ComfyOutput())
|
||||
}
|
||||
if m.ComfyInputs()[3].MaxBytes() != 512<<20 || (Input{Type: InputImage}).MaxBytes() != 16<<20 {
|
||||
t.Error("a file input's bound")
|
||||
}
|
||||
for name, c := range map[string]struct {
|
||||
m Model
|
||||
want string
|
||||
}{
|
||||
"an unknown kind": {run("hologram"), "not one of pictures"},
|
||||
"video, no workflow": {comfyModel("/w/x", &ComfyUI{Output: OutputVideo}), "makes video names its workflow"},
|
||||
"a capital name": {run(OutputAudio, Input{Name: "Tags", Type: InputText}), "lowercase"},
|
||||
"an unknown type": {run(OutputAudio, Input{Name: "x", Type: "colour"}), "not one of text"},
|
||||
"a choice of nothing": {run(OutputAudio, Input{Name: "x", Type: InputChoice}), "no choices"},
|
||||
"min above max": {run(OutputAudio, Input{Name: "x", Type: InputInt, Min: &one, Max: &zero}), "min above max"},
|
||||
"required and default": {run(OutputAudio, Input{Name: "x", Type: InputInt, Required: true, Default: 3}), "one or the other"},
|
||||
"a file's default": {run(OutputAudio, Input{Name: "x", Type: InputImage, Default: "a.png"}), "cannot have a default"},
|
||||
"twice": {run(OutputAudio, Input{Name: "x", Type: InputText}, Input{Name: "x", Type: InputInt}), "declared twice"},
|
||||
} {
|
||||
if _, err := New([]Model{c.m}); err == nil || !strings.Contains(err.Error(), c.want) {
|
||||
t.Errorf("%s: %v", name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user