mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-09-10 11:35:40 +00:00
convert Primitive nodes to V3 schema (#9372)
This commit is contained in:
@@ -1,98 +1,109 @@
|
|||||||
# Primitive nodes that are evaluated at backend.
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
from typing_extensions import override
|
||||||
|
|
||||||
from comfy.comfy_types.node_typing import ComfyNodeABC, InputTypeDict, IO
|
from comfy_api.latest import ComfyExtension, io
|
||||||
|
|
||||||
|
|
||||||
class String(ComfyNodeABC):
|
class String(io.ComfyNode):
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(cls) -> InputTypeDict:
|
def define_schema(cls):
|
||||||
return {
|
return io.Schema(
|
||||||
"required": {"value": (IO.STRING, {})},
|
node_id="PrimitiveString",
|
||||||
}
|
display_name="String",
|
||||||
|
category="utils/primitive",
|
||||||
|
inputs=[
|
||||||
|
io.String.Input("value"),
|
||||||
|
],
|
||||||
|
outputs=[io.String.Output()],
|
||||||
|
)
|
||||||
|
|
||||||
RETURN_TYPES = (IO.STRING,)
|
|
||||||
FUNCTION = "execute"
|
|
||||||
CATEGORY = "utils/primitive"
|
|
||||||
|
|
||||||
def execute(self, value: str) -> tuple[str]:
|
|
||||||
return (value,)
|
|
||||||
|
|
||||||
|
|
||||||
class StringMultiline(ComfyNodeABC):
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(cls) -> InputTypeDict:
|
def execute(cls, value: str) -> io.NodeOutput:
|
||||||
return {
|
return io.NodeOutput(value)
|
||||||
"required": {"value": (IO.STRING, {"multiline": True,},)},
|
|
||||||
}
|
|
||||||
|
|
||||||
RETURN_TYPES = (IO.STRING,)
|
|
||||||
FUNCTION = "execute"
|
|
||||||
CATEGORY = "utils/primitive"
|
|
||||||
|
|
||||||
def execute(self, value: str) -> tuple[str]:
|
|
||||||
return (value,)
|
|
||||||
|
|
||||||
|
|
||||||
class Int(ComfyNodeABC):
|
class StringMultiline(io.ComfyNode):
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(cls) -> InputTypeDict:
|
def define_schema(cls):
|
||||||
return {
|
return io.Schema(
|
||||||
"required": {"value": (IO.INT, {"min": -sys.maxsize, "max": sys.maxsize, "control_after_generate": True})},
|
node_id="PrimitiveStringMultiline",
|
||||||
}
|
display_name="String (Multiline)",
|
||||||
|
category="utils/primitive",
|
||||||
|
inputs=[
|
||||||
|
io.String.Input("value", multiline=True),
|
||||||
|
],
|
||||||
|
outputs=[io.String.Output()],
|
||||||
|
)
|
||||||
|
|
||||||
RETURN_TYPES = (IO.INT,)
|
|
||||||
FUNCTION = "execute"
|
|
||||||
CATEGORY = "utils/primitive"
|
|
||||||
|
|
||||||
def execute(self, value: int) -> tuple[int]:
|
|
||||||
return (value,)
|
|
||||||
|
|
||||||
|
|
||||||
class Float(ComfyNodeABC):
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(cls) -> InputTypeDict:
|
def execute(cls, value: str) -> io.NodeOutput:
|
||||||
return {
|
return io.NodeOutput(value)
|
||||||
"required": {"value": (IO.FLOAT, {"min": -sys.maxsize, "max": sys.maxsize})},
|
|
||||||
}
|
|
||||||
|
|
||||||
RETURN_TYPES = (IO.FLOAT,)
|
|
||||||
FUNCTION = "execute"
|
|
||||||
CATEGORY = "utils/primitive"
|
|
||||||
|
|
||||||
def execute(self, value: float) -> tuple[float]:
|
|
||||||
return (value,)
|
|
||||||
|
|
||||||
|
|
||||||
class Boolean(ComfyNodeABC):
|
class Int(io.ComfyNode):
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(cls) -> InputTypeDict:
|
def define_schema(cls):
|
||||||
return {
|
return io.Schema(
|
||||||
"required": {"value": (IO.BOOLEAN, {})},
|
node_id="PrimitiveInt",
|
||||||
}
|
display_name="Int",
|
||||||
|
category="utils/primitive",
|
||||||
|
inputs=[
|
||||||
|
io.Int.Input("value", min=-sys.maxsize, max=sys.maxsize, control_after_generate=True),
|
||||||
|
],
|
||||||
|
outputs=[io.Int.Output()],
|
||||||
|
)
|
||||||
|
|
||||||
RETURN_TYPES = (IO.BOOLEAN,)
|
@classmethod
|
||||||
FUNCTION = "execute"
|
def execute(cls, value: int) -> io.NodeOutput:
|
||||||
CATEGORY = "utils/primitive"
|
return io.NodeOutput(value)
|
||||||
|
|
||||||
def execute(self, value: bool) -> tuple[bool]:
|
|
||||||
return (value,)
|
|
||||||
|
|
||||||
|
|
||||||
NODE_CLASS_MAPPINGS = {
|
class Float(io.ComfyNode):
|
||||||
"PrimitiveString": String,
|
@classmethod
|
||||||
"PrimitiveStringMultiline": StringMultiline,
|
def define_schema(cls):
|
||||||
"PrimitiveInt": Int,
|
return io.Schema(
|
||||||
"PrimitiveFloat": Float,
|
node_id="PrimitiveFloat",
|
||||||
"PrimitiveBoolean": Boolean,
|
display_name="Float",
|
||||||
}
|
category="utils/primitive",
|
||||||
|
inputs=[
|
||||||
|
io.Float.Input("value", min=-sys.maxsize, max=sys.maxsize),
|
||||||
|
],
|
||||||
|
outputs=[io.Float.Output()],
|
||||||
|
)
|
||||||
|
|
||||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
@classmethod
|
||||||
"PrimitiveString": "String",
|
def execute(cls, value: float) -> io.NodeOutput:
|
||||||
"PrimitiveStringMultiline": "String (Multiline)",
|
return io.NodeOutput(value)
|
||||||
"PrimitiveInt": "Int",
|
|
||||||
"PrimitiveFloat": "Float",
|
|
||||||
"PrimitiveBoolean": "Boolean",
|
class Boolean(io.ComfyNode):
|
||||||
}
|
@classmethod
|
||||||
|
def define_schema(cls):
|
||||||
|
return io.Schema(
|
||||||
|
node_id="PrimitiveBoolean",
|
||||||
|
display_name="Boolean",
|
||||||
|
category="utils/primitive",
|
||||||
|
inputs=[
|
||||||
|
io.Boolean.Input("value"),
|
||||||
|
],
|
||||||
|
outputs=[io.Boolean.Output()],
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def execute(cls, value: bool) -> io.NodeOutput:
|
||||||
|
return io.NodeOutput(value)
|
||||||
|
|
||||||
|
|
||||||
|
class PrimitivesExtension(ComfyExtension):
|
||||||
|
@override
|
||||||
|
async def get_node_list(self) -> list[type[io.ComfyNode]]:
|
||||||
|
return [
|
||||||
|
String,
|
||||||
|
StringMultiline,
|
||||||
|
Int,
|
||||||
|
Float,
|
||||||
|
Boolean,
|
||||||
|
]
|
||||||
|
|
||||||
|
async def comfy_entrypoint() -> PrimitivesExtension:
|
||||||
|
return PrimitivesExtension()
|
||||||
|
Reference in New Issue
Block a user