tctien342 / comfyui-sdk

SDK for ComfyUI
MIT License
39 stars 8 forks source link

Multi value input nodes for Prompt Builder. #7

Closed btaens closed 1 month ago

btaens commented 1 month ago

In ComfyUI, there's some nodes with a variable amount of inputs, such as Power Lora Loader from rgthree. I'm not exactly sure what a good solution for this would look like, as unfortunately these don't even take a simple object as their nodes, but a pattern of node endpoints, in the case of Power Lora, every lora you add would look something like this: 26.inputs.lora_1, 26.inputs.lora_2, 26.inputs.lora_3 et cetera, each of which takes an object with multiple properties.

      "lora_1": {
        "on": true,
        "lora": "somelora.safetensors",
        "strength": 0.8
      },
      "lora_2": {
        "on": true,
        "lora": "anotherlora.safetensors",
        "strength": 1
      },
      "lora_3": {
        "on": false,
        "lora": "athirdlora.safetensors",
        "strength": 0.6
      }

Again, not sure how to implement this with the current predefined PromptBuilder inputs if the amount of inputs we receive is also variable. Maybe some deeper level .input method that allows the setting of arbitrary values. I guess you could just set the .setInputNode for such fields at request time and create a new instance of PromptBuilder for each generation, but that would kind of make the point of PromptBuilder moot in this use case.

tctien342 commented 1 month ago

@btaens How about i put a rawInput method that bypass typing ? So we can set any key we want into the workflow

btaens commented 1 month ago

Yeah, I think something like that is probably the best that can be done for this use case.

tctien342 commented 1 month ago

I have add setRawInputNode appendRawInputNode and setRawOutputNode, this will allow string as mapping key; and every setInput and output will return clone of current PromptBuilder. Hope it can help

btaens commented 1 month ago

Hmm, while it allows setting of arbitrary node values, it still expects it to be one of the predefined parameters, so a variable amount of inputs is still an issue.

tctien342 commented 1 month ago

Hmm, while it allows setting of arbitrary node values, it still expects it to be one of the predefined parameters, so a variable amount of inputs is still an issue.

Lol, i forgot about it, let me quick fix!

btaens commented 1 month ago

Maybe a simple .rawInput function at prompting, so you can just set an arbitrary node to a value if you need it?

tctien342 commented 1 month ago

Maybe a simple .rawInput function at prompting, so you can just set an arbitrary node to a value if you need it?

I think, allow to create undefined path in input method is enough, when using with default setInputNode, typescript lint already tell the error if it not correct the path. Please try again with latest version

tctien342 commented 1 month ago

@btaens also i have put the inputRaw method so we can bind value directly into any key

btaens commented 1 month ago

The typing still expects an value, so it still throws an error with the type must be one of the defined ones, though with inputRaw now that might be the point? One other thing: .input and .inputRaw seem to return an object with the prototype of PromptBuilder,, which typescript doesn't support from what I can gather, causing not being able to chain inputs. I think it's because the typing is typeof PromptBuilder instead of just PromptBuilder<I, O, T>, modifying index.d.ts seems to confirm this as it works perfectly afterwards.

tctien342 commented 1 month ago

Thank you, i have push a fix for jsdoc and typing, can you recheck again

btaens commented 1 month ago

Yeah, works perfectly! Thanks for the quick response!