✨ 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
2
poetry.lock
generated
2
poetry.lock
generated
|
|
@ -6416,4 +6416,4 @@ deploy = ["langchain-serve"]
|
||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.0"
|
lock-version = "2.0"
|
||||||
python-versions = ">=3.9,<3.12"
|
python-versions = ">=3.9,<3.12"
|
||||||
content-hash = "e3a7355edeae80f8330e6e71fd5acbc446fd287397cf7d8d027ab6b450569f28"
|
content-hash = "4ed469589797b717f4b878f219dfe7c83d21d45d6947617693b6d2feb55cee3a"
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ faiss-cpu = "^1.7.4"
|
||||||
anthropic = "^0.2.9"
|
anthropic = "^0.2.9"
|
||||||
orjson = "^3.9.0"
|
orjson = "^3.9.0"
|
||||||
multiprocess = "^0.70.14"
|
multiprocess = "^0.70.14"
|
||||||
|
cachetools = "^5.3.1"
|
||||||
|
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
[tool.poetry.group.dev.dependencies]
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,11 @@ from langflow.api.v1.schemas import BuiltResponse, InitResponse
|
||||||
from langflow.chat.manager import ChatManager
|
from langflow.chat.manager import ChatManager
|
||||||
from langflow.graph.graph.base import Graph
|
from langflow.graph.graph.base import Graph
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
|
from cachetools import LRUCache
|
||||||
|
|
||||||
router = APIRouter(tags=["Chat"])
|
router = APIRouter(tags=["Chat"])
|
||||||
chat_manager = ChatManager()
|
chat_manager = ChatManager()
|
||||||
flow_data_store = {}
|
flow_data_store = LRUCache(maxsize=10)
|
||||||
|
|
||||||
|
|
||||||
@router.websocket("/chat/{client_id}")
|
@router.websocket("/chat/{client_id}")
|
||||||
|
|
@ -38,7 +39,8 @@ async def init_build(graph_data: dict):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
flow_id = graph_data.get("id")
|
flow_id = graph_data.get("id")
|
||||||
|
if flow_id is None:
|
||||||
|
raise ValueError("No ID provided")
|
||||||
flow_data_store[flow_id] = graph_data
|
flow_data_store[flow_id] = graph_data
|
||||||
|
|
||||||
return InitResponse(flowId=flow_id)
|
return InitResponse(flowId=flow_id)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue