@@ -56,7 +56,7 @@ def _create_edges(self, edges: list) -> dict:
5656 edge_dict [from_node .node_name ] = to_node .node_name
5757 return edge_dict
5858
59- def execute (self , initial_state : dict ) -> dict :
59+ def execute (self , initial_state : dict ) -> ( dict , list ) :
6060 """
6161 Executes the graph by traversing nodes starting from the entry point. The execution
6262 follows the edges based on the result of each node's execution and continues until
@@ -68,13 +68,12 @@ def execute(self, initial_state: dict) -> dict:
6868 Returns:
6969 dict: The state after execution has completed, which may have been altered by the nodes.
7070 """
71- print (self .nodes )
7271 current_node_name = self .nodes [0 ]
7372 state = initial_state
7473
7574 # variables for tracking execution info
7675 total_exec_time = 0.0
77- exec_info = {}
76+ exec_info = []
7877 cb_total = {
7978 "total_tokens" : 0 ,
8079 "prompt_tokens" : 0 ,
@@ -94,18 +93,19 @@ def execute(self, initial_state: dict) -> dict:
9493 total_exec_time += node_exec_time
9594
9695 cb = {
96+ "node_name" : index .node_name ,
9797 "total_tokens" : cb .total_tokens ,
9898 "prompt_tokens" : cb .prompt_tokens ,
9999 "completion_tokens" : cb .completion_tokens ,
100100 "successful_requests" : cb .successful_requests ,
101101 "total_cost_USD" : cb .total_cost ,
102- }
103-
104- exec_info [current_node_name ] = {
105102 "exec_time" : node_exec_time ,
106- "model_info" : cb
107103 }
108104
105+ exec_info .append (
106+ cb
107+ )
108+
109109 cb_total ["total_tokens" ] += cb ["total_tokens" ]
110110 cb_total ["prompt_tokens" ] += cb ["prompt_tokens" ]
111111 cb_total ["completion_tokens" ] += cb ["completion_tokens" ]
@@ -119,10 +119,14 @@ def execute(self, initial_state: dict) -> dict:
119119 else :
120120 current_node_name = None
121121
122- execution_info = {
123- "total_exec_time" : total_exec_time ,
124- "total_model_info" : cb_total ,
125- "nodes_info" : exec_info
126- }
127-
128- return state , execution_info
122+ exec_info .append ({
123+ "node_name" : "TOTAL RESULT" ,
124+ "total_tokens" : cb_total ["total_tokens" ],
125+ "prompt_tokens" : cb_total ["prompt_tokens" ],
126+ "completion_tokens" : cb_total ["completion_tokens" ],
127+ "successful_requests" : cb_total ["successful_requests" ],
128+ "total_cost_USD" : cb_total ["total_cost_USD" ],
129+ "exec_time" : total_exec_time ,
130+ })
131+
132+ return state , exec_info
0 commit comments