Tachi67 commited on
Commit
51219b7
·
1 Parent(s): 10e06d1

Upload 3 files

Browse files
InteractivePlanGenFlow.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from copy import deepcopy
2
+ from typing import Any, Dict
3
+
4
+ from flows.base_flows import SequentialFlow
5
+ from flows.utils import logging
6
+
7
+ logging.set_verbosity_debug()
8
+ log = logging.get_logger(__name__)
9
+
10
+ class InteractivePlanGenFlow(SequentialFlow):
11
+ REQUIRED_KEYS_CONFIG = ["max_rounds", "early_exit_key", "topology", "memory_files"]
12
+
13
+ def __init__(
14
+ self,
15
+ memory_files: Dict[str, Any],
16
+ **kwargs
17
+ ):
18
+ super().__init__(**kwargs)
19
+ self.memory_files = memory_files
20
+
21
+ @classmethod
22
+ def instantiate_from_config(cls, config):
23
+ flow_config = deepcopy(config)
24
+
25
+ kwargs = {"flow_config": flow_config}
26
+
27
+ # ~~~ Set up memory file ~~~
28
+ memory_files = flow_config["memory_files"]
29
+ kwargs.update({"memory_files": memory_files})
30
+
31
+ # ~~~ Set up subflows ~~~
32
+ kwargs.update({"subflows": cls._set_up_subflows(flow_config)})
33
+
34
+ # ~~~ Instantiate flow ~~~
35
+ return cls(**kwargs)
36
+
37
+ def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
38
+ # ~~~ sets the input_data in the flow_state dict ~~~
39
+ self._state_update_dict(update_data=input_data)
40
+
41
+ # ~~~ set the memory file to the flow state ~~~
42
+ self._state_update_dict(update_data={"memory_files": self.memory_files})
43
+
44
+ max_rounds = self.flow_config.get("max_rounds", 1)
45
+ if max_rounds is None:
46
+ log.info(f"Running {self.flow_config['name']} without `max_rounds` until the early exit condition is met.")
47
+
48
+ self._sequential_run(max_rounds=max_rounds)
49
+
50
+ output = self._get_output_from_state()
51
+
52
+ return output
InteractivePlanGenFlow.yaml ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "InteractivePlanGenFlow"
2
+ description: "Generate step by step plan as goal requests, open up a temp file for the user to examine and provide feedback"
3
+
4
+ _target_: Tachi67.InteractivePlanGenFlowModule.InteractivePlanGenFlow.instantiate_from_default_config
5
+
6
+ memory_files: ???
7
+
8
+ input_interface:
9
+ - "goal"
10
+
11
+ output_interface:
12
+ - "plan"
13
+ - "feedback"
14
+ - "temp_plan_file_location"
15
+
16
+ subflows_config:
17
+ MemoryReading:
18
+ _target_: Tachi67.MemoryReadingFlowModule.MemoryReadingAtomicFlow.instantiate_from_default_config
19
+
20
+ PlanGenerator:
21
+ _target_: Tachi67.PlanGeneratorFlowModule.PlanGeneratorAtomicFlow.instantiate_from_default_config
22
+ backend:
23
+ api_infos: ???
24
+ model_name:
25
+ openai: gpt-4
26
+ azure: azure/gpt-4
27
+
28
+ PlanFileEditor:
29
+ _target_: Tachi67.PlanFileEditFlowModule.PlanFileEditAtomicFlow.instantiate_from_default_config
30
+
31
+ ParseFeedback:
32
+ _target_: Tachi67.ParseFeedbackFlowModule.ParseFeedbackAtomicFlow.instantiate_from_default_config
33
+ input_interface:
34
+ - "temp_plan_file_location"
35
+ - "temp_plan_file_written_timestamp"
36
+
37
+ early_exit_key: "EARLY_EXIT"
38
+
39
+ topology:
40
+ - goal: "Read in necessary memory"
41
+ input_interface:
42
+ _target_: flows.interfaces.KeyInterface
43
+ additional_transformations:
44
+ - _target_: flows.data_transformations.KeyMatchInput
45
+ flow: MemoryReading
46
+ reset: false
47
+
48
+ - goal: "Generate plan to achieve the task."
49
+ input_interface:
50
+ _target_: flows.interfaces.KeyInterface
51
+ additional_transformations:
52
+ - _target_: flows.data_transformations.KeyMatchInput
53
+ flow: PlanGenerator
54
+ reset: false
55
+
56
+ - goal: "Write the plan generated to a temp file with instructions to the user"
57
+ input_interface:
58
+ _target_: flows.interfaces.KeyInterface
59
+ additional_transformations:
60
+ - _target_: flows.data_transformations.KeyMatchInput
61
+ flow: PlanFileEditor
62
+ reset: false
63
+
64
+ - goal: "Parse user feedback from the temp file"
65
+ input_interface:
66
+ _target_: flows.interfaces.KeyInterface
67
+ additional_transformations:
68
+ - _target_: flows.data_transformations.KeyMatchInput
69
+ flow: ParseFeedback
70
+ reset: false
__init__.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ~~~ Specify the dependencies ~~~
2
+ dependencies = [
3
+ {"url": "Tachi67/MemoryReadingFlowModule", "revision": "main"},
4
+ {"url": "Tachi67/PlanGeneratorFlowModule", "revision": "main"},
5
+ {"url": "Tachi67/PlanFileEditFlowModule", "revision": "main"},
6
+ {"url": "Tachi67/ParseFeedbackFlowModule", "revision": "main"},
7
+ ]
8
+ from flows import flow_verse
9
+
10
+ flow_verse.sync_dependencies(dependencies)
11
+
12
+ from .InteractivePlanGenFlow import InteractivePlanGenFlow