Refactor code and fix custom_fields bug

This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-11-30 15:42:41 -03:00
commit 98d1eecd40
2 changed files with 13 additions and 13 deletions

View file

@ -1,15 +1,10 @@
from fastapi import APIRouter, HTTPException from fastapi import APIRouter, HTTPException
from langflow.api.v1.base import (Code, CodeValidationResponse,
from langflow.api.v1.base import ( PromptValidationResponse,
Code, ValidatePromptRequest, validate_prompt)
CodeValidationResponse,
ValidatePromptRequest,
PromptValidationResponse,
validate_prompt,
)
from langflow.template.field.base import TemplateField from langflow.template.field.base import TemplateField
from loguru import logger
from langflow.utils.validate import validate_code from langflow.utils.validate import validate_code
from loguru import logger
# build router # build router
router = APIRouter(prefix="/validate", tags=["Validate"]) router = APIRouter(prefix="/validate", tags=["Validate"])
@ -61,7 +56,11 @@ def get_old_custom_fields(prompt_request):
# then we are dealing with the first prompt request after the node was created # then we are dealing with the first prompt request after the node was created
prompt_request.name = list(prompt_request.frontend_node.custom_fields.keys())[0] prompt_request.name = list(prompt_request.frontend_node.custom_fields.keys())[0]
old_custom_fields = prompt_request.frontend_node.custom_fields[prompt_request.name].copy() old_custom_fields = prompt_request.frontend_node.custom_fields[prompt_request.name]
if old_custom_fields is None:
old_custom_fields = []
old_custom_fields = old_custom_fields.copy()
except KeyError: except KeyError:
old_custom_fields = [] old_custom_fields = []
prompt_request.frontend_node.custom_fields[prompt_request.name] = [] prompt_request.frontend_node.custom_fields[prompt_request.name] = []

View file

@ -1,9 +1,10 @@
import re import re
from collections import defaultdict from collections import defaultdict
from typing import ClassVar, DefaultDict, Dict, List, Optional from typing import ClassVar, Dict, List, Optional
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
@ -45,7 +46,7 @@ class FrontendNode(BaseModel):
name: str = "" name: str = ""
display_name: str = "" display_name: str = ""
documentation: str = "" documentation: str = ""
custom_fields: Optional[DefaultDict[str, List[str]]] = defaultdict(list) custom_fields: Optional[Dict] = defaultdict(list)
output_types: List[str] = [] output_types: List[str] = []
full_path: Optional[str] = None full_path: Optional[str] = None
field_formatters: FieldFormatters = Field(default_factory=FieldFormatters) field_formatters: FieldFormatters = Field(default_factory=FieldFormatters)