@@ -56,7 +56,7 @@ def _create_edges(self, edges: list) -> dict:
56
56
edge_dict [from_node .node_name ] = to_node .node_name
57
57
return edge_dict
58
58
59
- def execute (self , initial_state : dict ) -> dict :
59
+ def execute (self , initial_state : dict ) -> ( dict , list ) :
60
60
"""
61
61
Executes the graph by traversing nodes starting from the entry point. The execution
62
62
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:
68
68
Returns:
69
69
dict: The state after execution has completed, which may have been altered by the nodes.
70
70
"""
71
- print (self .nodes )
72
71
current_node_name = self .nodes [0 ]
73
72
state = initial_state
74
73
75
74
# variables for tracking execution info
76
75
total_exec_time = 0.0
77
- exec_info = {}
76
+ exec_info = []
78
77
cb_total = {
79
78
"total_tokens" : 0 ,
80
79
"prompt_tokens" : 0 ,
@@ -94,18 +93,19 @@ def execute(self, initial_state: dict) -> dict:
94
93
total_exec_time += node_exec_time
95
94
96
95
cb = {
96
+ "node_name" : index .node_name ,
97
97
"total_tokens" : cb .total_tokens ,
98
98
"prompt_tokens" : cb .prompt_tokens ,
99
99
"completion_tokens" : cb .completion_tokens ,
100
100
"successful_requests" : cb .successful_requests ,
101
101
"total_cost_USD" : cb .total_cost ,
102
- }
103
-
104
- exec_info [current_node_name ] = {
105
102
"exec_time" : node_exec_time ,
106
- "model_info" : cb
107
103
}
108
104
105
+ exec_info .append (
106
+ cb
107
+ )
108
+
109
109
cb_total ["total_tokens" ] += cb ["total_tokens" ]
110
110
cb_total ["prompt_tokens" ] += cb ["prompt_tokens" ]
111
111
cb_total ["completion_tokens" ] += cb ["completion_tokens" ]
@@ -119,10 +119,14 @@ def execute(self, initial_state: dict) -> dict:
119
119
else :
120
120
current_node_name = None
121
121
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