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.
This commit is contained in:
parent
06464eda46
commit
fd36938a03
1 changed files with 11 additions and 1 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue