Download AbstractBossFlow.py from Tachi67/AbstractBossFlowModule: direct link, hf CLI and curl.
- Browser
- Download file 1.73 kB
-
https://huggingface.co/Tachi67/AbstractBossFlowModule/resolve/f009267e3f8acd1cfa99087bfbb34c43ba114882/AbstractBossFlow.py
- Command line
-
hf download hf://Tachi67/AbstractBossFlowModule@f009267e3f8acd1cfa99087bfbb34c43ba114882/AbstractBossFlow.py
-
curl -L -o AbstractBossFlow.py https://huggingface.co/Tachi67/AbstractBossFlowModule/resolve/f009267e3f8acd1cfa99087bfbb34c43ba114882/AbstractBossFlow.py
1.73 kB
| from copy import deepcopy | |
| from typing import Dict, Any | |
| from aiflows.base_flows import SequentialFlow | |
| from aiflows.utils import logging | |
| from abc import ABC | |
| logging.set_verbosity_debug() | |
| log = logging.get_logger(__name__) | |
| class AbstractBossFlow(SequentialFlow, ABC): | |
| """ | |
| Abstract class of a 'boss': e.g. coder, ExtLib | |
| """ | |
| REQUIRED_KEYS_CONFIG = ["max_rounds", "early_exit_key", "topology", "memory_files"] | |
| def __init__( | |
| self, | |
| memory_files: Dict[str, Any], | |
| **kwargs | |
| ): | |
| super().__init__(**kwargs) | |
| self.memory_files = memory_files | |
| def instantiate_from_config(cls, config): | |
| flow_config = deepcopy(config) | |
| kwargs = {"flow_config": flow_config} | |
| # ~~~ Set up memory file ~~~ | |
| memory_files = flow_config["memory_files"] | |
| kwargs.update({"memory_files": memory_files}) | |
| # ~~~ Set up subflows ~~~ | |
| kwargs.update({"subflows": cls._set_up_subflows(flow_config)}) | |
| # ~~~ Instantiate flow ~~~ | |
| return cls(**kwargs) | |
| def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]: | |
| # ~~~ sets the input_data in the flow_state dict ~~~ | |
| self._state_update_dict(update_data=input_data) | |
| # ~~~ set the memory file to the flow state ~~~ | |
| self._state_update_dict(update_data={"memory_files": self.memory_files}) | |
| max_rounds = self.flow_config.get("max_rounds", 1) | |
| if max_rounds is None: | |
| log.info(f"Running {self.flow_config['name']} without `max_rounds` until the early exit condition is met.") | |
| self._sequential_run(max_rounds=max_rounds) | |
| output = self._get_output_from_state() | |
| return output |