mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
044d4c107a
All invocation metadata (type, title, tags and category) are now defined in decorators. The decorators add the `type: Literal["invocation_type"]: "invocation_type"` field to the invocation. Category is a new invocation metadata, but it is not used by the frontend just yet. - `@invocation()` decorator for invocations ```py @invocation( "sdxl_compel_prompt", title="SDXL Prompt", tags=["sdxl", "compel", "prompt"], category="conditioning", ) class SDXLCompelPromptInvocation(BaseInvocation, SDXLPromptInvocationBase): ... ``` - `@invocation_output()` decorator for invocation outputs ```py @invocation_output("clip_skip_output") class ClipSkipInvocationOutput(BaseInvocationOutput): ... ``` - update invocation docs - add category to decorator - regen frontend types
63 lines
2.4 KiB
Python
63 lines
2.4 KiB
Python
# Copyright (c) 2023 Kyle Schouviller (https://github.com/kyle0654)
|
|
|
|
import numpy as np
|
|
|
|
from invokeai.app.invocations.primitives import IntegerOutput
|
|
|
|
from .baseinvocation import BaseInvocation, FieldDescriptions, InputField, InvocationContext, invocation
|
|
|
|
|
|
@invocation("add", title="Add Integers", tags=["math", "add"], category="math")
|
|
class AddInvocation(BaseInvocation):
|
|
"""Adds two numbers"""
|
|
|
|
a: int = InputField(default=0, description=FieldDescriptions.num_1)
|
|
b: int = InputField(default=0, description=FieldDescriptions.num_2)
|
|
|
|
def invoke(self, context: InvocationContext) -> IntegerOutput:
|
|
return IntegerOutput(value=self.a + self.b)
|
|
|
|
|
|
@invocation("sub", title="Subtract Integers", tags=["math", "subtract"], category="math")
|
|
class SubtractInvocation(BaseInvocation):
|
|
"""Subtracts two numbers"""
|
|
|
|
a: int = InputField(default=0, description=FieldDescriptions.num_1)
|
|
b: int = InputField(default=0, description=FieldDescriptions.num_2)
|
|
|
|
def invoke(self, context: InvocationContext) -> IntegerOutput:
|
|
return IntegerOutput(value=self.a - self.b)
|
|
|
|
|
|
@invocation("mul", title="Multiply Integers", tags=["math", "multiply"], category="math")
|
|
class MultiplyInvocation(BaseInvocation):
|
|
"""Multiplies two numbers"""
|
|
|
|
a: int = InputField(default=0, description=FieldDescriptions.num_1)
|
|
b: int = InputField(default=0, description=FieldDescriptions.num_2)
|
|
|
|
def invoke(self, context: InvocationContext) -> IntegerOutput:
|
|
return IntegerOutput(value=self.a * self.b)
|
|
|
|
|
|
@invocation("div", title="Divide Integers", tags=["math", "divide"], category="math")
|
|
class DivideInvocation(BaseInvocation):
|
|
"""Divides two numbers"""
|
|
|
|
a: int = InputField(default=0, description=FieldDescriptions.num_1)
|
|
b: int = InputField(default=0, description=FieldDescriptions.num_2)
|
|
|
|
def invoke(self, context: InvocationContext) -> IntegerOutput:
|
|
return IntegerOutput(value=int(self.a / self.b))
|
|
|
|
|
|
@invocation("rand_int", title="Random Integer", tags=["math", "random"], category="math")
|
|
class RandomIntInvocation(BaseInvocation):
|
|
"""Outputs a single random integer."""
|
|
|
|
low: int = InputField(default=0, description="The inclusive low value")
|
|
high: int = InputField(default=np.iinfo(np.int32).max, description="The exclusive high value")
|
|
|
|
def invoke(self, context: InvocationContext) -> IntegerOutput:
|
|
return IntegerOutput(value=np.random.randint(self.low, self.high))
|