From fd36938a03c90f105ea4224642761ea00f157dab Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 9 Jul 2024 15:29:30 -0300 Subject: [PATCH] feat: update custom component attributes on /update endpoint (#2607) feat: Update custom component attributes with load from DB fields This commit updates the `custom_component_update` endpoint in `endpoints.py` to include the logic for updating custom component attributes with load from DB fields. The `cc_instance` is checked for the presence of a `set_attributes` method, and if it exists, the template and parameters are extracted from the code request. The load from DB fields are identified and used to update the parameters. Finally, the `set_attributes` method is called with the updated parameters. This enhancement improves the flexibility and functionality of custom components. --- src/backend/base/langflow/api/v1/endpoints.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/backend/base/langflow/api/v1/endpoints.py b/src/backend/base/langflow/api/v1/endpoints.py index 31d40a5c1..976a27b08 100644 --- a/src/backend/base/langflow/api/v1/endpoints.py +++ b/src/backend/base/langflow/api/v1/endpoints.py @@ -26,6 +26,7 @@ from langflow.custom.utils import build_custom_component_template, get_instance_ from langflow.graph.graph.base import Graph from langflow.graph.schema import RunOutputs from langflow.helpers.flow import get_flow_by_id_or_endpoint_name +from langflow.interface.initialize.loading import update_params_with_load_from_db_fields from langflow.processing.process import process_tweaks, run_graph_internal from langflow.schema.graph import Tweaks from langflow.services.auth.utils import api_key_security, get_current_active_user @@ -555,7 +556,16 @@ async def custom_component_update( component, user_id=user.id, ) - + if hasattr(cc_instance, "set_attributes"): + template = code_request.get_template() + params = {key: value_dict["value"] for key, value_dict in template.items() if isinstance(value_dict, dict)} + load_from_db_fields = [ + field_name + for field_name, field_dict in template.items() + if isinstance(field_dict, dict) and field_dict.get("load_from_db") + ] + params = update_params_with_load_from_db_fields(cc_instance, params, load_from_db_fields) + cc_instance.set_attributes(params) updated_build_config = cc_instance.update_build_config( build_config=code_request.get_template(), field_value=code_request.field_value,