Add pinned state to CustomComponent and FrontendNode

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-02-22 11:57:15 -03:00
commit 16018c1d6f
2 changed files with 19 additions and 1 deletions

View file

@ -6,6 +6,7 @@ from uuid import UUID
import yaml import yaml
from cachetools import TTLCache, cachedmethod from cachetools import TTLCache, cachedmethod
from fastapi import HTTPException from fastapi import HTTPException
from langflow.interface.custom.code_parser.utils import ( from langflow.interface.custom.code_parser.utils import (
extract_inner_type_from_generic_alias, extract_inner_type_from_generic_alias,
extract_union_types_from_generic_alias, extract_union_types_from_generic_alias,
@ -35,6 +36,8 @@ class CustomComponent(Component):
"""The field configuration of the component. Defaults to an empty dictionary.""" """The field configuration of the component. Defaults to an empty dictionary."""
field_order: Optional[List[str]] = None field_order: Optional[List[str]] = None
"""The field order of the component. Defaults to an empty list.""" """The field order of the component. Defaults to an empty list."""
pinned: Optional[bool] = False
"""The default pinned state of the component. Defaults to False."""
code_class_base_inheritance: ClassVar[str] = "CustomComponent" code_class_base_inheritance: ClassVar[str] = "CustomComponent"
function_entrypoint_name: ClassVar[str] = "build" function_entrypoint_name: ClassVar[str] = "build"
function: Optional[Callable] = None function: Optional[Callable] = None

View file

@ -2,6 +2,8 @@ import re
from collections import defaultdict from collections import defaultdict
from typing import ClassVar, Dict, List, Optional, Union from typing import ClassVar, Dict, List, Optional, Union
from pydantic import BaseModel, Field, field_serializer, model_serializer
from langflow.template.field.base import TemplateField from langflow.template.field.base import TemplateField
from langflow.template.frontend_node.constants import ( from langflow.template.frontend_node.constants import (
CLASSES_TO_REMOVE, CLASSES_TO_REMOVE,
@ -10,7 +12,6 @@ from langflow.template.frontend_node.constants import (
from langflow.template.frontend_node.formatter import field_formatters from langflow.template.frontend_node.formatter import field_formatters
from langflow.template.template.base import Template from langflow.template.template.base import Template
from langflow.utils import constants from langflow.utils import constants
from pydantic import BaseModel, Field, field_serializer, model_serializer
class FieldFormatters(BaseModel): class FieldFormatters(BaseModel):
@ -44,17 +45,31 @@ class FieldFormatters(BaseModel):
class FrontendNode(BaseModel): class FrontendNode(BaseModel):
_format_template: bool = True _format_template: bool = True
template: Template template: Template
"""Template for the frontend node."""
description: Optional[str] = None description: Optional[str] = None
"""Description of the frontend node."""
icon: Optional[str] = None icon: Optional[str] = None
"""Icon of the frontend node."""
is_composition: Optional[bool] = None is_composition: Optional[bool] = None
"""Whether the frontend node is used for composition."""
base_classes: List[str] base_classes: List[str]
"""List of base classes for the frontend node."""
name: str = "" name: str = ""
"""Name of the frontend node."""
display_name: Optional[str] = "" display_name: Optional[str] = ""
"""Display name of the frontend node."""
documentation: str = "" documentation: str = ""
"""Documentation of the frontend node."""
custom_fields: Optional[Dict] = defaultdict(list) custom_fields: Optional[Dict] = defaultdict(list)
"""Custom fields of the frontend node."""
output_types: List[str] = [] output_types: List[str] = []
"""List of output types for the frontend node."""
full_path: Optional[str] = None full_path: Optional[str] = None
"""Full path of the frontend node."""
field_formatters: FieldFormatters = Field(default_factory=FieldFormatters) field_formatters: FieldFormatters = Field(default_factory=FieldFormatters)
"""Field formatters for the frontend node."""
pinned: bool = False
"""Whether the frontend node is pinned."""
beta: bool = False beta: bool = False
error: Optional[str] = None error: Optional[str] = None