Add is_composition to FrontendNode
This commit is contained in:
parent
17dee05b78
commit
0aad733e39
1 changed files with 31 additions and 8 deletions
|
|
@ -3,7 +3,10 @@ from collections import defaultdict
|
||||||
from typing import ClassVar, Dict, List, Optional, Union
|
from typing import ClassVar, Dict, List, Optional, Union
|
||||||
|
|
||||||
from langflow.template.field.base import TemplateField
|
from langflow.template.field.base import TemplateField
|
||||||
from langflow.template.frontend_node.constants import CLASSES_TO_REMOVE, FORCE_SHOW_FIELDS
|
from langflow.template.frontend_node.constants import (
|
||||||
|
CLASSES_TO_REMOVE,
|
||||||
|
FORCE_SHOW_FIELDS,
|
||||||
|
)
|
||||||
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
|
||||||
|
|
@ -43,6 +46,7 @@ class FrontendNode(BaseModel):
|
||||||
template: Template
|
template: Template
|
||||||
description: Optional[str] = None
|
description: Optional[str] = None
|
||||||
icon: Optional[str] = None
|
icon: Optional[str] = None
|
||||||
|
is_composition: Optional[bool] = None
|
||||||
base_classes: List[str]
|
base_classes: List[str]
|
||||||
name: str = ""
|
name: str = ""
|
||||||
display_name: Optional[str] = ""
|
display_name: Optional[str] = ""
|
||||||
|
|
@ -69,7 +73,11 @@ class FrontendNode(BaseModel):
|
||||||
def process_base_classes(self, base_classes: List[str]) -> List[str]:
|
def process_base_classes(self, base_classes: List[str]) -> List[str]:
|
||||||
"""Removes unwanted base classes from the list of base classes."""
|
"""Removes unwanted base classes from the list of base classes."""
|
||||||
|
|
||||||
return [base_class for base_class in base_classes if base_class not in CLASSES_TO_REMOVE]
|
return [
|
||||||
|
base_class
|
||||||
|
for base_class in base_classes
|
||||||
|
if base_class not in CLASSES_TO_REMOVE
|
||||||
|
]
|
||||||
|
|
||||||
@field_serializer("display_name")
|
@field_serializer("display_name")
|
||||||
def process_display_name(self, display_name: str) -> str:
|
def process_display_name(self, display_name: str) -> str:
|
||||||
|
|
@ -149,7 +157,9 @@ class FrontendNode(BaseModel):
|
||||||
return _type
|
return _type
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def handle_special_field(field, key: str, _type: str, SPECIAL_FIELD_HANDLERS) -> str:
|
def handle_special_field(
|
||||||
|
field, key: str, _type: str, SPECIAL_FIELD_HANDLERS
|
||||||
|
) -> str:
|
||||||
"""Handles special field by using the respective handler if present."""
|
"""Handles special field by using the respective handler if present."""
|
||||||
handler = SPECIAL_FIELD_HANDLERS.get(key)
|
handler = SPECIAL_FIELD_HANDLERS.get(key)
|
||||||
return handler(field) if handler else _type
|
return handler(field) if handler else _type
|
||||||
|
|
@ -160,7 +170,11 @@ class FrontendNode(BaseModel):
|
||||||
if "dict" in _type.lower() and field.name == "dict_":
|
if "dict" in _type.lower() and field.name == "dict_":
|
||||||
field.field_type = "file"
|
field.field_type = "file"
|
||||||
field.file_types = [".json", ".yaml", ".yml"]
|
field.file_types = [".json", ".yaml", ".yml"]
|
||||||
elif _type.startswith("Dict") or _type.startswith("Mapping") or _type.startswith("dict"):
|
elif (
|
||||||
|
_type.startswith("Dict")
|
||||||
|
or _type.startswith("Mapping")
|
||||||
|
or _type.startswith("dict")
|
||||||
|
):
|
||||||
field.field_type = "dict"
|
field.field_type = "dict"
|
||||||
return _type
|
return _type
|
||||||
|
|
||||||
|
|
@ -171,7 +185,9 @@ class FrontendNode(BaseModel):
|
||||||
field.value = value["default"]
|
field.value = value["default"]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def handle_specific_field_values(field: TemplateField, key: str, name: Optional[str] = None) -> None:
|
def handle_specific_field_values(
|
||||||
|
field: TemplateField, key: str, name: Optional[str] = None
|
||||||
|
) -> None:
|
||||||
"""Handles specific field values for certain fields."""
|
"""Handles specific field values for certain fields."""
|
||||||
if key == "headers":
|
if key == "headers":
|
||||||
field.value = """{"Authorization": "Bearer <token>"}"""
|
field.value = """{"Authorization": "Bearer <token>"}"""
|
||||||
|
|
@ -179,7 +195,9 @@ class FrontendNode(BaseModel):
|
||||||
FrontendNode._handle_api_key_specific_field_values(field, key, name)
|
FrontendNode._handle_api_key_specific_field_values(field, key, name)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _handle_model_specific_field_values(field: TemplateField, key: str, name: Optional[str] = None) -> None:
|
def _handle_model_specific_field_values(
|
||||||
|
field: TemplateField, key: str, name: Optional[str] = None
|
||||||
|
) -> None:
|
||||||
"""Handles specific field values related to models."""
|
"""Handles specific field values related to models."""
|
||||||
model_dict = {
|
model_dict = {
|
||||||
"OpenAI": constants.OPENAI_MODELS,
|
"OpenAI": constants.OPENAI_MODELS,
|
||||||
|
|
@ -192,7 +210,9 @@ class FrontendNode(BaseModel):
|
||||||
field.is_list = True
|
field.is_list = True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _handle_api_key_specific_field_values(field: TemplateField, key: str, name: Optional[str] = None) -> None:
|
def _handle_api_key_specific_field_values(
|
||||||
|
field: TemplateField, key: str, name: Optional[str] = None
|
||||||
|
) -> None:
|
||||||
"""Handles specific field values related to API keys."""
|
"""Handles specific field values related to API keys."""
|
||||||
if "api_key" in key and "OpenAI" in str(name):
|
if "api_key" in key and "OpenAI" in str(name):
|
||||||
field.display_name = "OpenAI API Key"
|
field.display_name = "OpenAI API Key"
|
||||||
|
|
@ -232,7 +252,10 @@ class FrontendNode(BaseModel):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def should_be_password(key: str, show: bool) -> bool:
|
def should_be_password(key: str, show: bool) -> bool:
|
||||||
"""Determines whether the field should be a password field."""
|
"""Determines whether the field should be a password field."""
|
||||||
return any(text in key.lower() for text in {"password", "token", "api", "key"}) and show
|
return (
|
||||||
|
any(text in key.lower() for text in {"password", "token", "api", "key"})
|
||||||
|
and show
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def should_be_multiline(key: str) -> bool:
|
def should_be_multiline(key: str) -> bool:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue