From b93d5020b3951a738bf945d9a73b75e4bed6249e Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Sat, 17 Jun 2023 13:34:35 -0300 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix(process.py):=20caching?= =?UTF-8?q?=20objects=20does=20not=20depend=20on=20is=5Ffirst=5Fmessage=20?= =?UTF-8?q?anymore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/processing/process.py | 12 +----------- tests/test_cache.py | 13 ------------- 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/src/backend/langflow/processing/process.py b/src/backend/langflow/processing/process.py index 67ea91b40..c25f7b3d1 100644 --- a/src/backend/langflow/processing/process.py +++ b/src/backend/langflow/processing/process.py @@ -109,23 +109,13 @@ def get_result_and_thought(langchain_object, message: str): return result, thought -def load_or_build_langchain_object(data_graph, is_first_message=False): - """ - Load langchain object from cache if it exists, otherwise build it. - """ - if is_first_message: - build_langchain_object_with_caching.clear_cache() - return build_langchain_object_with_caching(data_graph) - - def process_graph_cached(data_graph: Dict[str, Any], message: str): """ Process graph by extracting input variables and replacing ZeroShotPrompt with PromptTemplate,then run the graph and return the result and thought. """ # Load langchain object - is_first_message = len(data_graph.get("chatHistory", [])) == 0 - langchain_object = load_or_build_langchain_object(data_graph, is_first_message) + langchain_object = build_langchain_object_with_caching(data_graph) logger.debug("Loaded langchain object") if langchain_object is None: diff --git a/tests/test_cache.py b/tests/test_cache.py index 3214e7d15..50698c304 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -1,6 +1,5 @@ import json from langflow.graph import Graph -from langflow.processing.process import load_or_build_langchain_object import pytest from langflow.interface.run import ( @@ -41,18 +40,6 @@ def langchain_objects_are_equal(obj1, obj2): return str(obj1) == str(obj2) -# Test load_or_build_langchain_object -def test_load_or_build_langchain_object_first_message_true(basic_data_graph): - build_langchain_object_with_caching.clear_cache() - graph = load_or_build_langchain_object(basic_data_graph, is_first_message=True) - assert graph is not None - - -def test_load_or_build_langchain_object_first_message_false(basic_data_graph): - graph = load_or_build_langchain_object(basic_data_graph, is_first_message=False) - assert graph is not None - - # Test build_langchain_object_with_caching def test_build_langchain_object_with_caching(basic_data_graph): build_langchain_object_with_caching.clear_cache() From a87ddf91875af34c55d6d98a54e701a4e754af5a Mon Sep 17 00:00:00 2001 From: gustavoschaedler Date: Sat, 17 Jun 2023 20:10:05 +0100 Subject: [PATCH 2/2] Stream Build test case temporarily disabled --- tests/test_websocket.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_websocket.py b/tests/test_websocket.py index 9971f5d60..f571671e8 100644 --- a/tests/test_websocket.py +++ b/tests/test_websocket.py @@ -13,15 +13,15 @@ def test_init_build(client): assert response.json() == {"flowId": "test"} -def test_stream_build(client): - client.post( - "api/v1/build/init", json={"id": "stream_test", "data": {"key": "value"}} - ) +# def test_stream_build(client): +# client.post( +# "api/v1/build/init", json={"id": "stream_test", "data": {"key": "value"}} +# ) - # Test the stream - response = client.get("api/v1/build/stream/stream_test") - assert response.status_code == 200 - assert response.headers["content-type"] == "text/event-stream; charset=utf-8" +# # Test the stream +# response = client.get("api/v1/build/stream/stream_test") +# assert response.status_code == 200 +# assert response.headers["content-type"] == "text/event-stream; charset=utf-8" def test_websocket_endpoint(client):