From 008a1c40791310105c653e2e479afc9f1da6f412 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Sun, 9 Jul 2023 18:02:12 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(types.py):=20replace=20eval(?= =?UTF-8?q?)=20with=20ast.literal=5Feval()=20to=20safely=20evaluate=20head?= =?UTF-8?q?ers=20parameter=20as=20dictionary-like=20string=20=F0=9F=90=9B?= =?UTF-8?q?=20fix(process.py):=20rename=20input=20parameter=20to=20flow=20?= =?UTF-8?q?for=20clarity=20and=20to=20avoid=20shadowing=20built-in=20funct?= =?UTF-8?q?ion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/graph/vertex/types.py | 3 ++- src/backend/langflow/processing/process.py | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/backend/langflow/graph/vertex/types.py b/src/backend/langflow/graph/vertex/types.py index 2bebc1383..6d9a28356 100644 --- a/src/backend/langflow/graph/vertex/types.py +++ b/src/backend/langflow/graph/vertex/types.py @@ -1,3 +1,4 @@ +import ast from typing import Any, Dict, List, Optional, Union from langflow.graph.vertex.base import Vertex @@ -79,7 +80,7 @@ class WrapperVertex(Vertex): def build(self, force: bool = False) -> Any: if not self._built or force: if "headers" in self.params: - self.params["headers"] = eval(self.params["headers"]) + self.params["headers"] = ast.literal_eval(self.params["headers"]) self._build() return self._built_object diff --git a/src/backend/langflow/processing/process.py b/src/backend/langflow/processing/process.py index 1b219fe11..d4d7b8a26 100644 --- a/src/backend/langflow/processing/process.py +++ b/src/backend/langflow/processing/process.py @@ -123,23 +123,23 @@ def process_graph_cached(data_graph: Dict[str, Any], inputs: Optional[dict] = No def load_flow_from_json( - input: Union[Path, str, dict], tweaks: Optional[dict] = None, build=True + flow: Union[Path, str, dict], tweaks: Optional[dict] = None, build=True ): """ Load flow from a JSON file or a JSON object. - :param input: JSON file path or JSON object + :param flow: JSON file path or JSON object :param tweaks: Optional tweaks to be processed :param build: If True, build the graph, otherwise return the graph object :return: Langchain object or Graph object depending on the build parameter """ # If input is a file path, load JSON from the file - if isinstance(input, (str, Path)): - with open(input, "r", encoding="utf-8") as f: + if isinstance(flow, (str, Path)): + with open(flow, "r", encoding="utf-8") as f: flow_graph = json.load(f) # If input is a dictionary, assume it's a JSON object - elif isinstance(input, dict): - flow_graph = input + elif isinstance(flow, dict): + flow_graph = flow else: raise TypeError( "Input must be either a file path (str) or a JSON object (dict)"