From bc04bb8dc0051dc059647fb2bd8b18b65e62a08b Mon Sep 17 00:00:00 2001 From: Joey Ballentine Date: Mon, 5 Feb 2024 00:27:07 -0500 Subject: [PATCH 1/6] "Hub" node --- .../chaiNNer_standard/utility/value/hub.py | 43 +++++++++++++++++++ .../utility/value/pass_through.py | 4 -- 2 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 backend/src/packages/chaiNNer_standard/utility/value/hub.py diff --git a/backend/src/packages/chaiNNer_standard/utility/value/hub.py b/backend/src/packages/chaiNNer_standard/utility/value/hub.py new file mode 100644 index 000000000..75b743336 --- /dev/null +++ b/backend/src/packages/chaiNNer_standard/utility/value/hub.py @@ -0,0 +1,43 @@ +from __future__ import annotations + +from nodes.groups import optional_list_group +from nodes.properties.inputs import AnyInput +from nodes.properties.outputs import BaseOutput + +from .. import value_group + + +@value_group.register( + schema_id="chainner:utility:hub", + name="Hub", + description="Similar to passthrough, but allows many input to be passed in, which will then be output in order.", + icon="MdDoubleArrow", + inputs=[ + AnyInput(label="Value 1").make_fused(0), + optional_list_group( + AnyInput(label="Value 2").make_fused(1).make_optional(), + AnyInput(label="Value 3").make_fused(2).make_optional(), + AnyInput(label="Value 4").make_fused(3).make_optional(), + AnyInput(label="Value 5").make_fused(4).make_optional(), + AnyInput(label="Value 6").make_fused(5).make_optional(), + AnyInput(label="Value 7").make_fused(6).make_optional(), + AnyInput(label="Value 8").make_fused(7).make_optional(), + AnyInput(label="Value 9").make_fused(8).make_optional(), + AnyInput(label="Value 10").make_fused(9).make_optional(), + ), + ], + outputs=[ + BaseOutput(output_type="Input0", label="Value 1"), + BaseOutput(output_type="Input1", label="Value 2"), + BaseOutput(output_type="Input2", label="Value 3"), + BaseOutput(output_type="Input3", label="Value 4"), + BaseOutput(output_type="Input4", label="Value 5"), + BaseOutput(output_type="Input5", label="Value 6"), + BaseOutput(output_type="Input6", label="Value 7"), + BaseOutput(output_type="Input7", label="Value 8"), + BaseOutput(output_type="Input8", label="Value 9"), + BaseOutput(output_type="Input9", label="Value 10"), + ], +) +def hub_node(value: object) -> object: + return value diff --git a/backend/src/packages/chaiNNer_standard/utility/value/pass_through.py b/backend/src/packages/chaiNNer_standard/utility/value/pass_through.py index 36ffc41c8..444e59def 100644 --- a/backend/src/packages/chaiNNer_standard/utility/value/pass_through.py +++ b/backend/src/packages/chaiNNer_standard/utility/value/pass_through.py @@ -1,7 +1,3 @@ -""" -Nodes that provide various generic utility -""" - from __future__ import annotations from nodes.properties.inputs import AnyInput From 4100ff81f098166b653b87c8676c17d21c09c251 Mon Sep 17 00:00:00 2001 From: Joey Ballentine Date: Mon, 5 Feb 2024 00:29:20 -0500 Subject: [PATCH 2/6] Make it actually work --- .../chaiNNer_standard/utility/value/hub.py | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/backend/src/packages/chaiNNer_standard/utility/value/hub.py b/backend/src/packages/chaiNNer_standard/utility/value/hub.py index 75b743336..8b0f5672e 100644 --- a/backend/src/packages/chaiNNer_standard/utility/value/hub.py +++ b/backend/src/packages/chaiNNer_standard/utility/value/hub.py @@ -39,5 +39,29 @@ BaseOutput(output_type="Input9", label="Value 10"), ], ) -def hub_node(value: object) -> object: - return value +def hub_node( + value_a: object, + value_b: object = None, + value_c: object = None, + value_d: object = None, + value_e: object = None, + value_f: object = None, + value_g: object = None, + value_h: object = None, + value_i: object = None, + value_j: object = None, +) -> tuple[ + object, object, object, object, object, object, object, object, object, object +]: + return ( + value_a, + value_b, + value_c, + value_d, + value_e, + value_f, + value_g, + value_h, + value_i, + value_j, + ) From f02fb4b6e4340b0a576d742e82040ffc5cb741f5 Mon Sep 17 00:00:00 2001 From: Joey Ballentine Date: Mon, 5 Feb 2024 00:33:45 -0500 Subject: [PATCH 3/6] Make it _actually_ work --- backend/src/api/output.py | 5 ++- .../chaiNNer_standard/utility/value/hub.py | 36 +++++++++---------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/backend/src/api/output.py b/backend/src/api/output.py index f9fbb5f96..d17825536 100644 --- a/backend/src/api/output.py +++ b/backend/src/api/output.py @@ -17,6 +17,7 @@ def __init__( kind: OutputKind = "generic", has_handle: bool = True, associated_type: Any = None, + allow_none: bool = False, ): self.output_type: navi.ExpressionJson = output_type self.label: str = label @@ -26,6 +27,7 @@ def __init__( self.has_handle: bool = has_handle self.associated_type: Any = associated_type + self.allow_none: bool = allow_none # Optional documentation self.description: str | None = None @@ -66,5 +68,6 @@ def get_broadcast_type(self, _value: object) -> navi.ExpressionJson | None: return None def enforce(self, value: object) -> object: - assert value is not None + if not self.allow_none: + assert value is not None return value diff --git a/backend/src/packages/chaiNNer_standard/utility/value/hub.py b/backend/src/packages/chaiNNer_standard/utility/value/hub.py index 8b0f5672e..339506c2f 100644 --- a/backend/src/packages/chaiNNer_standard/utility/value/hub.py +++ b/backend/src/packages/chaiNNer_standard/utility/value/hub.py @@ -28,28 +28,28 @@ ], outputs=[ BaseOutput(output_type="Input0", label="Value 1"), - BaseOutput(output_type="Input1", label="Value 2"), - BaseOutput(output_type="Input2", label="Value 3"), - BaseOutput(output_type="Input3", label="Value 4"), - BaseOutput(output_type="Input4", label="Value 5"), - BaseOutput(output_type="Input5", label="Value 6"), - BaseOutput(output_type="Input6", label="Value 7"), - BaseOutput(output_type="Input7", label="Value 8"), - BaseOutput(output_type="Input8", label="Value 9"), - BaseOutput(output_type="Input9", label="Value 10"), + BaseOutput(output_type="Input1", label="Value 2", allow_none=True), + BaseOutput(output_type="Input2", label="Value 3", allow_none=True), + BaseOutput(output_type="Input3", label="Value 4", allow_none=True), + BaseOutput(output_type="Input4", label="Value 5", allow_none=True), + BaseOutput(output_type="Input5", label="Value 6", allow_none=True), + BaseOutput(output_type="Input6", label="Value 7", allow_none=True), + BaseOutput(output_type="Input7", label="Value 8", allow_none=True), + BaseOutput(output_type="Input8", label="Value 9", allow_none=True), + BaseOutput(output_type="Input9", label="Value 10", allow_none=True), ], ) def hub_node( value_a: object, - value_b: object = None, - value_c: object = None, - value_d: object = None, - value_e: object = None, - value_f: object = None, - value_g: object = None, - value_h: object = None, - value_i: object = None, - value_j: object = None, + value_b: object | None = None, + value_c: object | None = None, + value_d: object | None = None, + value_e: object | None = None, + value_f: object | None = None, + value_g: object | None = None, + value_h: object | None = None, + value_i: object | None = None, + value_j: object | None = None, ) -> tuple[ object, object, object, object, object, object, object, object, object, object ]: From 2eb4ac2e49568220f4bac9ed2a416bf0fb812a97 Mon Sep 17 00:00:00 2001 From: Joey Ballentine Date: Mon, 5 Feb 2024 01:14:07 -0500 Subject: [PATCH 4/6] Just add hub features to passthrough --- .../chaiNNer_standard/utility/value/hub.py | 67 ------------------- .../utility/value/pass_through.py | 55 +++++++++++++-- 2 files changed, 50 insertions(+), 72 deletions(-) delete mode 100644 backend/src/packages/chaiNNer_standard/utility/value/hub.py diff --git a/backend/src/packages/chaiNNer_standard/utility/value/hub.py b/backend/src/packages/chaiNNer_standard/utility/value/hub.py deleted file mode 100644 index 339506c2f..000000000 --- a/backend/src/packages/chaiNNer_standard/utility/value/hub.py +++ /dev/null @@ -1,67 +0,0 @@ -from __future__ import annotations - -from nodes.groups import optional_list_group -from nodes.properties.inputs import AnyInput -from nodes.properties.outputs import BaseOutput - -from .. import value_group - - -@value_group.register( - schema_id="chainner:utility:hub", - name="Hub", - description="Similar to passthrough, but allows many input to be passed in, which will then be output in order.", - icon="MdDoubleArrow", - inputs=[ - AnyInput(label="Value 1").make_fused(0), - optional_list_group( - AnyInput(label="Value 2").make_fused(1).make_optional(), - AnyInput(label="Value 3").make_fused(2).make_optional(), - AnyInput(label="Value 4").make_fused(3).make_optional(), - AnyInput(label="Value 5").make_fused(4).make_optional(), - AnyInput(label="Value 6").make_fused(5).make_optional(), - AnyInput(label="Value 7").make_fused(6).make_optional(), - AnyInput(label="Value 8").make_fused(7).make_optional(), - AnyInput(label="Value 9").make_fused(8).make_optional(), - AnyInput(label="Value 10").make_fused(9).make_optional(), - ), - ], - outputs=[ - BaseOutput(output_type="Input0", label="Value 1"), - BaseOutput(output_type="Input1", label="Value 2", allow_none=True), - BaseOutput(output_type="Input2", label="Value 3", allow_none=True), - BaseOutput(output_type="Input3", label="Value 4", allow_none=True), - BaseOutput(output_type="Input4", label="Value 5", allow_none=True), - BaseOutput(output_type="Input5", label="Value 6", allow_none=True), - BaseOutput(output_type="Input6", label="Value 7", allow_none=True), - BaseOutput(output_type="Input7", label="Value 8", allow_none=True), - BaseOutput(output_type="Input8", label="Value 9", allow_none=True), - BaseOutput(output_type="Input9", label="Value 10", allow_none=True), - ], -) -def hub_node( - value_a: object, - value_b: object | None = None, - value_c: object | None = None, - value_d: object | None = None, - value_e: object | None = None, - value_f: object | None = None, - value_g: object | None = None, - value_h: object | None = None, - value_i: object | None = None, - value_j: object | None = None, -) -> tuple[ - object, object, object, object, object, object, object, object, object, object -]: - return ( - value_a, - value_b, - value_c, - value_d, - value_e, - value_f, - value_g, - value_h, - value_i, - value_j, - ) diff --git a/backend/src/packages/chaiNNer_standard/utility/value/pass_through.py b/backend/src/packages/chaiNNer_standard/utility/value/pass_through.py index 444e59def..0e97d65dd 100644 --- a/backend/src/packages/chaiNNer_standard/utility/value/pass_through.py +++ b/backend/src/packages/chaiNNer_standard/utility/value/pass_through.py @@ -1,5 +1,6 @@ from __future__ import annotations +from nodes.groups import optional_list_group from nodes.properties.inputs import AnyInput from nodes.properties.outputs import BaseOutput @@ -9,14 +10,58 @@ @value_group.register( schema_id="chainner:utility:pass_through", name="Pass Through", - description="Outputs the input value as is.", + description="Outputs the input value as is. Supports up to 10 inputs.", icon="MdDoubleArrow", inputs=[ - AnyInput(label="Value").make_fused(), + AnyInput(label="Value 1").make_fused(0), + optional_list_group( + AnyInput(label="Value 2").make_fused(1).make_optional(), + AnyInput(label="Value 3").make_fused(2).make_optional(), + AnyInput(label="Value 4").make_fused(3).make_optional(), + AnyInput(label="Value 5").make_fused(4).make_optional(), + AnyInput(label="Value 6").make_fused(5).make_optional(), + AnyInput(label="Value 7").make_fused(6).make_optional(), + AnyInput(label="Value 8").make_fused(7).make_optional(), + AnyInput(label="Value 9").make_fused(8).make_optional(), + AnyInput(label="Value 10").make_fused(9).make_optional(), + ), ], outputs=[ - BaseOutput(output_type="Input0", label="Value"), + BaseOutput(output_type="Input0", label="Value 1"), + BaseOutput(output_type="Input1", label="Value 2", allow_none=True), + BaseOutput(output_type="Input2", label="Value 3", allow_none=True), + BaseOutput(output_type="Input3", label="Value 4", allow_none=True), + BaseOutput(output_type="Input4", label="Value 5", allow_none=True), + BaseOutput(output_type="Input5", label="Value 6", allow_none=True), + BaseOutput(output_type="Input6", label="Value 7", allow_none=True), + BaseOutput(output_type="Input7", label="Value 8", allow_none=True), + BaseOutput(output_type="Input8", label="Value 9", allow_none=True), + BaseOutput(output_type="Input9", label="Value 10", allow_none=True), ], ) -def pass_through_node(value: object) -> object: - return value +def pass_through_node( + value_a: object, + value_b: object | None = None, + value_c: object | None = None, + value_d: object | None = None, + value_e: object | None = None, + value_f: object | None = None, + value_g: object | None = None, + value_h: object | None = None, + value_i: object | None = None, + value_j: object | None = None, +) -> tuple[ + object, object, object, object, object, object, object, object, object, object +]: + return ( + value_a, + value_b, + value_c, + value_d, + value_e, + value_f, + value_g, + value_h, + value_i, + value_j, + ) From 64a25b3b242f300c4948a961d45fd86dbeb69d1f Mon Sep 17 00:00:00 2001 From: Joey Ballentine Date: Mon, 5 Feb 2024 20:57:51 -0500 Subject: [PATCH 5/6] anyoutput --- backend/src/api/output.py | 4 ---- .../properties/outputs/generic_outputs.py | 12 ++++++++++ .../utility/value/pass_through.py | 22 +++++++++---------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/backend/src/api/output.py b/backend/src/api/output.py index d17825536..b20ba1a19 100644 --- a/backend/src/api/output.py +++ b/backend/src/api/output.py @@ -17,7 +17,6 @@ def __init__( kind: OutputKind = "generic", has_handle: bool = True, associated_type: Any = None, - allow_none: bool = False, ): self.output_type: navi.ExpressionJson = output_type self.label: str = label @@ -27,7 +26,6 @@ def __init__( self.has_handle: bool = has_handle self.associated_type: Any = associated_type - self.allow_none: bool = allow_none # Optional documentation self.description: str | None = None @@ -68,6 +66,4 @@ def get_broadcast_type(self, _value: object) -> navi.ExpressionJson | None: return None def enforce(self, value: object) -> object: - if not self.allow_none: - assert value is not None return value diff --git a/backend/src/nodes/properties/outputs/generic_outputs.py b/backend/src/nodes/properties/outputs/generic_outputs.py index f4e53feb3..b2ea6803b 100644 --- a/backend/src/nodes/properties/outputs/generic_outputs.py +++ b/backend/src/nodes/properties/outputs/generic_outputs.py @@ -104,3 +104,15 @@ def __init__(self, label: str = "Audio Stream"): label=label, kind="generic", ) + + +class AnyOutput(BaseOutput): + def __init__(self, label: str = "Any", output_type: navi.ExpressionJson = "Any"): + super().__init__( + output_type=output_type, + label=label, + kind="generic", + ) + + def enforce(self, value: object) -> object: + return value diff --git a/backend/src/packages/chaiNNer_standard/utility/value/pass_through.py b/backend/src/packages/chaiNNer_standard/utility/value/pass_through.py index 0e97d65dd..07439255f 100644 --- a/backend/src/packages/chaiNNer_standard/utility/value/pass_through.py +++ b/backend/src/packages/chaiNNer_standard/utility/value/pass_through.py @@ -2,7 +2,7 @@ from nodes.groups import optional_list_group from nodes.properties.inputs import AnyInput -from nodes.properties.outputs import BaseOutput +from nodes.properties.outputs import AnyOutput from .. import value_group @@ -27,16 +27,16 @@ ), ], outputs=[ - BaseOutput(output_type="Input0", label="Value 1"), - BaseOutput(output_type="Input1", label="Value 2", allow_none=True), - BaseOutput(output_type="Input2", label="Value 3", allow_none=True), - BaseOutput(output_type="Input3", label="Value 4", allow_none=True), - BaseOutput(output_type="Input4", label="Value 5", allow_none=True), - BaseOutput(output_type="Input5", label="Value 6", allow_none=True), - BaseOutput(output_type="Input6", label="Value 7", allow_none=True), - BaseOutput(output_type="Input7", label="Value 8", allow_none=True), - BaseOutput(output_type="Input8", label="Value 9", allow_none=True), - BaseOutput(output_type="Input9", label="Value 10", allow_none=True), + AnyOutput(output_type="Input0", label="Value 1"), + AnyOutput(output_type="Input1", label="Value 2"), + AnyOutput(output_type="Input2", label="Value 3"), + AnyOutput(output_type="Input3", label="Value 4"), + AnyOutput(output_type="Input4", label="Value 5"), + AnyOutput(output_type="Input5", label="Value 6"), + AnyOutput(output_type="Input6", label="Value 7"), + AnyOutput(output_type="Input7", label="Value 8"), + AnyOutput(output_type="Input8", label="Value 9"), + AnyOutput(output_type="Input9", label="Value 10"), ], ) def pass_through_node( From f0791f671e48224124ddd24625622e5780fae04e Mon Sep 17 00:00:00 2001 From: Joey Ballentine Date: Tue, 6 Feb 2024 23:46:12 -0500 Subject: [PATCH 6/6] add back assertion --- backend/src/api/output.py | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/api/output.py b/backend/src/api/output.py index b20ba1a19..f9fbb5f96 100644 --- a/backend/src/api/output.py +++ b/backend/src/api/output.py @@ -66,4 +66,5 @@ def get_broadcast_type(self, _value: object) -> navi.ExpressionJson | None: return None def enforce(self, value: object) -> object: + assert value is not None return value