ComfyUI icon indicating copy to clipboard operation
ComfyUI copied to clipboard

How to create a custom node that returns a sampler ?

Open dchatel opened this issue 2 years ago • 3 comments

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 ?

dchatel avatar Dec 09 '23 10:12 dchatel

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")

thoroc avatar Jan 03 '24 07:01 thoroc

You can try:

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

    # ...

        return ([sampler_name],[scheduler_name], steps, hires_steps, cfg)

water2891 avatar Apr 20 '24 14:04 water2891

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")

PsHohe avatar Apr 22 '24 05:04 PsHohe