refactor: Update post_code_processing method in CustomComponent class

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

- Import the update_frontend_node_with_template_values function from langflow.template.utils.
- Update the function signature to accept new_build_config and current_build_config as parameters.
- Call the update_frontend_node_with_template_values function to update the frontend_node with any values set in the current_build_config.
- Remove unnecessary comments and whitespace.

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-23 01:52:55 -03:00
commit 22839ee270
3 changed files with 12 additions and 11 deletions

View file

@ -466,8 +466,8 @@ async def custom_component(
component = Component(code=raw_code.code)
built_frontend_node, component_instance = build_custom_component_template(component, user_id=user.id)
built_frontend_node = component_instance.post_code_processing(built_frontend_node, raw_code.frontend_node)
if raw_code.frontend_node is not None:
built_frontend_node = component_instance.post_code_processing(built_frontend_node, raw_code.frontend_node)
return built_frontend_node

View file

@ -225,12 +225,3 @@ class Component(CustomComponent):
def build(self, **kwargs):
self.set_attributes(kwargs)
def post_code_processing(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

View file

@ -17,6 +17,7 @@ from langflow.schema.schema import OutputLog
from langflow.services.deps import get_storage_service, get_variable_service, session_scope
from langflow.services.storage.service import StorageService
from langflow.services.tracing.schema import Log
from langflow.template.utils import update_frontend_node_with_template_values
from langflow.type_extraction.type_extraction import (
extract_inner_type_from_generic_alias,
extract_union_types_from_generic_alias,
@ -495,3 +496,12 @@ class CustomComponent(BaseComponent):
self._logs.append(log)
if self.vertex:
self._tracing_service.add_log(trace_name=self.vertex.id, log=log)
def post_code_processing(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