Tachi67 commited on
Commit
b5548dd
·
1 Parent(s): a7a3bf9

Upload 3 files

Browse files
Files changed (3) hide show
  1. AbstractBossFlow.py +57 -0
  2. AbstractBossFlow.yaml +51 -0
  3. __init__.py +9 -0
AbstractBossFlow.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from copy import deepcopy
2
+ from typing import Dict, Any
3
+
4
+ from flows.base_flows import SequentialFlow
5
+ from flows.utils import logging
6
+ from abc import ABC
7
+
8
+
9
+ logging.set_verbosity_debug()
10
+ log = logging.get_logger(__name__)
11
+
12
+ class AbstractBossFlow(SequentialFlow, ABC):
13
+ """
14
+ Abstract class of a 'boss': e.g. coder, ExtLib
15
+ """
16
+ REQUIRED_KEYS_CONFIG = ["max_rounds", "early_exit_key", "topology", "memory_files"]
17
+
18
+ def __init__(
19
+ self,
20
+ memory_files: Dict[str, Any],
21
+ **kwargs
22
+ ):
23
+ super().__init__(**kwargs)
24
+ self.memory_files = memory_files
25
+
26
+ @classmethod
27
+ def instantiate_from_config(cls, config):
28
+ flow_config = deepcopy(config)
29
+
30
+ kwargs = {"flow_config": flow_config}
31
+
32
+ # ~~~ Set up memory file ~~~
33
+ memory_files = flow_config["memory_files"]
34
+ kwargs.update({"memory_files": memory_files})
35
+
36
+ # ~~~ Set up subflows ~~~
37
+ kwargs.update({"subflows": cls._set_up_subflows(flow_config)})
38
+
39
+ # ~~~ Instantiate flow ~~~
40
+ return cls(**kwargs)
41
+
42
+ def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
43
+ # ~~~ sets the input_data in the flow_state dict ~~~
44
+ self._state_update_dict(update_data=input_data)
45
+
46
+ # ~~~ set the memory file to the flow state ~~~
47
+ self._state_update_dict(update_data={"memory_files": self.memory_files})
48
+
49
+ max_rounds = self.flow_config.get("max_rounds", 1)
50
+ if max_rounds is None:
51
+ log.info(f"Running {self.flow_config['name']} without `max_rounds` until the early exit condition is met.")
52
+
53
+ self._sequential_run(max_rounds=max_rounds)
54
+
55
+ output = self._get_output_from_state()
56
+
57
+ return output
AbstractBossFlow.yaml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "AbstractBossFlow"
2
+ description: "Abstract class of a boss, e.g. coder, ExtendLibrary, etc."
3
+
4
+ _target_: Tachi67.AbstractBossFlowModule.AbstractBossFlow.instantiate_from_default_config
5
+
6
+ memory_files: ???
7
+
8
+ input_interface:
9
+ - "goal"
10
+
11
+ output_interface:
12
+ - "answer"
13
+ - "summary" # to be written into the logs of the upper level boss
14
+
15
+ subflows_config:
16
+ MemoryReading:
17
+ _target_: Tachi67.MemoryReadingFlowModule.MemoryReadingAtomicFlow.instantiate_from_default_config
18
+
19
+ Planner:
20
+ _target_: Tachi67.PlanWriterFlowModule.PlanWriterFlow.instantiate_from_default_config
21
+
22
+ # the flow with a controller, few executors in a branch, memory reading and memory writing
23
+ CtrlExMem:
24
+ _target_: Tachi67.CtrlExMemFlowModule.CtrlExMemFlow.instantiate_from_default_config
25
+
26
+ early_exit_key: "EARLY_EXIT"
27
+
28
+ topology:
29
+ - goal: "Read in necessary memory"
30
+ input_interface:
31
+ _target_: flows.interfaces.KeyInterface
32
+ additional_transformations:
33
+ - _target_: flows.data_transformations.KeyMatchInput
34
+ flow: MemoryReading
35
+ reset: false
36
+
37
+ - goal: "Make plans in an interactive fashion, write the plan into the plan file"
38
+ input_interface:
39
+ _target_: flows.interfaces.KeyInterface
40
+ additional_transformations:
41
+ - _target_: flows.data_transformations.KeyMatchInput
42
+ flow: Planner
43
+ reset: false
44
+
45
+ - goal: "Execute the plan and return answer & a summary of what was done"
46
+ input_interface:
47
+ _target_: flows.interfaces.KeyInterface
48
+ additional_transformations:
49
+ - _target_: flows.data_transformations.KeyMatchInput
50
+ flow: CtrlExMem
51
+ reset: false
__init__.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ dependencies = [
2
+ {"url": "Tachi67/MemoryReadingFlowModule", "revision": "main"},
3
+ {"url": "Tachi67/PlanWriterFlowModule", "revision":"main"},
4
+ {"url": "Tachi67/CtrlExMemFlowModule", "revision":"main"},
5
+ ]
6
+ from flows import flow_verse
7
+
8
+ flow_verse.sync_dependencies(dependencies)
9
+ from .AbstractBossFlow import AbstractBossFlow