From 173db54a4dcd029ab8b61e8e97bcdf777c5baaa9 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 28 Nov 2023 23:00:48 -0300 Subject: [PATCH] Fix field value replacement in build_input_keys_response function --- src/backend/langflow/api/utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/backend/langflow/api/utils.py b/src/backend/langflow/api/utils.py index 42ed4aa68..2a3c4c36c 100644 --- a/src/backend/langflow/api/utils.py +++ b/src/backend/langflow/api/utils.py @@ -47,3 +47,17 @@ def build_input_keys_response(langchain_object, artifacts): input_keys_response["template"] = langchain_object.prompt.template return input_keys_response + +def replace_existing_field_values(built_frontend_node, raw_code): + if built_frontend_node and "template" in built_frontend_node and raw_code.template is not None: + # Run over the template and replace the values + for key, value_dict in raw_code.template.items(): + if key in ["code"] or not isinstance(value_dict, dict): + continue + value = value_dict.get("value") + if value is None: + continue + # template is a dict and all the values are dicts + if key in built_frontend_node["template"]: + built_frontend_node["template"][key]["value"] = value + return built_frontend_node \ No newline at end of file