comfyanonymous / ComfyUI

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface.
https://www.comfy.org/
GNU General Public License v3.0
51k stars 5.35k forks source link

How to create a custom node that returns a sampler ? #2234

Open dchatel opened 9 months ago

dchatel commented 9 months ago

Here is what I have right now:

class BasicParameters:
    @classmethod
    def INPUT_TYPES(cls):
        return {
            "required": {
                "sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
                "scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
                "steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
                "hires_steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
                "cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "step":0.1, "round": 0.01}),
            }
        }

    RETURN_TYPES = ("COMBO,STRING", "COMBO, STRING", "INT", "INT", "FLOAT")
    RETURN_NAMES = ("sampler_name", "scheduler_name", "steps", "hires steps", "cfg")
    FUNCTION = "select"
    CATEGORY = "sampling"

    def select(self, sampler_name, scheduler_name, steps, hires_steps, cfg):
        return (sampler_name, scheduler_name, steps, hires_steps, cfg)

I've tried to use RETURN_TYPES = ("COMBO", ....) instead of "COMBO,STRING", but apparently, the frontend requires that extra ,STRING in order to accept the connection. But then, here is what I get when I'm trying to generate: Return type mismatch between linked nodes: sampler_name, COMBO,STRING != COMBO

So, how do you do this properly ?

thoroc commented 8 months ago

Shouldn't the return type not be a tuple for the sampler and scheduler?

    RETURN_TYPES = (("COMBO", "STRING"), ("COMBO", "STRING"), "INT", "INT", "FLOAT")
    RETURN_NAMES = ("sampler_name", "scheduler_name", "steps", "hires steps", "cfg")
water2891 commented 5 months ago

You can try:

    RETURN_TYPES = ("COMBO", "COMBO", "INT", "INT", "FLOAT")

    # ...

        return ([sampler_name],[scheduler_name], steps, hires_steps, cfg)
PsHohe commented 5 months ago

This is old, but I recently came across this same situation. The way I solved was by just using comfy.samplers.KSampler.SAMPLERS in the RETURN_TYPES. It would look like this: RETURN_TYPES = (comfy.samplers.KSampler.SAMPLERS, comfy.samplers.KSampler.SCHEDULERS, "INT", "INT", "FLOAT")