2023-04-14 06:41:06 +00:00
|
|
|
# Copyright (c) 2023 Kyle Schouviller (https://github.com/kyle0654)
|
|
|
|
|
|
|
|
from typing import Literal
|
2023-07-18 14:26:33 +00:00
|
|
|
|
2023-04-14 06:41:06 +00:00
|
|
|
from pydantic import Field
|
2023-07-18 14:26:33 +00:00
|
|
|
|
|
|
|
from .baseinvocation import (BaseInvocation, BaseInvocationOutput,
|
|
|
|
InvocationConfig, InvocationContext)
|
|
|
|
from .math import FloatOutput, IntOutput
|
2023-04-14 06:41:06 +00:00
|
|
|
|
|
|
|
# Pass-through parameter nodes - used by subgraphs
|
|
|
|
|
|
|
|
class ParamIntInvocation(BaseInvocation):
|
|
|
|
"""An integer parameter"""
|
|
|
|
#fmt: off
|
|
|
|
type: Literal["param_int"] = "param_int"
|
|
|
|
a: int = Field(default=0, description="The integer value")
|
|
|
|
#fmt: on
|
|
|
|
|
2023-07-18 14:26:33 +00:00
|
|
|
class Config(InvocationConfig):
|
|
|
|
schema_extra = {
|
|
|
|
"ui": {
|
|
|
|
"tags": ["param", "integer"],
|
|
|
|
"title": "Integer Parameter"
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-04-14 06:41:06 +00:00
|
|
|
def invoke(self, context: InvocationContext) -> IntOutput:
|
|
|
|
return IntOutput(a=self.a)
|
2023-05-26 18:06:37 +00:00
|
|
|
|
|
|
|
class ParamFloatInvocation(BaseInvocation):
|
|
|
|
"""A float parameter"""
|
|
|
|
#fmt: off
|
|
|
|
type: Literal["param_float"] = "param_float"
|
|
|
|
param: float = Field(default=0.0, description="The float value")
|
|
|
|
#fmt: on
|
|
|
|
|
2023-07-18 14:26:33 +00:00
|
|
|
class Config(InvocationConfig):
|
|
|
|
schema_extra = {
|
|
|
|
"ui": {
|
|
|
|
"tags": ["param", "float"],
|
|
|
|
"title": "Float Parameter"
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-05-26 18:06:37 +00:00
|
|
|
def invoke(self, context: InvocationContext) -> FloatOutput:
|
|
|
|
return FloatOutput(param=self.param)
|
2023-07-18 14:26:33 +00:00
|
|
|
|
|
|
|
class StringOutput(BaseInvocationOutput):
|
|
|
|
"""A string output"""
|
|
|
|
type: Literal["string_output"] = "string_output"
|
|
|
|
text: str = Field(default=None, description="The output string")
|
|
|
|
|
|
|
|
|
|
|
|
class ParamStringInvocation(BaseInvocation):
|
|
|
|
"""A string parameter"""
|
|
|
|
type: Literal['param_string'] = 'param_string'
|
|
|
|
text: str = Field(default='', description='The string value')
|
|
|
|
|
|
|
|
class Config(InvocationConfig):
|
|
|
|
schema_extra = {
|
|
|
|
"ui": {
|
|
|
|
"tags": ["param", "string"],
|
|
|
|
"title": "String Parameter"
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-07-18 14:49:09 +00:00
|
|
|
def invoke(self, context: InvocationContext) -> StringOutput:
|
2023-07-18 14:26:33 +00:00
|
|
|
return StringOutput(text=self.text)
|
|
|
|
|