From fe0c6f7f385d9b017339d0a2427e4e7b885500ff Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 12 Jun 2023 17:04:52 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(chat.py):=20rename=20websock?= =?UTF-8?q?et=5Fendpoint=20to=20chat=20for=20better=20semantics=20?= =?UTF-8?q?=E2=9C=A8=20feat(chat.py):=20add=20build=5Fstatus=20endpoint=20?= =?UTF-8?q?to=20check=20if=20flow=5Fid=20is=20in=20flow=5Fdata=5Fstore=20T?= =?UTF-8?q?he=20function=20name=20websocket=5Fendpoint=20was=20renamed=20t?= =?UTF-8?q?o=20chat=20to=20improve=20semantics.=20The=20new=20build=5Fstat?= =?UTF-8?q?us=20endpoint=20was=20added=20to=20check=20if=20a=20flow=5Fid?= =?UTF-8?q?=20is=20in=20the=20flow=5Fdata=5Fstore.=20This=20endpoint=20ret?= =?UTF-8?q?urns=20a=20JSON=20response=20with=20a=20boolean=20value=20indic?= =?UTF-8?q?ating=20whether=20the=20flow=5Fid=20is=20built=20or=20not.=20If?= =?UTF-8?q?=20the=20flow=5Fid=20is=20not=20in=20the=20flow=5Fdata=5Fstore,?= =?UTF-8?q?=20a=20JSON=20response=20with=20a=20value=20of=20False=20is=20r?= =?UTF-8?q?eturned.=20If=20an=20exception=20occurs,=20a=20500=20HTTPExcept?= =?UTF-8?q?ion=20is=20raised=20with=20the=20exception=20message=20as=20the?= =?UTF-8?q?=20detail.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/chat.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/api/v1/chat.py b/src/backend/langflow/api/v1/chat.py index 4d9d85a58..eccfde71a 100644 --- a/src/backend/langflow/api/v1/chat.py +++ b/src/backend/langflow/api/v1/chat.py @@ -1,6 +1,7 @@ import json from fastapi import ( APIRouter, + HTTPException, WebSocket, WebSocketDisconnect, WebSocketException, @@ -18,7 +19,7 @@ flow_data_store = {} @router.websocket("/chat/{client_id}") -async def websocket_endpoint(client_id: str, websocket: WebSocket): +async def chat(client_id: str, websocket: WebSocket): """Websocket endpoint for chat.""" try: if client_id in chat_manager.in_memory_cache: @@ -45,6 +46,19 @@ async def init_build(graph_data: dict): return JSONResponse(content={"flowId": flow_id}) +@router.get("/build/{flow_id}/status") +async def build_status(flow_id: str): + """Check the flow_id is in the flow_data_store.""" + try: + if flow_id in flow_data_store: + return JSONResponse(content={"built": True}) + else: + return JSONResponse(content={"built": False}) + except Exception as exc: + logger.error(exc) + return HTTPException(status_code=500, detail=str(exc)) + + @router.get("/build/stream/{flow_id}", response_class=StreamingResponse) async def stream_build(flow_id: str): """Stream the build process based on stored flow data."""