| 646 | |
| 647 | @AgentRegistry.register('FinalMajorVote') |
| 648 | class FinalMajorVote(Node): |
| 649 | def __init__(self, id: str | None =None, domain: str = "", llm_name: str = "",): |
| 650 | """ Used for Directed IO """ |
| 651 | super().__init__(id, "FinalMajorVote") |
| 652 | self.prompt_set = PromptSetRegistry.get(domain) |
| 653 | |
| 654 | def _process_inputs(self, raw_inputs:Dict[str,str], spatial_info:Dict[str,Any], temporal_info:Dict[str,Any], **kwargs)->List[Any]: |
| 655 | """ To be overriden by the descendant class """ |
| 656 | """ Process the raw_inputs(most of the time is a List[Dict]) """ |
| 657 | return None |
| 658 | |
| 659 | def _execute(self, input:Dict[str,str], spatial_info:Dict[str,Any], temporal_info:Dict[str,Any],**kwargs): |
| 660 | """ To be overriden by the descendant class """ |
| 661 | """ Use the processed input to get the result """ |
| 662 | output_num = {} |
| 663 | max_output = "" |
| 664 | max_output_num = 0 |
| 665 | for info in spatial_info.values(): |
| 666 | processed_output = self.prompt_set.postprocess_answer(info['output']) |
| 667 | if processed_output in output_num: |
| 668 | output_num[processed_output] += 1 |
| 669 | else: |
| 670 | output_num[processed_output] = 1 |
| 671 | if output_num[processed_output] > max_output_num: |
| 672 | max_output = processed_output |
| 673 | max_output_num = output_num[processed_output] |
| 674 | return max_output |
| 675 | |
| 676 | async def _async_execute(self, input:Dict[str,str], spatial_info:Dict[str,Any], temporal_info:Dict[str,Any], mode: str = "default", **kwargs): |
| 677 | """ To be overriden by the descendant class """ |
| 678 | """ Use the processed input to get the result """ |
| 679 | output_num = {} |
| 680 | max_output = "" |
| 681 | max_output_num = 0 |
| 682 | for info in spatial_info.values(): |
| 683 | processed_output = await self.prompt_set.postprocess_answer(info['output']) |
| 684 | logger.debug("Processed output: {}", processed_output) |
| 685 | if processed_output in output_num: |
| 686 | output_num[processed_output] += 1 |
| 687 | else: |
| 688 | output_num[processed_output] = 1 |
| 689 | if output_num[processed_output] > max_output_num: |
| 690 | max_output = processed_output |
| 691 | max_output_num = output_num[processed_output] |
| 692 | if mode == "allow_kv_reuse": |
| 693 | return input.get("task"), max_output |
| 694 | return max_output |
nothing calls this directly
no outgoing calls
no test coverage detected