Clean Versions
Browse filesFiles changed (4)
- ControllerExecutorFlow.py+22-14
- ControllerExecutorFlow.yaml+10-1
- demo.yaml+7-5
- run.py+11-11
60 unmodified lines616263646566679 unmodified lines777879808182838485868 unmodified lines95969798991001011021031041051064 unmodified lines11111211311411511611711811912012112211 unmodified lines1341351361371381399 unmodified lines14915015115215315415515615715815916016128 unmodified lines1901911921931941951961971981992002012022032041 unmodified line20620720820921060 unmodified lines- `answer` (str): The answer of the flow to the query (e.g. "Michael Jordan is a basketball player and business man. He was born on February 17, 1963.")- `status` (str): The status of the flow. It can be "finished" or "unfinished". If the status is "unfinished", it's usually because the maximum amount of rounds was reached before the model found an answer.:param flow_config: The configuration of the flow (see Configuration Parameters).:param subflows: A list of subflows. Required when instantiating the subflow programmatically (it replaces subflows_config from flow_config)."""9 unmodified lines)self.reply_interface = KeyInterface(keys_to_select = ["answer","status", "EARLY_EXIT"],)self.next_flow_to_call = {None: "Controller","Controller": "Executor","Executor": "Controller"8 unmodified lines)self.send_message(reply)def get_next_flow_to_call(self):if self.flow_config["max_rounds"] is not None and self.flow_state["current_round"] >= self.flow_config["max_rounds"]:return Nonereturn self.next_flow_to_call[self.flow_state["last_called"]]def _on_reach_max_round(self):""" 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."""4 unmodified lines})def set_up_flow_state(self):super().set_up_flow_state()self.flow_state["last_called"] = Noneself.flow_state["current_round"] = 0def call_controller(self):#first_roundif self.flow_state["current_round"] == 0:input_interface = self.input_interface_first_round_controller11 unmodified lines)def call_executor(self):#call executorexecutor_branch_to_call = self.flow_state["command"]9 unmodified linesdef register_data_to_state(self, input_message):last_called = self.flow_state["last_called"]if last_called is None:self.flow_state["input_message"] = input_messageself.flow_state["goal"] = input_message.data["goal"]elif last_called == "Executor":self.flow_state["observation"] = input_message.dataelse:28 unmodified linesself.register_data_to_state(input_message)flow_to_call = self.get_next_flow_to_call()if self.flow_state.get("early_exit_flag",False):self.generate_reply()elif flow_to_call == "Controller":self.call_controller()elif flow_to_call == "Executor":self.call_executor()self.flow_state["current_round"] += 11 unmodified lineself._on_reach_max_round()self.generate_reply()self.flow_state["last_called"] = flow_to_call60 unmodified lines616263646566679 unmodified lines777879808182838485868 unmodified lines95969798991001011021031041051064 unmodified lines11111211311411511611711811912012112212312411 unmodified lines1361371381391401411429 unmodified lines15215315415515615715815916016116216316416516616716816928 unmodified lines1981992002012022032042052062072082092102112121 unmodified line21421521621721860 unmodified lines- `answer` (str): The answer of the flow to the query (e.g. "Michael Jordan is a basketball player and business man. He was born on February 17, 1963.")- `status` (str): The status of the flow. It can be "finished" or "unfinished". If the status is "unfinished", it's usually because the maximum amount of rounds was reached before the model found an answer.:param flow_config: The configuration of the flow (see Configuration Parameters).:param subflows: A list of subflows. Required when instantiating the subflow programmatically (it replaces subflows_config from flow_config)."""9 unmodified lines)self.reply_interface = KeyInterface(keys_to_select = ["answer","status"],)self.next_state = {None: "Controller","Controller": "Executor","Executor": "Controller"8 unmodified lines)self.send_message(reply)def get_next_state(self):""" """if self.flow_config["max_rounds"] is not None and self.flow_state["current_round"] >= self.flow_config["max_rounds"]:return Nonereturn self.next_state[self.flow_state["last_state"]]def _on_reach_max_round(self):""" 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."""4 unmodified lines})def set_up_flow_state(self):""" Sets up the flow state."""super().set_up_flow_state()self.flow_state["last_state"] = Noneself.flow_state["current_round"] = 0def call_controller(self):""" Calls the controller: the flow that decides which command to call next."""#first_roundif self.flow_state["current_round"] == 0:input_interface = self.input_interface_first_round_controller11 unmodified lines)def call_executor(self):""" Calls the flow that executes the command instructed by the ControllerAtomicFlow."""#call executorexecutor_branch_to_call = self.flow_state["command"]9 unmodified linesdef register_data_to_state(self, input_message):"""This method registers the input message data to the flow state. It's everytime a new input message is received.:param input_message: The input message:type input_message: FlowMessage"""last_state = self.flow_state["last_state"]if last_state is None:self.flow_state["input_message"] = input_messageself.flow_state["goal"] = input_message.data["goal"]elif last_state == "Executor":self.flow_state["observation"] = input_message.dataelse:28 unmodified linesself.register_data_to_state(input_message)current_state = self.get_next_state()if self.flow_state.get("early_exit_flag",False):self.generate_reply()elif current_state == "Controller":self.call_controller()elif current_state == "Executor":self.call_executor()self.flow_state["current_round"] += 11 unmodified lineself._on_reach_max_round()self.generate_reply()self.flow_state["last_state"] = current_state
13 unmodified lines1415161718195 unmodified lines2526272829303113 unmodified linesController:name: "ControllerAtomicFlow"description: "A flow that calls other flows to solve a problem."_target_: flow_modules.aiflows.ControllerExecutorFlowModule.ControllerAtomicFlow.instantiate_from_default_configcommands:finish:5 unmodified lines# description: "Performs a search on Wikipedia."# input_args: ["search_term"]# E.g.,# wiki_search:# _target_: .WikiSearchAtomicFlow.instantiate_from_default_config13 unmodified lines1415161718192021225 unmodified lines2829303132333435363738394013 unmodified linesController:name: "ControllerAtomicFlow"description: "A flow that calls other flows to solve a problem."flow_class_name: flow_modules.aiflows.ControllerExecutorFlowModule.ControllerAtomicFlowflow_endpoint: ControllerAtomicFlowuser_id: local_target_: flow_modules.aiflows.ControllerExecutorFlowModule.ControllerAtomicFlow.instantiate_from_default_configcommands:finish:5 unmodified lines# description: "Performs a search on Wikipedia."# input_args: ["search_term"]wiki_search:_target_: flow_modules.aiflows.ControllerExecutorFlowModule.WikiSearchAtomicFlow.instantiate_from_default_configflow_class_name: flow_modules.aiflows.ControllerExecutorFlowModule.WikiSearchAtomicFlowflow_endpoint: WikiSearchAtomicFlowuser_id: localname: "WikiSearchAtomicFlow"description: "A flow that searches Wikipedia for information."# E.g.,# wiki_search:# _target_: .WikiSearchAtomicFlow.instantiate_from_default_config
3 unmodified lines456789101112131411 unmodified lines26272829303132333 unmodified lines### Subflows specificationsubflows_config:Controller:_target_: aiflows.base_flows.AtomicFlow.instantiate_from_default_configname: "Proxy Controller"description: "A flow that acts as a proxy for the controller."flow_endpoint: ControllerAtomicFlowuser_id: localcommands:wiki_search:description: "Performs a search on Wikipedia."11 unmodified lineswiki_search:_target_: aiflows.base_flows.AtomicFlow.instantiate_from_default_configname: "WikiSearchAtomicFlow"description: "A flow that searches Wikipedia for information."flow_endpoint: WikiSearchAtomicFlowuser_id: local3 unmodified lines45678910111213141511 unmodified lines2728293031323334353 unmodified lines### Subflows specificationsubflows_config:Controller:_target_: flow_modules.aiflows.ControllerExecutorFlowModule.ControllerAtomicFlow.instantiate_from_default_configname: "Proxy Controller"flow_class_name: flow_modules.aiflows.ControllerExecutorFlowModule.ControllerAtomicFlowflow_endpoint: ControllerAtomicFlowuser_id: localdescription: "A flow that acts as a proxy for the controller."commands:wiki_search:description: "Performs a search on Wikipedia."11 unmodified lineswiki_search:_target_: flow_modules.aiflows.ControllerExecutorFlowModule.WikiSearchAtomicFlow.instantiate_from_default_configflow_class_name: flow_modules.aiflows.ControllerExecutorFlowModule.WikiSearchAtomicFlowflow_endpoint: WikiSearchAtomicFlowuser_id: localname: "WikiSearchAtomicFlow"description: "A flow that searches Wikipedia for information."
59 unmodified lines6061626364656667686970717273747576777859 unmodified lines#3. ~~~~ Serve The Flow ~~~~serve_utils.serve_flow(cl = cl,flow_class_name="flow_modules.aiflows.ControllerExecutorFlowModule.WikiSearchAtomicFlow",flow_endpoint="WikiSearchAtomicFlow",)serve_utils.serve_flow(cl = cl,flow_class_name="flow_modules.aiflows.ControllerExecutorFlowModule.ControllerAtomicFlow",flow_endpoint="ControllerAtomicFlow",)serve_utils.serve_flow(cl = cl,flow_class_name="flow_modules.aiflows.ControllerExecutorFlowModule.ControllerExecutorFlow",flow_endpoint="ControllerExecutorFlow",59 unmodified lines6061626364656667686970717273747576777859 unmodified lines#3. ~~~~ Serve The Flow ~~~~# serve_utils.recursive_serve_flow(# cl = cl,# flow_class_name="flow_modules.aiflows.ControllerExecutorFlowModule.WikiSearchAtomicFlow",# flow_endpoint="WikiSearchAtomicFlow",# )# serve_utils.serve_flow(# cl = cl,# flow_class_name="flow_modules.aiflows.ControllerExecutorFlowModule.ControllerAtomicFlow",# flow_endpoint="ControllerAtomicFlow",# )serve_utils.recursive_serve_flow(cl = cl,flow_class_name="flow_modules.aiflows.ControllerExecutorFlowModule.ControllerExecutorFlow",flow_endpoint="ControllerExecutorFlow",
ControllerExecutorFlow.py+22-14
ControllerExecutorFlow.yaml+10-1
demo.yaml+7-5
run.py+11-11