Tachi67 commited on
Commit
e0487cd
·
1 Parent(s): f2ec15a

Upload 6 files

Browse files
InteractivePlanGenFlow.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from copy import deepcopy
2
+ from typing import Any, Dict
3
+
4
+ from aiflows.base_flows import SequentialFlow
5
+ from aiflows.utils import logging
6
+
7
+ logging.set_verbosity_debug()
8
+ log = logging.get_logger(__name__)
9
+
10
+ class InteractivePlanGenFlow(SequentialFlow):
11
+ """This flow writes code in an interactive manner. It is a sequential flow composed of:
12
+ 1. PlanGenerator: generates plan based on the goal.
13
+ 2. PlanFileEditor: writes the generated plan to a temp file for the user to see, edit and provide feedback.
14
+ 3. ParseFeedback: opens up the temp file with vscode and parses the feedback from the user.
15
+
16
+ *Input Interface*:
17
+ - `goal`
18
+ - `plan_file_location`
19
+
20
+ *Output Interface*:
21
+ - `plan`
22
+ - `feedback`
23
+ - `temp_plan_file_location`
24
+ """
25
+ REQUIRED_KEYS_CONFIG = ["max_rounds", "early_exit_key", "topology"]
26
+
27
+ def __init__(
28
+ self,
29
+ **kwargs
30
+ ):
31
+ super().__init__(**kwargs)
32
+
33
+ @classmethod
34
+ def instantiate_from_config(cls, config):
35
+ flow_config = deepcopy(config)
36
+
37
+ kwargs = {"flow_config": flow_config}
38
+
39
+ # ~~~ Set up subflows ~~~
40
+ kwargs.update({"subflows": cls._set_up_subflows(flow_config)})
41
+
42
+ # ~~~ Instantiate flow ~~~
43
+ return cls(**kwargs)
44
+
45
+ def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
46
+ # ~~~ sets the input_data in the flow_state dict ~~~
47
+ self._state_update_dict(update_data=input_data)
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
InteractivePlanGenFlow.yaml ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_: flow_modules.aiflows.InteractivePlanGenFlowModule.InteractivePlanGenFlow.instantiate_from_default_config
5
+
6
+ input_interface:
7
+ - "goal"
8
+ - "plan_file_location"
9
+
10
+ output_interface:
11
+ - "plan"
12
+ - "feedback"
13
+ - "temp_plan_file_location"
14
+
15
+ subflows_config:
16
+ PlanGenerator:
17
+ _target_: flow_modules.aiflows.PlanGeneratorFlowModule.PlanGeneratorAtomicFlow.instantiate_from_default_config
18
+ backend:
19
+ api_infos: ???
20
+ model_name:
21
+ openai: gpt-4
22
+ azure: azure/gpt-4
23
+
24
+ PlanFileEditor:
25
+ _target_: flow_modules.aiflows.PlanFileEditFlowModule.PlanFileEditAtomicFlow.instantiate_from_default_config
26
+
27
+ ParseFeedback:
28
+ _target_: flow_modules.aiflows.ParseFeedbackFlowModule.ParseFeedbackAtomicFlow.instantiate_from_default_config
29
+ input_interface:
30
+ - "temp_plan_file_location"
31
+ output_interface:
32
+ - "plan"
33
+ - "feedback"
34
+
35
+ early_exit_key: "EARLY_EXIT"
36
+
37
+ topology:
38
+ - goal: "Generate plan to achieve the task."
39
+ input_interface:
40
+ _target_: aiflows.interfaces.KeyInterface
41
+ additional_transformations:
42
+ - _target_: aiflows.data_transformations.KeyMatchInput
43
+ flow: PlanGenerator
44
+ reset: false
45
+
46
+ - goal: "Write the plan generated to a temp file with instructions to the user"
47
+ input_interface:
48
+ _target_: aiflows.interfaces.KeyInterface
49
+ additional_transformations:
50
+ - _target_: aiflows.data_transformations.KeyMatchInput
51
+ flow: PlanFileEditor
52
+ reset: false
53
+
54
+ - goal: "Parse user feedback from the temp file"
55
+ input_interface:
56
+ _target_: aiflows.interfaces.KeyInterface
57
+ additional_transformations:
58
+ - _target_: aiflows.data_transformations.KeyMatchInput
59
+ flow: ParseFeedback
60
+ reset: false
README.md CHANGED
@@ -1,3 +1,70 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Structure of InteractivePlanGenFlow
2
+
3
+ ```
4
+ goal
5
+ |
6
+ |
7
+ |
8
+ v
9
+ +------------------+
10
+ | PlanGenerator | Generates plan given goal. (https://huggingface.co/Tachi67/PlanGeneratorFlowModule)
11
+ +------------------+
12
+ |
13
+ | (plan)
14
+ |
15
+ v
16
+ +-------------------+
17
+ | PlanFileEdit | Edit a temp file with the plan generated. (https://huggingface.co/Tachi67/PlanFileEditFlowModule)
18
+ +-------------------+
19
+ |
20
+ | (temp_plan_file_location)
21
+ |
22
+ v
23
+ +------------------+
24
+ | ParseFeedback | Opens up the temp file until user closes the file, parse for user feedback. (https://huggingface.co/Tachi67/ParseFeedbackFlowModule)
25
+ +------------------+
26
+ |
27
+ | (plan, feedback)
28
+ |
29
+ v
30
+ plan, feedback
31
+
32
+ ```
33
+
34
+
35
+ # Table of Contents
36
+
37
+ * [InteractivePlanGenFlow](#InteractivePlanGenFlow)
38
+ * [InteractivePlanGenFlow](#InteractivePlanGenFlow.InteractivePlanGenFlow)
39
+ * [\_\_init\_\_](#__init__)
40
+
41
+ <a id="InteractivePlanGenFlow"></a>
42
+
43
+ # InteractivePlanGenFlow
44
+
45
+ <a id="InteractivePlanGenFlow.InteractivePlanGenFlow"></a>
46
+
47
+ ## InteractivePlanGenFlow Objects
48
+
49
+ ```python
50
+ class InteractivePlanGenFlow(SequentialFlow)
51
+ ```
52
+
53
+ This flow writes code in an interactive manner. It is a sequential flow composed of:
54
+ 1. PlanGenerator: generates plan based on the goal.
55
+ 2. PlanFileEditor: writes the generated plan to a temp file for the user to see, edit and provide feedback.
56
+ 3. ParseFeedback: opens up the temp file with vscode and parses the feedback from the user.
57
+
58
+ *Input Interface*:
59
+ - `goal`
60
+ - `plan_file_location`
61
+
62
+ *Output Interface*:
63
+ - `plan`
64
+ - `feedback`
65
+ - `temp_plan_file_location`
66
+
67
+ <a id="__init__"></a>
68
+
69
+ # \_\_init\_\_
70
+
__init__.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ~~~ Specify the dependencies ~~~
2
+ dependencies = [
3
+ {"url": "aiflows/PlanGeneratorFlowModule", "revision": "main"},
4
+ {"url": "aiflows/PlanFileEditFlowModule", "revision": "main"},
5
+ {"url": "aiflows/ParseFeedbackFlowModule", "revision": "main"},
6
+ ]
7
+ from aiflows import flow_verse
8
+
9
+ flow_verse.sync_dependencies(dependencies)
10
+
11
+ from .InteractivePlanGenFlow import InteractivePlanGenFlow
pip_requirements.txt ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ colorama==0.4.6
2
+ pytest==7.3.1
3
+ pytest-cov==4.1.0
4
+ hydra-core==1.3.2
5
+ hydra-colorlog==1.1.0
6
+ wrapt-timeout-decorator==1.3.12.2
7
+ diskcache==5.6.1
8
+ openai==1.0.0
9
+ huggingface_hub==0.19.4
10
+ jsonlines==3.1.0
11
+ jinja2==3.1.2
12
+ mock==5.0.2
13
+ rich==12.6.0
14
+ litellm==1.0.0
15
+ aiflows
run.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import hydra
4
+
5
+ from aiflows.backends.api_info import ApiInfo
6
+ from aiflows.messages import InputMessage
7
+ from aiflows.utils.general_helpers import read_yaml_file, quick_load
8
+
9
+ from aiflows import logging
10
+ from aiflows.flow_cache import CACHING_PARAMETERS, clear_cache
11
+
12
+ CACHING_PARAMETERS.do_caching = False # Set to True in order to disable caching
13
+
14
+ logging.set_verbosity_debug()
15
+ logging.auto_set_dir()
16
+
17
+ dependencies = [
18
+ {"url": "aiflows/InteractivePlanGenFlowModule", "revision": "main"},
19
+ ]
20
+
21
+ from aiflows import flow_verse
22
+
23
+ flow_verse.sync_dependencies(dependencies)
24
+
25
+ if __name__ == "__main__":
26
+ # ~~~ make sure to set the openai api key in the envs ~~~
27
+ key = os.getenv("OPENAI_API_KEY")
28
+ api_information = [ApiInfo(backend_used="openai", api_key=os.getenv("OPENAI_API_KEY"))]
29
+ current_dir = os.getcwd()
30
+ cfg_path = os.path.join(current_dir, "InteractivePlanGenFlow.yaml")
31
+ cfg = read_yaml_file(cfg_path)
32
+
33
+ with open(os.path.join(current_dir, "example_plan.txt"), "r") as f:
34
+ pass
35
+
36
+ # configuring api information
37
+ quick_load(cfg, api_information)
38
+
39
+ InteractivePlanGenFlow = hydra.utils.instantiate(cfg, _recursive_=False, _convert_="partial")
40
+
41
+
42
+ input_data = {
43
+ "goal": "write a function to add up two numbers",
44
+ "plan_file_location": os.path.join(current_dir, "example_plan.txt")
45
+ }
46
+ input_message = InputMessage.build(
47
+ data_dict=input_data,
48
+ src_flow="Launcher",
49
+ dst_flow=InteractivePlanGenFlow.name
50
+ )
51
+
52
+ # ~~~ calling the flow ~~~
53
+ output_message = InteractivePlanGenFlow(input_message)
54
+
55
+ print(output_message.data)