🐛 fix(chat.py): add exception handling to post_build endpoint

 feat(cache/__init__.py): add InMemoryCache to exported modules
🔖 refactor(endpoints.py): remove unused import statement
The post_build endpoint in chat.py now has exception handling to catch any errors that may occur during the build process. InMemoryCache is now exported as part of the cache module. The endpoints.py file has been refactored to remove an unused import statement.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-11 18:06:57 -03:00
commit bdbc46f01d
3 changed files with 19 additions and 2 deletions

View file

@ -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

View file

@ -1,5 +1,4 @@
import logging
from importlib.metadata import version
from fastapi import APIRouter, HTTPException

View file

@ -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",
]