🔨 refactor(endpoints.py): remove unused get_flow_from_token function and HTTPBearer import
🐛 fix(endpoints.py): add check for flow data before processing 🔨 refactor(process.py): add type hints to process_tweaks function The get_flow_from_token function and HTTPBearer import are removed as they are not used in the code. A check for flow data is added before processing to avoid errors when the flow data is None. The process_tweaks function is updated to include type hints for the graph_data and tweaks parameters.
This commit is contained in:
parent
3a3487dc26
commit
f42830ca47
2 changed files with 4 additions and 16 deletions
|
|
@ -3,7 +3,6 @@ from langflow.processing.process import process_graph_cached, process_tweaks
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
from fastapi.security import HTTPBearer
|
|
||||||
|
|
||||||
from langflow.api.v1.schemas import (
|
from langflow.api.v1.schemas import (
|
||||||
PredictRequest,
|
PredictRequest,
|
||||||
|
|
@ -17,20 +16,6 @@ from sqlmodel import Session
|
||||||
# build router
|
# build router
|
||||||
router = APIRouter(tags=["Base"])
|
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")
|
@router.get("/all")
|
||||||
def get_all():
|
def get_all():
|
||||||
|
|
@ -51,6 +36,9 @@ async def predict_flow(
|
||||||
flow = session.get(Flow, flow_id)
|
flow = session.get(Flow, flow_id)
|
||||||
if flow is None:
|
if flow is None:
|
||||||
raise ValueError(f"Flow {flow_id} not found")
|
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
|
graph_data = flow.data
|
||||||
if predict_request.tweaks:
|
if predict_request.tweaks:
|
||||||
graph_data = process_tweaks(graph_data, predict_request.tweaks)
|
graph_data = process_tweaks(graph_data, predict_request.tweaks)
|
||||||
|
|
|
||||||
|
|
@ -172,7 +172,7 @@ def load_flow_from_json(path: str, build=True):
|
||||||
return graph
|
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"""
|
"""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 tweaks dict is a dict of dicts
|
||||||
# the key is the node id and the value is a dict of the tweaks
|
# the key is the node id and the value is a dict of the tweaks
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue