changed regex to replace everything related to the old edges and nodes, changed update_provider_components to get updated flow from langflow

This commit is contained in:
Lucas Oliveira 2025-09-22 13:15:04 -03:00
parent 34add855ca
commit dfd60574d0

View file

@ -313,10 +313,10 @@ class FlowsService:
# Replace embedding ID references # Replace embedding ID references
flow_json_str = re.sub( flow_json_str = re.sub(
r"\b" + re.escape(old_embedding_id) + r"\b", new_embedding_id, flow_json_str re.escape(old_embedding_id), new_embedding_id, flow_json_str
) )
flow_json_str = re.sub( flow_json_str = re.sub(
r"\b" + re.escape(old_embedding_id.split("-")[0]) + r"\b", re.escape(old_embedding_id.split("-")[0]),
new_embedding_id.split("-")[0], new_embedding_id.split("-")[0],
flow_json_str, flow_json_str,
) )
@ -324,10 +324,10 @@ class FlowsService:
# Replace LLM ID references (if applicable) # Replace LLM ID references (if applicable)
if old_llm_id: if old_llm_id:
flow_json_str = re.sub( flow_json_str = re.sub(
r"\b" + re.escape(old_llm_id) + r"\b", new_llm_id, flow_json_str re.escape(old_llm_id), new_llm_id, flow_json_str
) )
flow_json_str = re.sub( flow_json_str = re.sub(
r"\b" + re.escape(old_llm_id.split("-")[0]) + r"\b", re.escape(old_llm_id.split("-")[0]),
new_llm_id.split("-")[0], new_llm_id.split("-")[0],
flow_json_str, flow_json_str,
) )
@ -492,21 +492,19 @@ class FlowsService:
): ):
"""Update provider components and their dropdown values in a flow""" """Update provider components and their dropdown values in a flow"""
flow_name = config["name"] flow_name = config["name"]
flow_file = config["file"]
flow_id = config["flow_id"] flow_id = config["flow_id"]
# Get the project root directory # Get flow data from Langflow API instead of file
current_file_dir = os.path.dirname(os.path.abspath(__file__)) response = await clients.langflow_request(
src_dir = os.path.dirname(current_file_dir) "GET", f"/api/v1/flows/{flow_id}"
project_root = os.path.dirname(src_dir) )
flow_path = os.path.join(project_root, flow_file)
if response.status_code != 200:
if not os.path.exists(flow_path): raise Exception(
raise FileNotFoundError(f"Flow file not found at: {flow_path}") f"Failed to get flow from Langflow: HTTP {response.status_code} - {response.text}"
)
# Load flow JSON
with open(flow_path, "r") as f: flow_data = response.json()
flow_data = json.load(f)
updates_made = [] updates_made = []