From 90a1dd9795ef297a072c9603f6f08eb670d876ce Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 13 Jun 2023 12:49:22 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(process.py):=20refactor=20?= =?UTF-8?q?process=5Ftweaks=20function=20to=20improve=20readability=20and?= =?UTF-8?q?=20maintainability=20The=20process=5Ftweaks=20function=20has=20?= =?UTF-8?q?been=20refactored=20to=20improve=20readability=20and=20maintain?= =?UTF-8?q?ability.=20The=20function=20now=20takes=20in=20two=20parameters?= =?UTF-8?q?,=20graph=5Fdata=20and=20tweaks,=20and=20returns=20the=20modifi?= =?UTF-8?q?ed=20graph=5Fdata.=20The=20tweaks=20parameter=20is=20a=20dictio?= =?UTF-8?q?nary=20of=20dictionaries,=20where=20the=20key=20is=20the=20node?= =?UTF-8?q?=20id=20and=20the=20value=20is=20a=20dictionary=20of=20the=20tw?= =?UTF-8?q?eaks.=20The=20function=20processes=20the=20graph=20data=20to=20?= =?UTF-8?q?add=20the=20tweaks=20by=20iterating=20over=20the=20nodes=20and?= =?UTF-8?q?=20checking=20if=20the=20node=20id=20is=20in=20the=20tweaks=20d?= =?UTF-8?q?ictionary.=20If=20it=20is,=20the=20function=20applies=20the=20t?= =?UTF-8?q?weaks=20to=20the=20node=20by=20updating=20the=20template=20data?= =?UTF-8?q?=20with=20the=20new=20values.=20The=20function=20also=20prints?= =?UTF-8?q?=20a=20message=20to=20the=20console=20to=20indicate=20that=20a?= =?UTF-8?q?=20tweak=20has=20been=20applied.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/processing/process.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/backend/langflow/processing/process.py b/src/backend/langflow/processing/process.py index 3b8852e00..ae0bf28b1 100644 --- a/src/backend/langflow/processing/process.py +++ b/src/backend/langflow/processing/process.py @@ -170,3 +170,25 @@ def load_flow_from_json(path: str, build=True): fix_memory_inputs(langchain_object) return langchain_object return graph + + +def process_tweaks(graph_data: dict, tweaks: dict): + """This function is used to tweak the graph data using the node id and the tweaks dict""" + # the tweaks dict is a dict of dicts + # the key is the node id and the value is a dict of the tweaks + # the dict of tweaks contains the name of a certain parameter and the value to be tweaked + + # We need to process the graph data to add the tweaks + nodes = graph_data["data"]["nodes"] + for node in nodes: + node_id = node["id"] + if node_id in tweaks: + node_tweaks = tweaks[node_id] + template_data = node["data"]["node"]["template"] + for tweak_name, tweake_value in node_tweaks.items(): + if tweak_name in template_data: + template_data[tweak_name]["value"] = tweake_value + print( + f"Something changed in node {node_id} with tweak {tweak_name} and value {tweake_value}" + ) + return graph_data