refactor: Update post_code_validation method in Component class

Refactor the post_code_validation method in the Component class to improve code readability and maintainability. The changes include:

- Rename the parameters to better reflect their purpose.
- Update the function documentation to provide a clear explanation of the method's purpose.
- Remove unnecessary comments and whitespace.
- Improve variable naming for better clarity.

These changes enhance the overall quality of the code and make it easier to understand and maintain.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-06-22 18:00:32 -03:00
commit 95d666636b
2 changed files with 12 additions and 3 deletions

View file

@ -8,7 +8,6 @@ from fastapi import APIRouter, BackgroundTasks, Body, Depends, HTTPException, Re
from loguru import logger from loguru import logger
from sqlmodel import Session, select from sqlmodel import Session, select
from langflow.api.utils import update_frontend_node_with_template_values
from langflow.api.v1.schemas import ( from langflow.api.v1.schemas import (
ConfigResponse, ConfigResponse,
CustomComponentRequest, CustomComponentRequest,
@ -466,9 +465,9 @@ async def custom_component(
): ):
component = Component(code=raw_code.code) component = Component(code=raw_code.code)
built_frontend_node, _ = build_custom_component_template(component, user_id=user.id) built_frontend_node, component_instance = build_custom_component_template(component, user_id=user.id)
built_frontend_node = update_frontend_node_with_template_values(built_frontend_node, raw_code.frontend_node) built_frontend_node = component_instance.post_code_validation(built_frontend_node, raw_code.frontend_node)
return built_frontend_node return built_frontend_node

View file

@ -10,6 +10,7 @@ from langflow.schema.artifact import get_artifact_type, post_process_raw
from langflow.schema.data import Data from langflow.schema.data import Data
from langflow.schema.message import Message from langflow.schema.message import Message
from langflow.template.field.base import UNDEFINED, Output from langflow.template.field.base import UNDEFINED, Output
from langflow.template.utils import update_frontend_node_with_template_values
from .custom_component import CustomComponent from .custom_component import CustomComponent
@ -224,3 +225,12 @@ class Component(CustomComponent):
def build(self, **kwargs): def build(self, **kwargs):
self.set_attributes(kwargs) self.set_attributes(kwargs)
def post_code_validation(self, new_build_config: dict, current_build_config: dict):
"""
This function is called after the code validation is done.
"""
frontend_node = update_frontend_node_with_template_values(
frontend_node=new_build_config, raw_frontend_node=current_build_config
)
return frontend_node