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}`, {