🐛 fix(chat.py): remove unnecessary blank line to improve code readability

🐛 fix(chat.py): remove unused variable 'valid' to improve code readability
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py): fix indentation of 'yield' statement to match the surrounding code
🐛 fix(chat.py
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-10-04 18:46:20 -03:00
commit 7d633d853d
4 changed files with 33 additions and 10 deletions

View file

@ -164,6 +164,7 @@ async def stream_build(
}
yield str(StreamData(event="log", data=log_dict))
vertex.build(user_id)
params = vertex._built_object_repr()
valid = True
logger.debug(f"Building node {str(vertex.vertex_type)}")
@ -181,14 +182,18 @@ async def stream_build(
valid = False
flow_data_store[flow_id]["status"] = BuildStatus.FAILURE
response = {
"valid": valid,
"params": params,
"id": vertex.id,
"progress": round(i / number_of_nodes, 2),
}
vertex_id = (
vertex.parent_node_id if vertex.parent_is_top_level else vertex.id
)
if vertex_id in graph.top_level_nodes:
response = {
"valid": valid,
"params": params,
"id": vertex_id,
"progress": round(i / number_of_nodes, 2),
}
yield str(StreamData(event="message", data=response))
yield str(StreamData(event="message", data=response))
langchain_object = graph.build()
# Now we need to check the input_keys to send them to the client

View file

@ -25,8 +25,9 @@ class Graph:
) -> None:
self._nodes = nodes
self._edges = edges
self._graph_data = {"nodes": nodes, "edges": edges}
self._graph_data = process_flow(self._graph_data)
self.raw_graph_data = {"nodes": nodes, "edges": edges}
self.top_level_nodes = [node.get("id") for node in nodes]
self._graph_data = process_flow(self.raw_graph_data)
self._nodes = self._graph_data["nodes"]
self._edges = self._graph_data["edges"]
self._build_graph()
@ -210,7 +211,9 @@ class Graph:
node_lc_type: str = node_data["node"]["template"]["_type"] # type: ignore
VertexClass = self._get_vertex_class(node_type, node_lc_type)
nodes.append(VertexClass(node))
vertex = VertexClass(node)
vertex.set_top_level(self.top_level_nodes)
nodes.append(vertex)
return nodes

View file

@ -9,12 +9,22 @@ def find_last_node(data):
return next((n for n in nodes if all(e["source"] != n["id"] for e in edges)), None)
def add_parent_node_id(nodes, parent_node_id):
"""
This function receives a list of nodes and adds a parent_node_id to each node.
"""
for node in nodes:
node["parent_node_id"] = parent_node_id
def ungroup_node(group_node_data, base_flow):
template, flow = (
group_node_data["node"]["template"],
group_node_data["node"]["flow"],
)
parent_node_id = group_node_data["id"]
g_nodes = flow["data"]["nodes"]
add_parent_node_id(g_nodes, parent_node_id)
g_edges = flow["data"]["edges"]
# Redirect edges to the correct proxy node

View file

@ -26,6 +26,11 @@ class Vertex:
self._built_object = UnbuiltObject()
self._built = False
self.artifacts: Dict[str, Any] = {}
self.parent_node_id: Optional[str] = self._data.get("parent_node_id")
self.parent_is_top_level = False
def set_top_level(self, top_level_nodes: List[str]) -> None:
self.parent_is_top_level = self.parent_node_id in top_level_nodes
def _parse_data(self) -> None:
self.data = self._data["data"]