From 85b7ff1d31ef6f17c54a47c23ce2d8b7785f65b8 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 28 Jun 2023 22:45:37 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(chat.py):=20update=20init?= =?UTF-8?q?=5Fbuild=20endpoint=20to=20include=20flow=5Fid=20as=20a=20path?= =?UTF-8?q?=20parameter=20The=20unnecessary=20imports=20have=20been=20remo?= =?UTF-8?q?ved=20from=20the=20chat.py=20file=20to=20improve=20code=20clean?= =?UTF-8?q?liness=20and=20readability.=20The=20init=5Fbuild=20endpoint=20i?= =?UTF-8?q?n=20the=20chat.py=20file=20has=20been=20updated=20to=20include?= =?UTF-8?q?=20the=20flow=5Fid=20as=20a=20path=20parameter=20instead=20of?= =?UTF-8?q?=20extracting=20it=20from=20the=20graph=5Fdata=20dictionary.=20?= =?UTF-8?q?This=20change=20allows=20for=20a=20more=20explicit=20and=20cons?= =?UTF-8?q?istent=20API=20design.=20=F0=9F=94=A7=20chore(chat.py):=20remov?= =?UTF-8?q?e=20unnecessary=20imports=20and=20reformat=20code=20for=20bette?= =?UTF-8?q?r=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/chat.py | 18 +++++++----------- src/frontend/src/controllers/API/index.ts | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/backend/langflow/api/v1/chat.py b/src/backend/langflow/api/v1/chat.py index b992afe9a..fd0232189 100644 --- a/src/backend/langflow/api/v1/chat.py +++ b/src/backend/langflow/api/v1/chat.py @@ -1,10 +1,4 @@ -from fastapi import ( - APIRouter, - HTTPException, - WebSocket, - WebSocketException, - status, -) +from fastapi import APIRouter, HTTPException, WebSocket, WebSocketException, status from fastapi.responses import StreamingResponse from langflow.api.v1.schemas import BuildStatus, BuiltResponse, InitResponse, StreamData @@ -32,16 +26,18 @@ async def chat(client_id: str, websocket: WebSocket): await websocket.close(code=status.WS_1011_INTERNAL_ERROR, reason=str(exc)) -@router.post("/build/init", response_model=InitResponse, status_code=201) -async def init_build(graph_data: dict): +@router.post("/build/init/{flow_id}", response_model=InitResponse, status_code=201) +async def init_build(graph_data: dict, flow_id: str): """Initialize the build by storing graph data and returning a unique session ID.""" try: - flow_id = graph_data.get("id") if flow_id is None: raise ValueError("No ID provided") # Check if already building - if flow_id in flow_data_store and flow_data_store[flow_id].get("building"): + if ( + flow_id in flow_data_store + and flow_data_store[flow_id]["status"] == BuildStatus.IN_PROGRESS + ): return InitResponse(flowId=flow_id) # Delete from cache if already exists diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts index 2651a0058..cfae748d8 100644 --- a/src/frontend/src/controllers/API/index.ts +++ b/src/frontend/src/controllers/API/index.ts @@ -311,7 +311,7 @@ export async function getBuildStatus( export async function postBuildInit( flow: FlowType ): Promise> { - return await axios.post(`/api/v1/build/init`, flow); + return await axios.post(`/api/v1/build/init/${flow.id}`, flow); } // fetch(`/upload/${id}`, {