Tachi67 commited on
Commit
b7c0c96
·
1 Parent(s): 83bd82e

Upload 10 files

Browse files
PlanWriterAskUserFlow.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flow_modules.aiflows.HumanStandardInputFlowModule import HumanStandardInputFlow
2
+
3
+ from typing import Dict, Any
4
+
5
+ from aiflows.messages import UpdateMessage_Generic
6
+
7
+ from aiflows.utils import logging
8
+
9
+ log = logging.get_logger(f"aiflows.{__name__}")
10
+
11
+
12
+ class PlanWriterAskUserFlow(HumanStandardInputFlow):
13
+ """
14
+ Refer to: https://huggingface.co/Tachi67/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.py
15
+ """
16
+ def run(self,
17
+ input_data: Dict[str, Any]) -> Dict[str, Any]:
18
+
19
+ query_message = self._get_message(self.query_message_prompt_template, input_data)
20
+ state_update_message = UpdateMessage_Generic(
21
+ created_by=self.flow_config['name'],
22
+ updated_flow=self.flow_config["name"],
23
+ data={"query_message": query_message},
24
+ )
25
+ self._log_message(state_update_message)
26
+
27
+ log.info(query_message)
28
+ human_input = self._read_input()
29
+
30
+ response = {}
31
+ response["feedback"] = human_input
32
+ response["plan"] = "no plan was written"
33
+
34
+ return response
PlanWriterAskUserFlow.yaml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ _target_: flow_modules.aiflows.PlanWriterFlowModule.PlanWriterAskUserFlow.instantiate_from_default_config
2
+ request_multi_line_input_flag: False
3
+ end_of_input_string: EOI
4
+
5
+ query_message_prompt_template:
6
+ template: |2-
7
+ {{question}}
8
+ input_variables:
9
+ - "question"
PlanWriterCtrlFlow.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from copy import deepcopy
3
+ from typing import Any, Dict, List
4
+
5
+ from flow_modules.aiflows.ChatFlowModule import ChatAtomicFlow
6
+
7
+ from dataclasses import dataclass
8
+
9
+
10
+ @dataclass
11
+ class Command:
12
+ name: str
13
+ description: str
14
+ input_args: List[str]
15
+
16
+ class PlanWriterCtrlFlow(ChatAtomicFlow):
17
+ """Refer to: https://huggingface.co/Tachi67/JarvisFlowModule/blob/main/Controller_JarvisFlow.py
18
+ """
19
+ def __init__(
20
+ self,
21
+ commands: List[Command],
22
+ **kwargs):
23
+ super().__init__(**kwargs)
24
+ self.system_message_prompt_template = self.system_message_prompt_template.partial(
25
+ commands=self._build_commands_manual(commands),
26
+ )
27
+ self.hint_for_model = """
28
+ Make sure your response is in the following format:
29
+ Response Format:
30
+ {
31
+ "command": "call plan writer, or to finish with a summary",
32
+ "command_args": {
33
+ "arg name": "value"
34
+ }
35
+ }
36
+ """
37
+
38
+ @staticmethod
39
+ def _build_commands_manual(commands: List[Command]) -> str:
40
+ ret = ""
41
+ for i, command in enumerate(commands):
42
+ command_input_json_schema = json.dumps(
43
+ {input_arg: f"YOUR_{input_arg.upper()}" for input_arg in command.input_args})
44
+ ret += f"{i + 1}. {command.name}: {command.description} Input arguments (given in the JSON schema): {command_input_json_schema}\n"
45
+ return ret
46
+
47
+ @classmethod
48
+ def instantiate_from_config(cls, config):
49
+ flow_config = deepcopy(config)
50
+
51
+ kwargs = {"flow_config": flow_config}
52
+
53
+ # ~~~ Set up prompts ~~~
54
+ kwargs.update(cls._set_up_prompts(flow_config))
55
+
56
+ # ~~~Set up backend ~~~
57
+ kwargs.update(cls._set_up_backend(flow_config))
58
+
59
+ # ~~~ Set up commands ~~~
60
+ commands = flow_config["commands"]
61
+ commands = [
62
+ Command(name, command_conf["description"], command_conf["input_args"]) for name, command_conf in
63
+ commands.items()
64
+ ]
65
+ kwargs.update({"commands": commands})
66
+
67
+ # ~~~ Instantiate flow ~~~
68
+ return cls(**kwargs)
69
+
70
+ def _update_prompts_and_input(self, input_data: Dict[str, Any]):
71
+ if 'goal' in input_data:
72
+ input_data['goal'] += self.hint_for_model
73
+ if 'feedback' in input_data:
74
+ input_data['feedback'] += self.hint_for_model
75
+
76
+ def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
77
+ self._update_prompts_and_input(input_data)
78
+
79
+ # ~~~when conversation is initialized, append the updated system prompts to the chat history ~~~
80
+ if self._is_conversation_initialized():
81
+ updated_system_message_content = self._get_message(self.system_message_prompt_template, input_data)
82
+ self._state_update_add_chat_message(content=updated_system_message_content,
83
+ role=self.flow_config["system_name"])
84
+
85
+ while True:
86
+ api_output = super().run(input_data)["api_output"].strip()
87
+ try:
88
+ response = json.loads(api_output)
89
+ return response
90
+ except (json.decoder.JSONDecodeError, json.JSONDecodeError):
91
+ updated_system_message_content = self._get_message(self.system_message_prompt_template, input_data)
92
+ self._state_update_add_chat_message(content=updated_system_message_content,
93
+ role=self.flow_config["system_name"])
94
+ new_goal = "The previous respond cannot be parsed with json.loads. Next time, do not provide any comments or code blocks. Make sure your next response is purely json parsable."
95
+ new_input_data = input_data.copy()
96
+ new_input_data['feedback'] = new_goal
97
+ input_data = new_input_data
PlanWriterCtrlFlow.yaml ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ _target_: flow_modules.aiflows.PlanWriterFlowModule.PlanWriterCtrlFlow.instantiate_from_default_config
2
+ name: "PlanWriterControllerFlow"
3
+ description: "Proposes the next action to take towards achieving the goal, and prepares the input for the branching flow"
4
+ enable_cache: True
5
+
6
+ #######################################################
7
+ # Input keys
8
+ #######################################################
9
+
10
+ input_interface_non_initialized: # initial input keys
11
+ - "goal"
12
+
13
+ input_interface_initialized:
14
+ - "goal"
15
+ - "plan"
16
+ - "feedback"
17
+
18
+ #######################################################
19
+ # Output keys
20
+ #######################################################
21
+
22
+ output_interface:
23
+ - 'command'
24
+ - 'command_args'
25
+
26
+ backend:
27
+ api_infos: ???
28
+ model_name:
29
+ openai: gpt-4
30
+ azure: azure/gpt-4
31
+
32
+ commands:
33
+ write_plan:
34
+ description: "Write plan to finish the goal with user interaction"
35
+ input_args: ["goal"]
36
+ finish:
37
+ description: "Signal that the objective has been satisfied, return the summary of what was done"
38
+ input_args: ["summary"]
39
+ manual_finish:
40
+ description: "The user demands to quit and terminate the current process"
41
+ input_args: []
42
+ ask_user:
43
+ description: "Ask user a question for confirmation or assistance"
44
+ input_args: ["question"]
45
+
46
+ system_message_prompt_template:
47
+ _target_: langchain.PromptTemplate
48
+ template: |2-
49
+ You are in charge of a department of writing plans to solve a certain goal. You work with a planner, who does all the planning job.
50
+
51
+ Your **ONLY** task is to take the user's goal for you, to decide whether to call the planner to write or re-write the plan, or to finish the current task.
52
+
53
+ Here is the goal you need to achieve:
54
+ {{goal}}
55
+
56
+ When you need to call the plan writer, call the `write_plan` command with the goal specified.
57
+ When the plan is written and the user is satisfied, call the `finish` command to terminate the current process with a summary of what was done in one sentence.
58
+ Whenever you are in doubt, or need to confirm something to the user, call `ask_user` with the question.
59
+
60
+ You **must not** write plans yourself. You only decide whether to call the planner with specified goals or to finish.
61
+
62
+ Your workflow:
63
+ 0. Whenever the user demands to quit or terminate the current process, call `manual_finish` command.
64
+ 1. Upon user request, call the `write_plan` with the goal given.
65
+ 2. The planner will write the plan. The user will examine the plan, and provide feedback.
66
+ 3. Depending on the feedback of the user:
67
+ 3.1. The user provides feedback on how to change the plan, **call the planner with user's specific requirements again, to ask the planner to refine the plan**. Go back to step 2.
68
+ 3.2. The user does not provide details about refining the plan, for example, just stating the fact that the user has updated the plan, **this means the user is satisfied with the plan written, call the `finish` command.**
69
+ 3.3. The user is satisfied with the plan, **call the `finish` command with a summary of what was done**
70
+
71
+ If you have completed all your tasks, make sure to use the "finish" command, with a summary of what was done.
72
+
73
+ Constraints:
74
+ 1. Exclusively use the commands listed in double quotes e.g. "command name"
75
+
76
+ Your response **MUST** be in the following format:
77
+ Response Format:
78
+ {
79
+ "command": "call plan writer, or to finish",
80
+ "command_args": {
81
+ "arg name": "value"
82
+ }
83
+ }
84
+ Ensure your responses can be parsed by Python json.loads
85
+
86
+
87
+ Available Functions:
88
+ {{commands}}
89
+ input_variables: ["commands", "goal"]
90
+ template_format: jinja2
91
+
92
+ human_message_prompt_template:
93
+ _target_: aiflows.prompt_template.JinjaPrompt
94
+ template: |2-
95
+ Here is the plan written by the planner, it might have been updated by the user, depending on the user's feedback:
96
+ {{plan}}
97
+ Here is the feedback from the user:
98
+ {{feedback}}
99
+ input_variables:
100
+ - "plan"
101
+ - "feedback"
102
+ template_format: jinja2
103
+
104
+ init_human_message_prompt_template:
105
+ _target_: aiflows.prompt_template.JinjaPrompt
106
+ template: |2-
107
+ Here is the goal you need to achieve:
108
+ {{goal}}
109
+ input_variables:
110
+ - "goal"
111
+ template_format: jinja2
112
+
113
+ previous_messages:
114
+ last_k: 3
PlanWriterFlow.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, Any
2
+ import os
3
+
4
+ from flow_modules.aiflows.ContentWriterFlowModule import ContentWriterFlow
5
+ from aiflows.base_flows import CircularFlow
6
+
7
+
8
+ class PlanWriterFlow(ContentWriterFlow):
9
+ """This flow inherits from ContentWriterFlow.
10
+ In the subflow of the executor, we specify the InteractivePlanGneFlow (https://huggingface.co/Tachi67/InteractivePlanGenFlowModule)
11
+
12
+ *Input Interface*:
13
+ - `goal`
14
+
15
+ *Output Interface*:
16
+ - `plan`
17
+ - `result`
18
+ - `summary`
19
+ - `status`
20
+ """
21
+ def _on_reach_max_round(self):
22
+ self._state_update_dict({
23
+ "plan": "The maximum amount of rounds was reached before the model generated the plan.",
24
+ "status": "unfinished"
25
+ })
26
+
27
+ @CircularFlow.output_msg_payload_processor
28
+ def detect_finish_or_continue(self, output_payload: Dict[str, Any], src_flow) -> Dict[str, Any]:
29
+ command = output_payload["command"]
30
+ if command == "finish":
31
+ # ~~~ fetch temp file location, plan content, memory file (of upper level flow e.g. ExtLib) from flow state
32
+ keys_to_fetch_from_state = ["temp_plan_file_location", "plan", "memory_files"]
33
+ fetched_state = self._fetch_state_attributes_by_keys(keys=keys_to_fetch_from_state)
34
+ temp_plan_file_location = fetched_state["temp_plan_file_location"]
35
+ plan_content = fetched_state["plan"]
36
+ plan_file_location = fetched_state["memory_files"]["plan"]
37
+
38
+ # ~~~ delete the temp plan file ~~~
39
+ if os.path.exists(temp_plan_file_location):
40
+ os.remove(temp_plan_file_location)
41
+
42
+ # ~~~ write plan content to plan file ~~~
43
+ with open(plan_file_location, 'w') as file:
44
+ file.write(plan_content)
45
+
46
+ # ~~~ return the plan content ~~~
47
+ return {
48
+ "EARLY_EXIT": True,
49
+ "plan": plan_content,
50
+ "summary": "ExtendLibrary/PlanWriter: " + output_payload["command_args"]["summary"],
51
+ "status": "finished"
52
+ }
53
+ elif command == "manual_finish":
54
+ # ~~~ delete the temp plan file ~~~
55
+ keys_to_fetch_from_state = ["temp_plan_file_location"]
56
+ fetched_state = self._fetch_state_attributes_by_keys(keys=keys_to_fetch_from_state)
57
+ temp_plan_file_location = fetched_state["temp_plan_file_location"]
58
+ if os.path.exists(temp_plan_file_location):
59
+ os.remove(temp_plan_file_location)
60
+ # ~~~ return the manual quit status ~~~
61
+ return {
62
+ "EARLY_EXIT": True,
63
+ "plan": "no plan was generated",
64
+ "summary": "ExtendLibrary/PlanWriter: PlanWriter was terminated explicitly by the user, process is unfinished",
65
+ "status": "unfinished"
66
+ }
67
+ elif command == "write_plan":
68
+ keys_to_fetch_from_state = ["memory_files"]
69
+ fetched_state = self._fetch_state_attributes_by_keys(keys=keys_to_fetch_from_state)
70
+ plan_file_location = fetched_state["memory_files"]["plan"]
71
+ output_payload["command_args"]["plan_file_location"] = plan_file_location
72
+ return output_payload
73
+ else:
74
+ return output_payload
75
+
76
+ def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
77
+ # ~~~ sets the input_data in the flow_state dict ~~~
78
+ self._state_update_dict(update_data=input_data)
79
+
80
+ max_rounds = self.flow_config.get("max_rounds", 1)
81
+ if max_rounds is None:
82
+ log.info(f"Running {self.flow_config['name']} without `max_rounds` until the early exit condition is met.")
83
+
84
+ self._sequential_run(max_rounds=max_rounds)
85
+
86
+ output = self._get_output_from_state()
87
+
88
+ self.reset(full_reset=True, recursive=True, src_flow=self)
89
+
90
+ return output
PlanWriterFlow.yaml ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "PlanWriter"
2
+ description: "Generates plan with interactions with the user"
3
+
4
+ _target_: flow_modules.aiflows.PlanWriterFlowModule.PlanWriterFlow.instantiate_from_default_config
5
+
6
+ input_interface:
7
+ - "goal"
8
+ - "memory_files"
9
+
10
+ output_interface:
11
+ - "plan"
12
+ - "status"
13
+ - "summary"
14
+
15
+ ### Subflows specification
16
+ subflows_config:
17
+ Controller:
18
+ _target_: flow_modules.aiflows.PlanWriterFlowModule.PlanWriterCtrlFlow.instantiate_from_default_config
19
+ backend:
20
+ api_infos: ???
21
+ model_name:
22
+ openai: gpt-4
23
+ azure: azure/gpt-4
24
+
25
+ Executor:
26
+ _target_: aiflows.base_flows.BranchingFlow.instantiate_from_default_config
27
+ subflows_config:
28
+ write_plan:
29
+ _target_: flow_modules.aiflows.InteractivePlanGenFlowModule.InteractivePlanGenFlow.instantiate_from_default_config
30
+ subflows_config:
31
+ PlanGenerator:
32
+ _target_: flow_modules.aiflows.PlanGeneratorFlowModule.PlanGeneratorAtomicFlow.instantiate_from_default_config
33
+ backend:
34
+ api_infos: ???
35
+ model_name:
36
+ openai: gpt-4
37
+ azure: azure/gpt-4
38
+
39
+ PlanFileEditor:
40
+ _target_: flow_modules.aiflows.PlanFileEditFlowModule.PlanFileEditAtomicFlow.instantiate_from_default_config
41
+
42
+ ParseFeedback:
43
+ _target_: flow_modules.aiflows.ParseFeedbackFlowModule.ParseFeedbackAtomicFlow.instantiate_from_default_config
44
+ input_interface:
45
+ - "temp_plan_file_location"
46
+ output_interface:
47
+ - "plan"
48
+ - "feedback"
49
+
50
+ ask_user:
51
+ _target_: flow_modules.aiflows.PlanWriterFlowModule.PlanWriterAskUserFlow.instantiate_from_default_config
52
+
53
+
54
+ early_exit_key: "EARLY_EXIT"
55
+
56
+ topology:
57
+ - goal: "Select the next action and prepare the input for the executor."
58
+ input_interface:
59
+ _target_: aiflows.interfaces.KeyInterface
60
+ additional_transformations:
61
+ - _target_: aiflows.data_transformations.KeyMatchInput
62
+ flow: Controller
63
+ output_interface:
64
+ _target_: PlanWriterFlow.detect_finish_or_continue
65
+ reset: false
66
+
67
+ - goal: "Execute the action specified by the Controller."
68
+ input_interface:
69
+ _target_: aiflows.interfaces.KeyInterface
70
+ keys_to_rename:
71
+ command: branch
72
+ command_args: branch_input_data
73
+ keys_to_select: ["branch", "branch_input_data"]
74
+ flow: Executor
75
+ output_interface:
76
+ _target_: aiflows.interfaces.KeyInterface
77
+ keys_to_rename:
78
+ branch_output_data.plan: plan
79
+ branch_output_data.feedback: feedback
80
+ branch_output_data.temp_plan_file_location: temp_plan_file_location
81
+ keys_to_delete: ["branch_output_data"]
82
+ reset: false
README.md CHANGED
@@ -1,3 +1,119 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Structure of PlanWriterFlow
2
+
3
+ ```
4
+ goal
5
+ |
6
+ v
7
+ +---------------+
8
+ | Controller | --------<<<<-----------+
9
+ +---------------+ |
10
+ | |
11
+ | (command, command args) |
12
+ | |
13
+ v |
14
+ +------------------+ |
15
+ | Executor | Each branch is an |
16
+ | (Tree Structure) | executor |
17
+ +------------------+ |
18
+ | ^
19
+ | (summary) |
20
+ | |
21
+ v |
22
+ | |
23
+ +-> goes back to the Controller>-+
24
+
25
+ ```
26
+
27
+ Structure of the Executors:
28
+ ```
29
+ +-------------------+
30
+ | Branching |
31
+ | Executor |
32
+ +-------------------+
33
+ / \
34
+ / \
35
+ / \
36
+ / \
37
+ write_plan ask_user
38
+
39
+ ```
40
+
41
+ About the branches:
42
+ - [ask_user](https://huggingface.co/Tachi67/PlanWriterFlowModule/blob/main/PlanWriterAskUserFlow.py): Ask user for info / confirmation, etc.
43
+ - [write_plan](https://huggingface.co/Tachi67/InteractivePlanGenFlowModule): Generates plan (user edit is allowed) and fetches user feedback.
44
+
45
+ How it works:
46
+ Controller calls write_plan until user is satisfied in the feedback, finish.
47
+
48
+
49
+ # Table of Contents
50
+
51
+ * [run\_planwriter](#run_planwriter)
52
+ * [PlanWriterAskUserFlow](#PlanWriterAskUserFlow)
53
+ * [PlanWriterAskUserFlow](#PlanWriterAskUserFlow.PlanWriterAskUserFlow)
54
+ * [PlanWriterFlow](#PlanWriterFlow)
55
+ * [PlanWriterFlow](#PlanWriterFlow.PlanWriterFlow)
56
+ * [\_\_init\_\_](#__init__)
57
+ * [PlanWriterCtrlFlow](#PlanWriterCtrlFlow)
58
+ * [PlanWriterCtrlFlow](#PlanWriterCtrlFlow.PlanWriterCtrlFlow)
59
+
60
+ <a id="run_planwriter"></a>
61
+
62
+ # run\_planwriter
63
+
64
+ <a id="PlanWriterAskUserFlow"></a>
65
+
66
+ # PlanWriterAskUserFlow
67
+
68
+ <a id="PlanWriterAskUserFlow.PlanWriterAskUserFlow"></a>
69
+
70
+ ## PlanWriterAskUserFlow Objects
71
+
72
+ ```python
73
+ class PlanWriterAskUserFlow(HumanStandardInputFlow)
74
+ ```
75
+
76
+ Refer to: https://huggingface.co/Tachi67/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.py
77
+
78
+ <a id="PlanWriterFlow"></a>
79
+
80
+ # PlanWriterFlow
81
+
82
+ <a id="PlanWriterFlow.PlanWriterFlow"></a>
83
+
84
+ ## PlanWriterFlow Objects
85
+
86
+ ```python
87
+ class PlanWriterFlow(ContentWriterFlow)
88
+ ```
89
+
90
+ This flow inherits from ContentWriterFlow.
91
+ In the subflow of the executor, we specify the InteractivePlanGneFlow (https://huggingface.co/Tachi67/InteractivePlanGenFlowModule)
92
+
93
+ *Input Interface*:
94
+ - `goal`
95
+
96
+ *Output Interface*:
97
+ - `plan`
98
+ - `result`
99
+ - `summary`
100
+ - `status`
101
+
102
+ <a id="__init__"></a>
103
+
104
+ # \_\_init\_\_
105
+
106
+ <a id="PlanWriterCtrlFlow"></a>
107
+
108
+ # PlanWriterCtrlFlow
109
+
110
+ <a id="PlanWriterCtrlFlow.PlanWriterCtrlFlow"></a>
111
+
112
+ ## PlanWriterCtrlFlow Objects
113
+
114
+ ```python
115
+ class PlanWriterCtrlFlow(ChatAtomicFlow)
116
+ ```
117
+
118
+ Refer to: https://huggingface.co/Tachi67/JarvisFlowModule/blob/main/Controller_JarvisFlow.py
119
+
__init__.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ dependencies = [
2
+ {"url": "aiflows/ContentWriterFlowModule", "revision": "main"},
3
+ {"url": "aiflows/InteractivePlanGenFlowModule", "revision": "main"},
4
+ {"url": "aiflows/ChatFlowModule", "revision": "297c90d08087d9ff3139521f11d1a48d7dc63ed4"},
5
+ {"url": "aiflows/HumanStandardInputFlowModule", "revision": "4ff043522c89a964ea3a928ce09811c51a2b5b98"}
6
+ ]
7
+ from aiflows import flow_verse
8
+
9
+ flow_verse.sync_dependencies(dependencies)
10
+
11
+ from .PlanWriterFlow import PlanWriterFlow
12
+ from .PlanWriterCtrlFlow import PlanWriterCtrlFlow
13
+ from .PlanWriterAskUserFlow import PlanWriterAskUserFlow
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_planwriter.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
8
+
9
+ from aiflows import logging
10
+ from aiflows.flow_cache import CACHING_PARAMETERS, clear_cache
11
+ from aiflows.utils.general_helpers import quick_load
12
+
13
+ CACHING_PARAMETERS.do_caching = False # Set to True in order to disable caching
14
+ # clear_cache() # Uncomment this line to clear the cache
15
+
16
+ logging.set_verbosity_debug()
17
+ logging.auto_set_dir()
18
+
19
+ dependencies = [
20
+ {"url": "aiflows/ContentWriterFlowModule", "revision": "main"},
21
+ {"url": "aiflows/InteractivePlanGenFlowModule", "revision": "main"},
22
+ {"url": "aiflows/PlanWriterFlowModule", "revision": "main"},
23
+ {"url": "aiflows/ChatFlowModule", "revision": "297c90d08087d9ff3139521f11d1a48d7dc63ed4"},
24
+ ]
25
+
26
+ from aiflows import flow_verse
27
+
28
+ flow_verse.sync_dependencies(dependencies)
29
+
30
+ if __name__ == "__main__":
31
+ # ~~~ make sure to set the openai api key in the envs ~~~
32
+ key = os.getenv("OPENAI_API_KEY")
33
+ api_information = [ApiInfo(backend_used="openai", api_key=os.getenv("OPENAI_API_KEY"))]
34
+ path_to_output_file = None
35
+
36
+ current_dir = os.getcwd()
37
+ cfg_path = os.path.join(current_dir, "PlanWriterFlow.yaml")
38
+ cfg = read_yaml_file(cfg_path)
39
+
40
+ # ~~~ setting api information into config ~~~
41
+ quick_load(cfg, api_information)
42
+
43
+ # ~~~ instantiating the flow and input data ~~~
44
+ PlanWriterFlow = hydra.utils.instantiate(cfg, _recursive_=False, _convert_="partial")
45
+
46
+ # ~~~ creating the plan file location (of the upper level flow e.g. ExtLib)
47
+ plan_file_location = os.path.join(current_dir, "ExtLib_plan.txt")
48
+ with open(plan_file_location, 'w') as file:
49
+ pass
50
+
51
+ mem_files = {"plan": plan_file_location}
52
+
53
+ input_data = {
54
+ "goal": "create a function that adds two numbers and returns the result",
55
+ "memory_files": mem_files
56
+ }
57
+ input_message = InputMessage.build(
58
+ data_dict=input_data,
59
+ src_flow="Launcher",
60
+ dst_flow=PlanWriterFlow.name
61
+ )
62
+
63
+ # ~~~ calling the flow ~~~
64
+ output_message = PlanWriterFlow(input_message)