🐛 fix(chat.py): fix node to vertex variable name in stream_build function

 feat(chat.py): add progress logging to stream_build function
The variable node was renamed to vertex to improve semantics and consistency with the naming conventions. Progress logging was added to the stream_build function to provide feedback to the user on the progress of the build process.

🐛 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.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-19 16:03:25 -03:00
commit 825f2798c3
2 changed files with 21 additions and 9 deletions

View file

@ -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"

View file

@ -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) => {