🔀 refactor(base.py): import field_formatters module instead of importing specific module
🔀 refactor(base.py): move FieldFormatters class to the top of the file for better organization
The import statement in the base.py file has been updated to import the field_formatters module instead of importing specific modules. This change improves maintainability and readability by reducing the number of import statements and consolidating them into a single import. Additionally, the FieldFormatters class has been moved to the top of the file for better organization and readability.
This commit is contained in:
parent
d0217f0c26
commit
3bab730e65
1 changed files with 29 additions and 2 deletions
|
|
@ -3,7 +3,7 @@ from typing import List, Optional
|
|||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from langflow.template.frontend_node.formatter.field_formatters import FieldFormatters
|
||||
from langflow.template.frontend_node.formatter import field_formatters
|
||||
from langflow.template.frontend_node.constants import FORCE_SHOW_FIELDS
|
||||
from langflow.template.field.base import TemplateField
|
||||
from langflow.template.template.base import Template
|
||||
|
|
@ -12,6 +12,34 @@ from langflow.utils import constants
|
|||
CLASSES_TO_REMOVE = ["Serializable", "BaseModel", "object"]
|
||||
|
||||
|
||||
class FieldFormatters(BaseModel):
|
||||
formatters = {
|
||||
"openai_api_key": field_formatters.OpenAIAPIKeyFormatter(),
|
||||
}
|
||||
base_formatters = {
|
||||
"kwargs": field_formatters.KwargsFormatter(),
|
||||
"optional": field_formatters.RemoveOptionalFormatter(),
|
||||
"list": field_formatters.ListTypeFormatter(),
|
||||
"dict": field_formatters.DictTypeFormatter(),
|
||||
"union": field_formatters.UnionTypeFormatter(),
|
||||
"multiline": field_formatters.MultilineFieldFormatter(),
|
||||
"show": field_formatters.ShowFieldFormatter(),
|
||||
"password": field_formatters.PasswordFieldFormatter(),
|
||||
"default": field_formatters.DefaultValueFormatter(),
|
||||
"headers": field_formatters.HeadersDefaultValueFormatter(),
|
||||
"dict_code_file": field_formatters.DictCodeFileFormatter(),
|
||||
"model_fields": field_formatters.ModelSpecificFieldFormatter(),
|
||||
}
|
||||
|
||||
def format(self, field: TemplateField, name: Optional[str] = None) -> None:
|
||||
for key, formatter in self.base_formatters.items():
|
||||
formatter.format(field, name)
|
||||
|
||||
for key, formatter in self.formatters.items():
|
||||
if key == field.name:
|
||||
formatter.format(field, name)
|
||||
|
||||
|
||||
class FrontendNode(BaseModel):
|
||||
template: Template
|
||||
description: str
|
||||
|
|
@ -41,7 +69,6 @@ class FrontendNode(BaseModel):
|
|||
"""Sets the documentation of the frontend node."""
|
||||
self.documentation = documentation
|
||||
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
"""Returns a dict representation of the frontend node."""
|
||||
self.process_base_classes()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue