Skip to content

Commit 8ed5585

Browse files
psychedeliciousmaryhipp
authored andcommitted
feat(nodes): move output metadata to BaseInvocationOutput
1 parent 5ce226a commit 8ed5585

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

invokeai/app/invocations/baseinvocation.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
)
2626

2727
import semver
28-
from pydantic import BaseModel, ConfigDict, Field, TypeAdapter, create_model
28+
from pydantic import BaseModel, ConfigDict, Field, JsonValue, TypeAdapter, create_model
2929
from pydantic.fields import FieldInfo
3030
from pydantic_core import PydanticUndefined
3131

@@ -100,6 +100,12 @@ class BaseInvocationOutput(BaseModel):
100100
All invocation outputs must use the `@invocation_output` decorator to provide their unique type.
101101
"""
102102

103+
output_meta: Optional[dict[str, JsonValue]] = Field(
104+
default=None,
105+
description="Optional dictionary of metadata for the invocation output, unrelated to the invocation's actual output value. This is not exposed as an output field.",
106+
json_schema_extra={"field_kind": FieldKind.NodeAttribute},
107+
)
108+
103109
@staticmethod
104110
def json_schema_extra(schema: dict[str, Any], model_class: Type[BaseInvocationOutput]) -> None:
105111
"""Adds various UI-facing attributes to the invocation output's OpenAPI schema."""
@@ -235,12 +241,6 @@ def invoke_internal(self, context: InvocationContext, services: "InvocationServi
235241
json_schema_extra={"field_kind": FieldKind.NodeAttribute},
236242
)
237243

238-
output_metadata: Optional[dict[str, Any]] = Field(
239-
default=None,
240-
description="Optional metadata dictionary for the invocation",
241-
json_schema_extra={"field_kind": FieldKind.NodeAttribute},
242-
)
243-
244244
UIConfig: ClassVar[UIConfigBase]
245245

246246
model_config = ConfigDict(
@@ -360,12 +360,11 @@ def get_output_types(cls) -> Iterable[str]:
360360
"use_cache",
361361
"type",
362362
"workflow",
363-
"output_metadata",
364363
}
365364

366365
RESERVED_INPUT_FIELD_NAMES = {"metadata", "board"}
367366

368-
RESERVED_OUTPUT_FIELD_NAMES = {"type"}
367+
RESERVED_OUTPUT_FIELD_NAMES = {"type", "output_meta"}
369368

370369

371370
class _Model(BaseModel):

invokeai/app/util/custom_openapi.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ def openapi() -> dict[str, Any]:
6161
# We need to manually add all outputs to the schema - pydantic doesn't add them because they aren't used directly.
6262
for output in InvocationRegistry.get_output_classes():
6363
json_schema = output.model_json_schema(mode="serialization", ref_template="#/components/schemas/{model}")
64+
# Remove output_metadata that is only used on back-end from the schema
65+
if "output_meta" in json_schema["properties"]:
66+
json_schema["properties"].pop("output_meta")
67+
6468
move_defs_to_top_level(openapi_schema, json_schema)
6569
openapi_schema["components"]["schemas"][output.__name__] = json_schema
6670

@@ -70,9 +74,6 @@ def openapi() -> dict[str, Any]:
7074
json_schema = invocation.model_json_schema(
7175
mode="serialization", ref_template="#/components/schemas/{model}"
7276
)
73-
# Remove output_metadata that is only used on back-end from the schema
74-
if "output_metadata" in json_schema["properties"]:
75-
json_schema["properties"].pop("output_metadata")
7677
move_defs_to_top_level(openapi_schema, json_schema)
7778
output_title = invocation.get_output_annotation().__name__
7879
outputs_ref = {"$ref": f"#/components/schemas/{output_title}"}

0 commit comments

Comments
 (0)