Skip to content

experiment: allow Any as output type in nodes #7758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion invokeai/app/invocations/primitives.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) 2023 Kyle Schouviller (https://github.com/kyle0654)

from typing import Optional
from typing import Any, Optional

import torch

@@ -26,6 +26,7 @@
SD3ConditioningField,
TensorField,
UIComponent,
UIType,
)
from invokeai.app.services.images.images_common import ImageDTO
from invokeai.app.services.shared.invocation_context import InvocationContext
@@ -535,3 +536,27 @@ def invoke(self, context: InvocationContext) -> BoundingBoxOutput:


# endregion


@invocation_output("any_output")
class AnyOutput(BaseInvocationOutput):
value: Any = OutputField(description="The output value", ui_type=UIType.Any)


@invocation(
"switcher",
title="Switcher",
tags=["primitives", "switcher"],
category="primitives",
version="1.0.0",
)
class SwitcherInvocation(BaseInvocation):
a: Any = InputField(description="The first input", ui_type=UIType.Any)
b: Any = InputField(description="The second input", ui_type=UIType.Any)
switch: bool = InputField(
description="Switch between the two inputs. If false, the first input is returned. If true, the second input is returned."
)

def invoke(self, context: InvocationContext) -> AnyOutput:
value = self.b if self.switch else self.a
return AnyOutput(value=value)
Original file line number Diff line number Diff line change
@@ -58,6 +58,7 @@ export const validateConnectionTypes = (sourceType: FieldType, targetType: Field
const isSubTypeMatch = doesCardinalityMatch && (isIntToFloat || isIntToString || isFloatToString);

const isTargetAnyType = targetType.name === 'AnyField';
const isSourceAnyType = sourceType.name === 'AnyField';

// One of these must be true for the connection to be valid
return (
@@ -67,6 +68,7 @@ export const validateConnectionTypes = (sourceType: FieldType, targetType: Field
isGenericCollectionToAnyCollectionOrSingleOrCollection ||
isCollectionToGenericCollection ||
isSubTypeMatch ||
isTargetAnyType
isTargetAnyType ||
isSourceAnyType
);
};
Original file line number Diff line number Diff line change
@@ -144,7 +144,7 @@ export const parseSchema = (

const fieldType = fieldTypeOverride ?? originalFieldType;
if (!fieldType) {
log.trace({ node: type, field: propertyName, schema: parseify(property) }, 'Unable to parse field type');
log.warn({ node: type, field: propertyName, schema: parseify(property) }, 'Unable to parse field type');
return inputsAccumulator;
}

@@ -214,7 +214,7 @@ export const parseSchema = (

const fieldType = fieldTypeOverride ?? originalFieldType;
if (!fieldType) {
log.trace({ node: type, field: propertyName, schema: parseify(property) }, 'Unable to parse field type');
log.warn({ node: type, field: propertyName, schema: parseify(property) }, 'Unable to parse field type');
return outputsAccumulator;
}

@@ -269,7 +269,7 @@ const getFieldType = (
} catch (e) {
const tKey = kind === 'input' ? 'nodes.inputFieldTypeParseError' : 'nodes.outputFieldTypeParseError';
if (e instanceof FieldParseError) {
log.warn(
log.trace(
{
node: type,
field: propertyName,
@@ -282,7 +282,7 @@ const getFieldType = (
})
);
} else {
log.warn(
log.trace(
{
node: type,
field: propertyName,