From f42830ca47bf586606468f6e3e88a62fe0f64f35 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 16 Jun 2023 14:56:00 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20refactor(endpoints.py):=20remove?= =?UTF-8?q?=20unused=20get=5Fflow=5Ffrom=5Ftoken=20function=20and=20HTTPBe?= =?UTF-8?q?arer=20import=20=F0=9F=90=9B=20fix(endpoints.py):=20add=20check?= =?UTF-8?q?=20for=20flow=20data=20before=20processing=20=F0=9F=94=A8=20ref?= =?UTF-8?q?actor(process.py):=20add=20type=20hints=20to=20process=5Ftweaks?= =?UTF-8?q?=20function=20The=20get=5Fflow=5Ffrom=5Ftoken=20function=20and?= =?UTF-8?q?=20HTTPBearer=20import=20are=20removed=20as=20they=20are=20not?= =?UTF-8?q?=20used=20in=20the=20code.=20A=20check=20for=20flow=20data=20is?= =?UTF-8?q?=20added=20before=20processing=20to=20avoid=20errors=20when=20t?= =?UTF-8?q?he=20flow=20data=20is=20None.=20The=20process=5Ftweaks=20functi?= =?UTF-8?q?on=20is=20updated=20to=20include=20type=20hints=20for=20the=20g?= =?UTF-8?q?raph=5Fdata=20and=20tweaks=20parameters.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/endpoints.py | 18 +++--------------- src/backend/langflow/processing/process.py | 2 +- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/backend/langflow/api/v1/endpoints.py b/src/backend/langflow/api/v1/endpoints.py index f03c4990a..e6bb08a12 100644 --- a/src/backend/langflow/api/v1/endpoints.py +++ b/src/backend/langflow/api/v1/endpoints.py @@ -3,7 +3,6 @@ from langflow.processing.process import process_graph_cached, process_tweaks from langflow.utils.logger import logger from fastapi import APIRouter, Depends, HTTPException -from fastapi.security import HTTPBearer from langflow.api.v1.schemas import ( PredictRequest, @@ -17,20 +16,6 @@ from sqlmodel import Session # build router router = APIRouter(tags=["Base"]) -security = HTTPBearer() - - -def get_flow_from_token( - bearer: HTTPBearer = Depends(security), session: Session = Depends(get_session) -) -> str: - # Extract the token, which is the flow_id in this case - flow_id = bearer.credentials - # Check if the flow_id exists in the database - flow = session.get(Flow, flow_id) - if flow is None: - raise HTTPException(status_code=401, detail="Invalid token") - return flow - @router.get("/all") def get_all(): @@ -51,6 +36,9 @@ async def predict_flow( flow = session.get(Flow, flow_id) if flow is None: raise ValueError(f"Flow {flow_id} not found") + + if flow.data is None: + raise ValueError(f"Flow {flow_id} has no data") graph_data = flow.data if predict_request.tweaks: graph_data = process_tweaks(graph_data, predict_request.tweaks) diff --git a/src/backend/langflow/processing/process.py b/src/backend/langflow/processing/process.py index ae0bf28b1..deabe34dc 100644 --- a/src/backend/langflow/processing/process.py +++ b/src/backend/langflow/processing/process.py @@ -172,7 +172,7 @@ def load_flow_from_json(path: str, build=True): return graph -def process_tweaks(graph_data: dict, tweaks: dict): +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