Refactor input classes to include traceability and metadata support
This commit is contained in:
parent
9e4a414682
commit
1909acca52
2 changed files with 24 additions and 14 deletions
|
|
@ -87,6 +87,14 @@ class BaseInputMixin(BaseModel, validate_assignment=True):
|
||||||
return dump
|
return dump
|
||||||
|
|
||||||
|
|
||||||
|
class InputTraceMixin(BaseModel):
|
||||||
|
trace_as_input: bool = True
|
||||||
|
|
||||||
|
|
||||||
|
class MetadataTraceMixin(BaseModel):
|
||||||
|
trace_as_metadata: bool = True
|
||||||
|
|
||||||
|
|
||||||
# Mixin for input fields that can be listable
|
# Mixin for input fields that can be listable
|
||||||
class ListableInputMixin(BaseModel):
|
class ListableInputMixin(BaseModel):
|
||||||
is_list: bool = Field(default=False, serialization_alias="list")
|
is_list: bool = Field(default=False, serialization_alias="list")
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,16 @@ from .input_mixin import (
|
||||||
DropDownMixin,
|
DropDownMixin,
|
||||||
FieldTypes,
|
FieldTypes,
|
||||||
FileMixin,
|
FileMixin,
|
||||||
|
InputTraceMixin,
|
||||||
ListableInputMixin,
|
ListableInputMixin,
|
||||||
|
MetadataTraceMixin,
|
||||||
MultilineMixin,
|
MultilineMixin,
|
||||||
RangeMixin,
|
RangeMixin,
|
||||||
SerializableFieldTypes,
|
SerializableFieldTypes,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class HandleInput(BaseInputMixin, ListableInputMixin):
|
class HandleInput(BaseInputMixin, ListableInputMixin, MetadataTraceMixin):
|
||||||
"""
|
"""
|
||||||
Represents an Input that has a Handle to a specific type (e.g. BaseLanguageModel, BaseRetriever, etc.)
|
Represents an Input that has a Handle to a specific type (e.g. BaseLanguageModel, BaseRetriever, etc.)
|
||||||
|
|
||||||
|
|
@ -35,7 +37,7 @@ class HandleInput(BaseInputMixin, ListableInputMixin):
|
||||||
field_type: Optional[SerializableFieldTypes] = FieldTypes.OTHER
|
field_type: Optional[SerializableFieldTypes] = FieldTypes.OTHER
|
||||||
|
|
||||||
|
|
||||||
class DataInput(HandleInput):
|
class DataInput(HandleInput, InputTraceMixin):
|
||||||
"""
|
"""
|
||||||
Represents an Input that has a Handle that receives a Data object.
|
Represents an Input that has a Handle that receives a Data object.
|
||||||
|
|
||||||
|
|
@ -46,12 +48,12 @@ class DataInput(HandleInput):
|
||||||
input_types: list[str] = ["Data"]
|
input_types: list[str] = ["Data"]
|
||||||
|
|
||||||
|
|
||||||
class PromptInput(BaseInputMixin, ListableInputMixin):
|
class PromptInput(BaseInputMixin, ListableInputMixin, InputTraceMixin):
|
||||||
field_type: Optional[SerializableFieldTypes] = FieldTypes.PROMPT
|
field_type: Optional[SerializableFieldTypes] = FieldTypes.PROMPT
|
||||||
|
|
||||||
|
|
||||||
# Applying mixins to a specific input type
|
# Applying mixins to a specific input type
|
||||||
class StrInput(BaseInputMixin, ListableInputMixin, DatabaseLoadMixin):
|
class StrInput(BaseInputMixin, ListableInputMixin, DatabaseLoadMixin, MetadataTraceMixin):
|
||||||
field_type: Optional[SerializableFieldTypes] = FieldTypes.TEXT
|
field_type: Optional[SerializableFieldTypes] = FieldTypes.TEXT
|
||||||
load_from_db: CoalesceBool = False
|
load_from_db: CoalesceBool = False
|
||||||
"""Defines if the field will allow the user to open a text editor. Default is False."""
|
"""Defines if the field will allow the user to open a text editor. Default is False."""
|
||||||
|
|
@ -101,7 +103,7 @@ class StrInput(BaseInputMixin, ListableInputMixin, DatabaseLoadMixin):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
class MessageInput(StrInput):
|
class MessageInput(StrInput, InputTraceMixin):
|
||||||
input_types: list[str] = ["Message"]
|
input_types: list[str] = ["Message"]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
@ -114,7 +116,7 @@ class MessageInput(StrInput):
|
||||||
raise ValueError(f"Invalid value type {type(v)}")
|
raise ValueError(f"Invalid value type {type(v)}")
|
||||||
|
|
||||||
|
|
||||||
class TextInput(StrInput):
|
class TextInput(StrInput, MetadataTraceMixin, InputTraceMixin):
|
||||||
"""
|
"""
|
||||||
Represents a text input component for the Langflow system.
|
Represents a text input component for the Langflow system.
|
||||||
|
|
||||||
|
|
@ -163,7 +165,7 @@ class TextInput(StrInput):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
class MultilineInput(TextInput, MultilineMixin):
|
class MultilineInput(TextInput, MultilineMixin, InputTraceMixin):
|
||||||
"""
|
"""
|
||||||
Represents a multiline input field.
|
Represents a multiline input field.
|
||||||
|
|
||||||
|
|
@ -194,7 +196,7 @@ class SecretStrInput(BaseInputMixin, DatabaseLoadMixin):
|
||||||
load_from_db: CoalesceBool = True
|
load_from_db: CoalesceBool = True
|
||||||
|
|
||||||
|
|
||||||
class IntInput(BaseInputMixin, ListableInputMixin, RangeMixin):
|
class IntInput(BaseInputMixin, ListableInputMixin, RangeMixin, MetadataTraceMixin):
|
||||||
"""
|
"""
|
||||||
Represents an integer field.
|
Represents an integer field.
|
||||||
|
|
||||||
|
|
@ -208,7 +210,7 @@ class IntInput(BaseInputMixin, ListableInputMixin, RangeMixin):
|
||||||
field_type: Optional[SerializableFieldTypes] = FieldTypes.INTEGER
|
field_type: Optional[SerializableFieldTypes] = FieldTypes.INTEGER
|
||||||
|
|
||||||
|
|
||||||
class FloatInput(BaseInputMixin, ListableInputMixin, RangeMixin):
|
class FloatInput(BaseInputMixin, ListableInputMixin, RangeMixin, MetadataTraceMixin):
|
||||||
"""
|
"""
|
||||||
Represents a float field.
|
Represents a float field.
|
||||||
|
|
||||||
|
|
@ -222,7 +224,7 @@ class FloatInput(BaseInputMixin, ListableInputMixin, RangeMixin):
|
||||||
field_type: Optional[SerializableFieldTypes] = FieldTypes.FLOAT
|
field_type: Optional[SerializableFieldTypes] = FieldTypes.FLOAT
|
||||||
|
|
||||||
|
|
||||||
class BoolInput(BaseInputMixin, ListableInputMixin):
|
class BoolInput(BaseInputMixin, ListableInputMixin, MetadataTraceMixin):
|
||||||
"""
|
"""
|
||||||
Represents a boolean field.
|
Represents a boolean field.
|
||||||
|
|
||||||
|
|
@ -238,7 +240,7 @@ class BoolInput(BaseInputMixin, ListableInputMixin):
|
||||||
value: CoalesceBool = False
|
value: CoalesceBool = False
|
||||||
|
|
||||||
|
|
||||||
class NestedDictInput(BaseInputMixin, ListableInputMixin):
|
class NestedDictInput(BaseInputMixin, ListableInputMixin, MetadataTraceMixin, InputTraceMixin):
|
||||||
"""
|
"""
|
||||||
Represents a nested dictionary field.
|
Represents a nested dictionary field.
|
||||||
|
|
||||||
|
|
@ -254,7 +256,7 @@ class NestedDictInput(BaseInputMixin, ListableInputMixin):
|
||||||
value: Optional[dict] = {}
|
value: Optional[dict] = {}
|
||||||
|
|
||||||
|
|
||||||
class DictInput(BaseInputMixin, ListableInputMixin):
|
class DictInput(BaseInputMixin, ListableInputMixin, InputTraceMixin):
|
||||||
"""
|
"""
|
||||||
Represents a dictionary field.
|
Represents a dictionary field.
|
||||||
|
|
||||||
|
|
@ -270,7 +272,7 @@ class DictInput(BaseInputMixin, ListableInputMixin):
|
||||||
value: Optional[dict] = {}
|
value: Optional[dict] = {}
|
||||||
|
|
||||||
|
|
||||||
class DropdownInput(BaseInputMixin, DropDownMixin):
|
class DropdownInput(BaseInputMixin, DropDownMixin, MetadataTraceMixin):
|
||||||
"""
|
"""
|
||||||
Represents a dropdown input field.
|
Represents a dropdown input field.
|
||||||
|
|
||||||
|
|
@ -287,7 +289,7 @@ class DropdownInput(BaseInputMixin, DropDownMixin):
|
||||||
options: list[str] = Field(default_factory=list)
|
options: list[str] = Field(default_factory=list)
|
||||||
|
|
||||||
|
|
||||||
class FileInput(BaseInputMixin, ListableInputMixin, FileMixin):
|
class FileInput(BaseInputMixin, ListableInputMixin, FileMixin, MetadataTraceMixin):
|
||||||
"""
|
"""
|
||||||
Represents a file field.
|
Represents a file field.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue