refactor: Update field input classes and module structure

This commit is contained in:
ogabrielluiz 2024-06-12 13:54:04 -03:00
commit 8b87c0ef92
5 changed files with 40 additions and 12 deletions

View file

@ -0,0 +1,25 @@
from .inputs import (
BoolInput,
DictInput,
DropdownInput,
FileInput,
FloatInput,
IntInput,
NestedDictInput,
PromptInput,
SecretStrInput,
StrInput,
)
__all__ = [
"SecretStrInput",
"StrInput",
"IntInput",
"FloatInput",
"BoolInput",
"NestedDictInput",
"DictInput",
"DropdownInput",
"FileInput",
"PromptInput",
]

View file

@ -2,7 +2,7 @@ from typing import Callable, Optional, Union
from pydantic import Field from pydantic import Field
from langflow.template.field.input_mixin import ( from .input_mixin import (
BaseInputMixin, BaseInputMixin,
DatabaseLoadMixin, DatabaseLoadMixin,
DropDownMixin, DropDownMixin,
@ -10,50 +10,51 @@ from langflow.template.field.input_mixin import (
FileMixin, FileMixin,
ListableInputMixin, ListableInputMixin,
RangeMixin, RangeMixin,
SerializableFieldTypes,
) )
class PromptInput(BaseInputMixin, ListableInputMixin): class PromptInput(BaseInputMixin, ListableInputMixin):
field_type = 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): # noqa: F821 class StrInput(BaseInputMixin, ListableInputMixin): # noqa: F821
field_type = FieldTypes.TEXT field_type: Optional[SerializableFieldTypes] = FieldTypes.TEXT
multiline: bool = Field(default=False) multiline: bool = Field(default=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."""
class SecretStrInput(BaseInputMixin, DatabaseLoadMixin): class SecretStrInput(BaseInputMixin, DatabaseLoadMixin):
field_type = FieldTypes.PASSWORD field_type: Optional[SerializableFieldTypes] = FieldTypes.PASSWORD
password: bool = Field(default=True) password: bool = Field(default=True)
class IntInput(BaseInputMixin, ListableInputMixin, RangeMixin): class IntInput(BaseInputMixin, ListableInputMixin, RangeMixin):
field_type = FieldTypes.INTEGER field_type: Optional[SerializableFieldTypes] = FieldTypes.INTEGER
class FloatInput(BaseInputMixin, ListableInputMixin, RangeMixin): class FloatInput(BaseInputMixin, ListableInputMixin, RangeMixin):
field_type = FieldTypes.FLOAT field_type: Optional[SerializableFieldTypes] = FieldTypes.FLOAT
class BoolInput(BaseInputMixin, ListableInputMixin): class BoolInput(BaseInputMixin, ListableInputMixin):
field_type = FieldTypes.BOOLEAN field_type: Optional[SerializableFieldTypes] = FieldTypes.BOOLEAN
class NestedDictInput(BaseInputMixin, ListableInputMixin): class NestedDictInput(BaseInputMixin, ListableInputMixin):
field_type = FieldTypes.NESTED_DICT field_type: Optional[SerializableFieldTypes] = FieldTypes.NESTED_DICT
class DictInput(BaseInputMixin, ListableInputMixin): class DictInput(BaseInputMixin, ListableInputMixin):
field_type = FieldTypes.DICT field_type: Optional[SerializableFieldTypes] = FieldTypes.DICT
class DropdownInput(BaseInputMixin, DropDownMixin): class DropdownInput(BaseInputMixin, DropDownMixin):
field_type = FieldTypes.TEXT field_type: Optional[SerializableFieldTypes] = FieldTypes.TEXT
options: Optional[Union[list[str], Callable]] = None options: Optional[Union[list[str], Callable]] = None
"""List of options for the field. Only used when is_list=True. Default is an empty list.""" """List of options for the field. Only used when is_list=True. Default is an empty list."""
class FileInput(BaseInputMixin, ListableInputMixin, FileMixin): class FileInput(BaseInputMixin, ListableInputMixin, FileMixin):
field_type = FieldTypes.FILE field_type: Optional[SerializableFieldTypes] = FieldTypes.FILE

View file

@ -2,6 +2,7 @@ from langflow.template.field.base import Input, Output
from langflow.template.frontend_node.base import FrontendNode from langflow.template.frontend_node.base import FrontendNode
from langflow.template.template.base import Template from langflow.template.template.base import Template
__all__ = [ __all__ = [
"Input", "Input",
"Output", "Output",

View file

@ -2,13 +2,14 @@ from typing import Callable, Union
from pydantic import BaseModel, model_serializer from pydantic import BaseModel, model_serializer
from langflow.inputs.input_mixin import BaseInputMixin
from langflow.template.field.base import Input from langflow.template.field.base import Input
from langflow.utils.constants import DIRECT_TYPES from langflow.utils.constants import DIRECT_TYPES
class Template(BaseModel): class Template(BaseModel):
type_name: str type_name: str
fields: list[Input] fields: list[Input | BaseInputMixin]
def process_fields( def process_fields(
self, self,