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
50.49k stars 5.3k forks source link

Add an option to define the IDs used in the API workflow #4547

Open allo- opened 3 weeks ago

allo- commented 3 weeks ago

Feature Idea

Exporting a workflow for using it with the API assigns a numeric ID to each node, which appears to come from the order in which it was created. This makes it difficult to change parts of the workflow later, for example to assign a new prompt. Manually replacing the numbers with custom strings works fine with the API as the numeric IDs are also exported as strings, but the next time the workflow is exported it will have numeric node IDs again.

I suggest adding an optional field to define an ID to be used when exporting to the API, so that one can define IDs such as "prompt", "negative-prompt", "sampler", etc. to later use, for example, nodes["prompt"]["inputs"]["text"] for setting a prompt instead of nodes["7"]["inputs"]["text"].

Existing Solutions

TheBigRoomXXL commented 2 weeks ago

More generally, I think a way to add additional metadata to nodes would be very useful for API usage.

allo- commented 2 weeks ago

It seems that nodes marked as bypass are also not exported. I guess the export for the API is meant to be some kind of write-only format, but I think it would still be useful to export the full graph and have the bypass functionality so you can conditionally enable/disable parts of the graph in external code. Otherwise, you would have to export all combinations of active/inactive nodes into different API workflows to be able to, for example, change whether a control net is applied or not, instead of just changing the Apply Control Net node to be bypassed.