mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-12 23:30:56 +08:00
Due to how floating point works with rounding, setting min to `-sys.maxsize` and max to `sys.maxsize` will result in following error: ``` * PrimitiveFloat 969: - Value -9.223372036854776e+18 smaller than min of -9223372036854775807: value ``` The error arises because the floating-point approximation (-9.223372036854776e+18) is slightly smaller (i.e., more negative) than the precise integer value of -sys.maxsize (-9223372036854775807). Alternative approach would be to use sys.float_info.min and sys.float_info.max instead but that range might seem a bit excessive for a primitive node.
110 lines
2.8 KiB
Python
110 lines
2.8 KiB
Python
import sys
|
|
from typing_extensions import override
|
|
|
|
from comfy_api.latest import ComfyExtension, io
|
|
|
|
|
|
class String(io.ComfyNode):
|
|
@classmethod
|
|
def define_schema(cls):
|
|
return io.Schema(
|
|
node_id="PrimitiveString",
|
|
display_name="String",
|
|
category="utils/primitive",
|
|
inputs=[
|
|
io.String.Input("value"),
|
|
],
|
|
outputs=[io.String.Output()],
|
|
)
|
|
|
|
@classmethod
|
|
def execute(cls, value: str) -> io.NodeOutput:
|
|
return io.NodeOutput(value)
|
|
|
|
|
|
class StringMultiline(io.ComfyNode):
|
|
@classmethod
|
|
def define_schema(cls):
|
|
return io.Schema(
|
|
node_id="PrimitiveStringMultiline",
|
|
display_name="String (Multiline)",
|
|
category="utils/primitive",
|
|
inputs=[
|
|
io.String.Input("value", multiline=True),
|
|
],
|
|
outputs=[io.String.Output()],
|
|
)
|
|
|
|
@classmethod
|
|
def execute(cls, value: str) -> io.NodeOutput:
|
|
return io.NodeOutput(value)
|
|
|
|
|
|
class Int(io.ComfyNode):
|
|
@classmethod
|
|
def define_schema(cls):
|
|
return io.Schema(
|
|
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()],
|
|
)
|
|
|
|
@classmethod
|
|
def execute(cls, value: int) -> io.NodeOutput:
|
|
return io.NodeOutput(value)
|
|
|
|
|
|
class Float(io.ComfyNode):
|
|
@classmethod
|
|
def define_schema(cls):
|
|
return io.Schema(
|
|
node_id="PrimitiveFloat",
|
|
display_name="Float",
|
|
category="utils/primitive",
|
|
inputs=[
|
|
io.Float.Input("value", min=float(-sys.maxsize), max=float(sys.maxsize)),
|
|
],
|
|
outputs=[io.Float.Output()],
|
|
)
|
|
|
|
@classmethod
|
|
def execute(cls, value: float) -> io.NodeOutput:
|
|
return io.NodeOutput(value)
|
|
|
|
|
|
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()
|