✨ feat(chat.py): use LRUCache from cachetools to limit the size of flow_data_store
The cachetools package is added as a dependency to improve caching. In chat.py, a ValueError is raised if no ID is provided in init_build to prevent errors. The flow_data_store dictionary is replaced with an LRUCache from cachetools to limit the size of the cache to 10 items. This improves performance by reducing the memory usage of the application. 📦 chore(pyproject.toml): add cachetools dependency to improve caching 🐛 fix(chat.py): raise ValueError if no ID is provided in init_build
This commit is contained in:
parent
f42830ca47
commit
deb056df32
3 changed files with 6 additions and 3 deletions
|
|
@ -12,10 +12,11 @@ from langflow.api.v1.schemas import BuiltResponse, InitResponse
|
|||
from langflow.chat.manager import ChatManager
|
||||
from langflow.graph.graph.base import Graph
|
||||
from langflow.utils.logger import logger
|
||||
from cachetools import LRUCache
|
||||
|
||||
router = APIRouter(tags=["Chat"])
|
||||
chat_manager = ChatManager()
|
||||
flow_data_store = {}
|
||||
flow_data_store = LRUCache(maxsize=10)
|
||||
|
||||
|
||||
@router.websocket("/chat/{client_id}")
|
||||
|
|
@ -38,7 +39,8 @@ async def init_build(graph_data: dict):
|
|||
|
||||
try:
|
||||
flow_id = graph_data.get("id")
|
||||
|
||||
if flow_id is None:
|
||||
raise ValueError("No ID provided")
|
||||
flow_data_store[flow_id] = graph_data
|
||||
|
||||
return InitResponse(flowId=flow_id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue