From bdbc46f01ddf06e7c3ad350cad8b02ef02c5633c Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Sun, 11 Jun 2023 18:06:57 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(chat.py):=20add=20exception?= =?UTF-8?q?=20handling=20to=20post=5Fbuild=20endpoint=20=E2=9C=A8=20feat(c?= =?UTF-8?q?ache/=5F=5Finit=5F=5F.py):=20add=20InMemoryCache=20to=20exporte?= =?UTF-8?q?d=20modules=20=F0=9F=94=96=20refactor(endpoints.py):=20remove?= =?UTF-8?q?=20unused=20import=20statement=20The=20post=5Fbuild=20endpoint?= =?UTF-8?q?=20in=20chat.py=20now=20has=20exception=20handling=20to=20catch?= =?UTF-8?q?=20any=20errors=20that=20may=20occur=20during=20the=20build=20p?= =?UTF-8?q?rocess.=20InMemoryCache=20is=20now=20exported=20as=20part=20of?= =?UTF-8?q?=20the=20cache=20module.=20The=20endpoints.py=20file=20has=20be?= =?UTF-8?q?en=20refactored=20to=20remove=20an=20unused=20import=20statemen?= =?UTF-8?q?t.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/chat.py | 12 ++++++++++++ src/backend/langflow/api/v1/endpoints.py | 1 - src/backend/langflow/cache/__init__.py | 8 +++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/backend/langflow/api/v1/chat.py b/src/backend/langflow/api/v1/chat.py index 7df4c65ed..9619d5f30 100644 --- a/src/backend/langflow/api/v1/chat.py +++ b/src/backend/langflow/api/v1/chat.py @@ -1,5 +1,6 @@ from fastapi import ( APIRouter, + HTTPException, WebSocket, WebSocketDisconnect, WebSocketException, @@ -24,3 +25,14 @@ async def websocket_endpoint(client_id: str, websocket: WebSocket): except WebSocketDisconnect as exc: logger.error(exc) await websocket.close(code=status.WS_1000_NORMAL_CLOSURE, reason=str(exc)) + + +@router.post("/build/{client_id}") +async def post_build(client_id: str, graph_data: dict): + """Build langchain object from data_graph.""" + try: + if chat_manager.build(client_id, graph_data.get("data")): + return {"message": "Build successful"} + except Exception as exc: + logger.exception(exc) + raise HTTPException(status_code=500, detail=str(exc)) from exc diff --git a/src/backend/langflow/api/v1/endpoints.py b/src/backend/langflow/api/v1/endpoints.py index 0427eb291..bef1c4d1e 100644 --- a/src/backend/langflow/api/v1/endpoints.py +++ b/src/backend/langflow/api/v1/endpoints.py @@ -1,5 +1,4 @@ import logging -from importlib.metadata import version from fastapi import APIRouter, HTTPException diff --git a/src/backend/langflow/cache/__init__.py b/src/backend/langflow/cache/__init__.py index 583d5ac6d..723aa9e18 100644 --- a/src/backend/langflow/cache/__init__.py +++ b/src/backend/langflow/cache/__init__.py @@ -1 +1,7 @@ -from langflow.cache.manager import cache_manager # noqa +from langflow.cache.manager import cache_manager +from langflow.cache.flow import InMemoryCache + +__all__ = [ + "cache_manager", + "InMemoryCache", +]