nbaldwin commited on
Commit
e794544
·
1 Parent(s): 5fbaf2a

cleaned up run

Browse files
Files changed (1) hide show
  1. ControllerExecutorFlow.py +31 -20
ControllerExecutorFlow.py CHANGED
@@ -64,33 +64,44 @@ class ControllerExecutorFlow(CompositeFlow):
64
  :param flow_config: The configuration of the flow (see Configuration Parameters).
65
  :param subflows: A list of subflows. Required when instantiating the subflow programmatically (it replaces subflows_config from flow_config).
66
  """
67
- def __init__(self, flow_config: Dict[str, Any], subflows: Dict[str, Any] = None):
68
- super().__init__(flow_config, subflows)
 
 
 
 
 
69
 
70
- def set_up_flow_state(self):
71
- super().set_up_flow_state()
72
 
 
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  def run(self,input_data):
75
 
76
  executor_reply = input_data
77
 
78
  for round in range(self.flow_config["max_rounds"]):
79
- controller_reply = self.ask_subflow("Controller", executor_reply).get_data()
80
- if controller_reply["command"] == "finish":
81
- return {
82
- "EARLY_EXIT": True,
83
- "answer": controller_reply["command_args"]["answer"],
84
- "status": "finished"
85
- }
86
-
87
-
88
 
89
- executor_reply = {
90
- "observation": self.ask_subflow(controller_reply["command"], controller_reply["command_args"]).get_data()
91
- }
92
-
93
- return {
94
- "answer": "The maximum amount of rounds was reached before the model found an answer.",
 
95
  "status": "unfinished"
96
- }
 
64
  :param flow_config: The configuration of the flow (see Configuration Parameters).
65
  :param subflows: A list of subflows. Required when instantiating the subflow programmatically (it replaces subflows_config from flow_config).
66
  """
67
+
68
+ def _on_reach_max_round(self):
69
+ """ This method is called when the flow reaches the maximum amount of rounds. It updates the state of the flow and starts the process of terminating the flow."""
70
+ self._state_update_dict({
71
+ "answer": "The maximum amount of rounds was reached before the model found an answer.",
72
+ "status": "unfinished"
73
+ })
74
 
75
+ def _single_round_controller_executor(self, executor_reply: Dict[str,Any]) -> Dict[str,Any]:
 
76
 
77
+ controller_reply = self.ask_subflow("Controller", executor_reply).get_data()
78
 
79
+ if controller_reply["command"] == "finish":
80
+ return {
81
+ "EARLY_EXIT": True,
82
+ "answer": controller_reply["command_args"]["answer"],
83
+ "status": "finished"
84
+ }
85
+
86
+ executor_reply = {
87
+ "observation": self.ask_subflow(controller_reply["command"], controller_reply["command_args"]).get_data()
88
+ }
89
+
90
+ return executor_reply
91
+
92
  def run(self,input_data):
93
 
94
  executor_reply = input_data
95
 
96
  for round in range(self.flow_config["max_rounds"]):
97
+ executor_reply = self._single_round_controller_executor(executor_reply)
 
 
 
 
 
 
 
 
98
 
99
+ if executor_reply.get("EARLY_EXIT",False):
100
+ return executor_reply
101
+
102
+ self._on_reach_max_round()
103
+ return {
104
+ "EARLY_EXIT": False,
105
+ "answer": executor_reply["observation"],
106
  "status": "unfinished"
107
+ }