From ff0abf51839dec1113e350e403055e40f6954e49 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 26 Jun 2023 10:20:28 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20refactor(chat.py):=20refactor=20?= =?UTF-8?q?stream=5Fbuild=20function=20to=20send=20input=5Fkeys=20to=20the?= =?UTF-8?q?=20client=20The=20stream=5Fbuild=20function=20has=20been=20refa?= =?UTF-8?q?ctored=20to=20send=20input=5Fkeys=20to=20the=20client=20if=20th?= =?UTF-8?q?e=20langchain=5Fobject=20has=20the=20attribute=20"input=5Fkeys"?= =?UTF-8?q?.=20This=20change=20improves=20the=20user=20experience=20by=20p?= =?UTF-8?q?roviding=20the=20client=20with=20the=20necessary=20input=20keys?= =?UTF-8?q?=20to=20continue=20the=20conversation.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/chat.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/api/v1/chat.py b/src/backend/langflow/api/v1/chat.py index be9d6802c..666c5d3cd 100644 --- a/src/backend/langflow/api/v1/chat.py +++ b/src/backend/langflow/api/v1/chat.py @@ -120,7 +120,15 @@ async def stream_build(flow_id: str): yield str(StreamData(event="message", data=response)) - chat_manager.set_cache(flow_id, graph.build()) + langchain_object = graph.build() + # Now we need to check the input_keys to send them to the client + if hasattr(langchain_object, "input_keys"): + input_keys_response = { + "input_keys": langchain_object.input_keys, + } + yield str(StreamData(event="input_keys", data=input_keys_response)) + + chat_manager.set_cache(flow_id, langchain_object) except Exception as exc: logger.error("Error while building the flow: %s", exc) yield str(StreamData(event="error", data={"error": str(exc)}))