🔧 chore(process.py): refactor process_tweaks function to improve readability and maintainability
The process_tweaks function has been refactored to improve readability and maintainability. The function now takes in two parameters, graph_data and tweaks, and returns the modified graph_data. The tweaks parameter is a dictionary of dictionaries, where the key is the node id and the value is a dictionary of the tweaks. The function processes the graph data to add the tweaks by iterating over the nodes and checking if the node id is in the tweaks dictionary. If it is, the function applies the tweaks to the node by updating the template data with the new values. The function also prints a message to the console to indicate that a tweak has been applied.
This commit is contained in:
parent
faf44eca0e
commit
90a1dd9795
1 changed files with 22 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue