mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2025-12-08 21:44:33 +08:00
update example_node to use V3 schema (#9723)
This commit is contained in:
parent
e9364ee279
commit
1395bce9f7
@ -1,96 +1,70 @@
|
|||||||
class Example:
|
from typing_extensions import override
|
||||||
|
|
||||||
|
from comfy_api.latest import ComfyExtension, io
|
||||||
|
|
||||||
|
|
||||||
|
class Example(io.ComfyNode):
|
||||||
"""
|
"""
|
||||||
A example node
|
An example node
|
||||||
|
|
||||||
Class methods
|
Class methods
|
||||||
-------------
|
-------------
|
||||||
INPUT_TYPES (dict):
|
define_schema (io.Schema):
|
||||||
Tell the main program input parameters of nodes.
|
Tell the main program the metadata, input, output parameters of nodes.
|
||||||
IS_CHANGED:
|
fingerprint_inputs:
|
||||||
optional method to control when the node is re executed.
|
optional method to control when the node is re executed.
|
||||||
|
check_lazy_status:
|
||||||
|
optional method to control list of input names that need to be evaluated.
|
||||||
|
|
||||||
Attributes
|
|
||||||
----------
|
|
||||||
RETURN_TYPES (`tuple`):
|
|
||||||
The type of each element in the output tuple.
|
|
||||||
RETURN_NAMES (`tuple`):
|
|
||||||
Optional: The name of each output in the output tuple.
|
|
||||||
FUNCTION (`str`):
|
|
||||||
The name of the entry-point method. For example, if `FUNCTION = "execute"` then it will run Example().execute()
|
|
||||||
OUTPUT_NODE ([`bool`]):
|
|
||||||
If this node is an output node that outputs a result/image from the graph. The SaveImage node is an example.
|
|
||||||
The backend iterates on these output nodes and tries to execute all their parents if their parent graph is properly connected.
|
|
||||||
Assumed to be False if not present.
|
|
||||||
CATEGORY (`str`):
|
|
||||||
The category the node should appear in the UI.
|
|
||||||
DEPRECATED (`bool`):
|
|
||||||
Indicates whether the node is deprecated. Deprecated nodes are hidden by default in the UI, but remain
|
|
||||||
functional in existing workflows that use them.
|
|
||||||
EXPERIMENTAL (`bool`):
|
|
||||||
Indicates whether the node is experimental. Experimental nodes are marked as such in the UI and may be subject to
|
|
||||||
significant changes or removal in future versions. Use with caution in production workflows.
|
|
||||||
execute(s) -> tuple || None:
|
|
||||||
The entry point method. The name of this method must be the same as the value of property `FUNCTION`.
|
|
||||||
For example, if `FUNCTION = "execute"` then this method's name must be `execute`, if `FUNCTION = "foo"` then it must be `foo`.
|
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
def define_schema(cls) -> io.Schema:
|
||||||
"""
|
"""
|
||||||
Return a dictionary which contains config for all input fields.
|
Return a schema which contains all information about the node.
|
||||||
Some types (string): "MODEL", "VAE", "CLIP", "CONDITIONING", "LATENT", "IMAGE", "INT", "STRING", "FLOAT".
|
Some types: "Model", "Vae", "Clip", "Conditioning", "Latent", "Image", "Int", "String", "Float", "Combo".
|
||||||
Input types "INT", "STRING" or "FLOAT" are special values for fields on the node.
|
For outputs the "io.Model.Output" should be used, for inputs the "io.Model.Input" can be used.
|
||||||
The type can be a list for selection.
|
The type can be a "Combo" - this will be a list for selection.
|
||||||
|
|
||||||
Returns: `dict`:
|
|
||||||
- Key input_fields_group (`string`): Can be either required, hidden or optional. A node class must have property `required`
|
|
||||||
- Value input_fields (`dict`): Contains input fields config:
|
|
||||||
* Key field_name (`string`): Name of a entry-point method's argument
|
|
||||||
* Value field_config (`tuple`):
|
|
||||||
+ First value is a string indicate the type of field or a list for selection.
|
|
||||||
+ Second value is a config for type "INT", "STRING" or "FLOAT".
|
|
||||||
"""
|
"""
|
||||||
return {
|
return io.Schema(
|
||||||
"required": {
|
node_id="Example",
|
||||||
"image": ("IMAGE",),
|
display_name="Example Node",
|
||||||
"int_field": ("INT", {
|
category="Example",
|
||||||
"default": 0,
|
inputs=[
|
||||||
"min": 0, #Minimum value
|
io.Image.Input("image"),
|
||||||
"max": 4096, #Maximum value
|
io.Int.Input(
|
||||||
"step": 64, #Slider's step
|
"int_field",
|
||||||
"display": "number", # Cosmetic only: display as "number" or "slider"
|
min=0,
|
||||||
"lazy": True # Will only be evaluated if check_lazy_status requires it
|
max=4096,
|
||||||
}),
|
step=64, # Slider's step
|
||||||
"float_field": ("FLOAT", {
|
display_mode=io.NumberDisplay.number, # Cosmetic only: display as "number" or "slider"
|
||||||
"default": 1.0,
|
lazy=True, # Will only be evaluated if check_lazy_status requires it
|
||||||
"min": 0.0,
|
),
|
||||||
"max": 10.0,
|
io.Float.Input(
|
||||||
"step": 0.01,
|
"float_field",
|
||||||
"round": 0.001, #The value representing the precision to round to, will be set to the step value by default. Can be set to False to disable rounding.
|
default=1.0,
|
||||||
"display": "number",
|
min=0.0,
|
||||||
"lazy": True
|
max=10.0,
|
||||||
}),
|
step=0.01,
|
||||||
"print_to_screen": (["enable", "disable"],),
|
round=0.001, #The value representing the precision to round to, will be set to the step value by default. Can be set to False to disable rounding.
|
||||||
"string_field": ("STRING", {
|
display_mode=io.NumberDisplay.number,
|
||||||
"multiline": False, #True if you want the field to look like the one on the ClipTextEncode node
|
lazy=True,
|
||||||
"default": "Hello World!",
|
),
|
||||||
"lazy": True
|
io.Combo.Input("print_to_screen", options=["enable", "disable"]),
|
||||||
}),
|
io.String.Input(
|
||||||
},
|
"string_field",
|
||||||
}
|
multiline=False, # True if you want the field to look like the one on the ClipTextEncode node
|
||||||
|
default="Hello world!",
|
||||||
|
lazy=True,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
outputs=[
|
||||||
|
io.Image.Output(),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
RETURN_TYPES = ("IMAGE",)
|
@classmethod
|
||||||
#RETURN_NAMES = ("image_output_name",)
|
def check_lazy_status(cls, image, string_field, int_field, float_field, print_to_screen):
|
||||||
|
|
||||||
FUNCTION = "test"
|
|
||||||
|
|
||||||
#OUTPUT_NODE = False
|
|
||||||
|
|
||||||
CATEGORY = "Example"
|
|
||||||
|
|
||||||
def check_lazy_status(self, image, string_field, int_field, float_field, print_to_screen):
|
|
||||||
"""
|
"""
|
||||||
Return a list of input names that need to be evaluated.
|
Return a list of input names that need to be evaluated.
|
||||||
|
|
||||||
@ -107,7 +81,8 @@ class Example:
|
|||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def test(self, image, string_field, int_field, float_field, print_to_screen):
|
@classmethod
|
||||||
|
def execute(cls, image, string_field, int_field, float_field, print_to_screen) -> io.NodeOutput:
|
||||||
if print_to_screen == "enable":
|
if print_to_screen == "enable":
|
||||||
print(f"""Your input contains:
|
print(f"""Your input contains:
|
||||||
string_field aka input text: {string_field}
|
string_field aka input text: {string_field}
|
||||||
@ -116,7 +91,7 @@ class Example:
|
|||||||
""")
|
""")
|
||||||
#do some processing on the image, in this example I just invert it
|
#do some processing on the image, in this example I just invert it
|
||||||
image = 1.0 - image
|
image = 1.0 - image
|
||||||
return (image,)
|
return io.NodeOutput(image)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
The node will always be re executed if any of the inputs change but
|
The node will always be re executed if any of the inputs change but
|
||||||
@ -127,7 +102,7 @@ class Example:
|
|||||||
changes between executions the LoadImage node is executed again.
|
changes between executions the LoadImage node is executed again.
|
||||||
"""
|
"""
|
||||||
#@classmethod
|
#@classmethod
|
||||||
#def IS_CHANGED(s, image, string_field, int_field, float_field, print_to_screen):
|
#def fingerprint_inputs(s, image, string_field, int_field, float_field, print_to_screen):
|
||||||
# return ""
|
# return ""
|
||||||
|
|
||||||
# Set the web directory, any .js file in that directory will be loaded by the frontend as a frontend extension
|
# Set the web directory, any .js file in that directory will be loaded by the frontend as a frontend extension
|
||||||
@ -143,13 +118,13 @@ async def get_hello(request):
|
|||||||
return web.json_response("hello")
|
return web.json_response("hello")
|
||||||
|
|
||||||
|
|
||||||
# A dictionary that contains all nodes you want to export with their names
|
class ExampleExtension(ComfyExtension):
|
||||||
# NOTE: names should be globally unique
|
@override
|
||||||
NODE_CLASS_MAPPINGS = {
|
async def get_node_list(self) -> list[type[io.ComfyNode]]:
|
||||||
"Example": Example
|
return [
|
||||||
}
|
Example,
|
||||||
|
]
|
||||||
|
|
||||||
# A dictionary that contains the friendly/humanly readable titles for the nodes
|
|
||||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
async def comfy_entrypoint() -> ExampleExtension: # ComfyUI calls this to load your extension and its nodes.
|
||||||
"Example": "Example Node"
|
return ExampleExtension()
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user