From d0da0bb1ca5d07609346b74e06a77dcaa5f2c739 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 28 Jun 2023 17:27:18 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(chat.py):=20add=20support=20?= =?UTF-8?q?for=20artifacts=20in=20stream=5Fbuild=20function=20to=20pass=20?= =?UTF-8?q?prompt=20variables=20to=20build=5Finput=5Fkeys=5Fresponse=20?= =?UTF-8?q?=E2=9C=A8=20feat(chat.py):=20update=20build=5Finput=5Fkeys=5Fre?= =?UTF-8?q?sponse=20function=20to=20accept=20artifacts=20parameter=20to=20?= =?UTF-8?q?set=20input=5Fkeys=20values=20The=20stream=5Fbuild=20function?= =?UTF-8?q?=20now=20supports=20the=20artifacts=20parameter,=20which=20allo?= =?UTF-8?q?ws=20passing=20prompt=20variables=20to=20the=20build=5Finput=5F?= =?UTF-8?q?keys=5Fresponse=20function.=20This=20ensures=20that=20the=20inp?= =?UTF-8?q?ut=5Fkeys=20values=20are=20correctly=20set=20based=20on=20the?= =?UTF-8?q?=20provided=20artifacts.=20The=20build=5Finput=5Fkeys=5Frespons?= =?UTF-8?q?e=20function=20has=20been=20updated=20to=20accept=20the=20artif?= =?UTF-8?q?acts=20parameter=20and=20use=20it=20to=20set=20the=20input=5Fke?= =?UTF-8?q?ys=20values.=20This=20improves=20the=20functionality=20of=20the?= =?UTF-8?q?=20chat=20module=20by=20allowing=20more=20flexibility=20in=20ha?= =?UTF-8?q?ndling=20prompt=20variables.?= 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 de3c33e01..cdffcdf4f 100644 --- a/src/backend/langflow/api/v1/chat.py +++ b/src/backend/langflow/api/v1/chat.py @@ -72,6 +72,7 @@ async def stream_build(flow_id: str): async def event_stream(flow_id): final_response = {"end_of_stream": True} + artifacts = {} try: if flow_id not in flow_data_store: error_message = "Invalid session ID" @@ -108,6 +109,11 @@ async def stream_build(flow_id: str): logger.debug( f"Building node {params[:50]}{'...' if len(params) > 50 else ''}" ) + if vertex.artifacts: + # The artifacts will be prompt variables + # passed to build_input_keys_response + # to set the input_keys values + artifacts.update(vertex.artifacts) except Exception as exc: params = str(exc) valid = False @@ -124,7 +130,9 @@ async def stream_build(flow_id: str): 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 = build_input_keys_response(langchain_object) + input_keys_response = build_input_keys_response( + langchain_object, artifacts + ) yield str(StreamData(event="message", data=input_keys_response)) chat_manager.set_cache(flow_id, langchain_object)