From 825f2798c363eff58001ffe388c1732db3d641ad Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 19 Jun 2023 16:03:25 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(chat.py):=20fix=20node=20to?= =?UTF-8?q?=20vertex=20variable=20name=20in=20stream=5Fbuild=20function=20?= =?UTF-8?q?=E2=9C=A8=20feat(chat.py):=20add=20progress=20logging=20to=20st?= =?UTF-8?q?ream=5Fbuild=20function=20The=20variable=20node=20was=20renamed?= =?UTF-8?q?=20to=20vertex=20to=20improve=20semantics=20and=20consistency?= =?UTF-8?q?=20with=20the=20naming=20conventions.=20Progress=20logging=20wa?= =?UTF-8?q?s=20added=20to=20the=20stream=5Fbuild=20function=20to=20provide?= =?UTF-8?q?=20feedback=20to=20the=20user=20on=20the=20progress=20of=20the?= =?UTF-8?q?=20build=20process.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 fix(index.tsx): fix typo in setSuccessData function call ✨ feat(index.tsx): add success logging to handleBuild function A typo in the setSuccessData function call was fixed. Success logging was added to the handleBuild function to provide feedback to the user on the success of the build process. --- src/backend/langflow/api/v1/chat.py | 14 ++++++++++---- .../chatComponent/buildTrigger/index.tsx | 16 +++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/backend/langflow/api/v1/chat.py b/src/backend/langflow/api/v1/chat.py index 262defed6..ed0caeba2 100644 --- a/src/backend/langflow/api/v1/chat.py +++ b/src/backend/langflow/api/v1/chat.py @@ -87,10 +87,16 @@ async def stream_build(flow_id: str): logger.debug("Building langchain object") graph = Graph.from_payload(graph_data) - for node in graph.generator_build(): + number_of_nodes = len(graph.nodes) + for i, vertex in enumerate(graph.generator_build(), 1): try: - node.build() - params = node._built_object_repr() + log_dict = { + "log": f"Building node {vertex.vertex_type}", + "progress": round(i / number_of_nodes, 2), + } + yield f"data: {json.dumps(log_dict)}\n\n" + vertex.build() + params = vertex._built_object_repr() valid = True logger.debug( f"Building node {params[:50]}{'...' if len(params) > 50 else ''}" @@ -103,7 +109,7 @@ async def stream_build(flow_id: str): { "valid": valid, "params": params, - "id": node.id, + "id": vertex.id, } ) yield f"data: {response}\n\n" diff --git a/src/frontend/src/components/chatComponent/buildTrigger/index.tsx b/src/frontend/src/components/chatComponent/buildTrigger/index.tsx index c9113dbd7..49ec2922f 100644 --- a/src/frontend/src/components/chatComponent/buildTrigger/index.tsx +++ b/src/frontend/src/components/chatComponent/buildTrigger/index.tsx @@ -1,4 +1,4 @@ -import { useState, useContext } from "react"; +import { useContext } from "react"; import { Transition } from "@headlessui/react"; import { Zap } from "lucide-react"; import { validateNodes } from "../../../utils"; @@ -22,7 +22,7 @@ export default function BuildTrigger({ }) { const { updateSSEData, isBuilding, setIsBuilding } = useSSE(); const { reactFlowInstance } = useContext(typesContext); - const { setErrorData } = useContext(alertContext); + const { setErrorData, setSuccessData } = useContext(alertContext); async function handleBuild(flow: FlowType) { try { @@ -81,10 +81,16 @@ export default function BuildTrigger({ eventSource.close(); return; + } else if (parsedData.log) { + // If the event is a log, log it + // TODO: implement the progress + setSuccessData({ title: parsedData.log }); + setSuccessData({ title: parsedData.progress }); + } else { + // Otherwise, process the data + const isValid = processStreamResult(parsedData); + validationResults.push(isValid); } - // Otherwise, process the data - const isValid = processStreamResult(parsedData); - validationResults.push(isValid); }; eventSource.onerror = (error) => {