Tachi67 commited on
Commit
9c31af5
·
verified ·
1 Parent(s): 97c2789

add more docs and comments

Browse files
ControllerFlow_ExtLib.py CHANGED
@@ -13,12 +13,49 @@ class Command:
13
  description: str
14
  input_args: List[str]
15
 
 
16
  class ControllerFlow_ExtLib(ChatAtomicFlow):
17
- """Refer to: https://huggingface.co/Tachi67/JarvisFlowModule/blob/main/Controller_JarvisFlow.py"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  def __init__(
19
  self,
20
  commands: List[Command],
21
  **kwargs):
 
 
 
 
 
22
  super().__init__(**kwargs)
23
  self.system_message_prompt_template = self.system_message_prompt_template.partial(
24
  commands=self._build_commands_manual(commands),
@@ -39,6 +76,13 @@ class ControllerFlow_ExtLib(ChatAtomicFlow):
39
 
40
  @staticmethod
41
  def _build_commands_manual(commands: List[Command]) -> str:
 
 
 
 
 
 
 
42
  ret = ""
43
  for i, command in enumerate(commands):
44
  command_input_json_schema = json.dumps(
@@ -47,11 +91,27 @@ class ControllerFlow_ExtLib(ChatAtomicFlow):
47
  return ret
48
 
49
  def _get_plan_file_location(self, input_data: Dict[str, Any]):
 
 
 
 
 
 
 
 
 
50
  assert "memory_files" in input_data, "memory_files not passed to Extlib/Controller"
51
  assert "plan" in input_data["memory_files"], "plan not in memory files"
52
  return input_data["memory_files"]["plan"]
53
 
54
  def _get_plan_content(self, input_data: Dict[str, Any]):
 
 
 
 
 
 
 
55
  assert "plan" in input_data, "plan not passed to Extlib/Controller"
56
  plan_content = input_data["plan"]
57
  if len(plan_content) == 0:
@@ -59,6 +119,13 @@ class ControllerFlow_ExtLib(ChatAtomicFlow):
59
  return plan_content
60
 
61
  def _get_logs_content(self, input_data: Dict[str, Any]):
 
 
 
 
 
 
 
62
  assert "logs" in input_data, "logs not passed to Extlib/Controller"
63
  logs_content = input_data["logs"]
64
  if len(logs_content) == 0:
@@ -67,6 +134,12 @@ class ControllerFlow_ExtLib(ChatAtomicFlow):
67
 
68
  @classmethod
69
  def instantiate_from_config(cls, config):
 
 
 
 
 
 
70
  flow_config = deepcopy(config)
71
 
72
  kwargs = {"flow_config": flow_config}
@@ -89,6 +162,10 @@ class ControllerFlow_ExtLib(ChatAtomicFlow):
89
  return cls(**kwargs)
90
 
91
  def _update_prompts_and_input(self, input_data: Dict[str, Any]):
 
 
 
 
92
  if 'goal' in input_data:
93
  input_data['goal'] += self.hint_for_model
94
  if 'result' in input_data:
@@ -103,6 +180,12 @@ class ControllerFlow_ExtLib(ChatAtomicFlow):
103
  )
104
 
105
  def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
 
 
 
 
 
 
106
  self._update_prompts_and_input(input_data)
107
 
108
  # ~~~when conversation is initialized, append the updated system prompts to the chat history ~~~
 
13
  description: str
14
  input_args: List[str]
15
 
16
+
17
  class ControllerFlow_ExtLib(ChatAtomicFlow):
18
+ """Refer to: https://huggingface.co/aiflows/JarvisFlowModule/blob/main/Controller_JarvisFlow.py for a detailed doc.
19
+ This flow inherits from ChatAtomicFlow and is used as a controller of the ExtendLibraryFlow.
20
+
21
+ *Input Interface Non Initialized*:
22
+ - `goal`
23
+ - `memory_files`
24
+ - `plan`
25
+ - `logs`
26
+
27
+ *Input Interface Initialized*:
28
+ - `goal`
29
+ - `memory_files`
30
+ - `plan`
31
+ - `logs`
32
+ - `result`
33
+
34
+ *Output Interface*:
35
+ - `command`
36
+ - `command_args`
37
+
38
+ *Configuration Parameters*:
39
+ - `input_interface_non_initialized`: a list of input interface names when the conversation starts.
40
+ - `input_interface_initialized`: a list of input interface names when the conversation is initialized.
41
+ - `output_interface`: the output of the controller, it is the command and the command arguments.
42
+ - `commands`: a list of commands that the controller can call. Each command has a name, a description, and a list of input arguments.
43
+ - `system_message_prompt_template`: the system message prompt template.
44
+ - `init_human_message_prompt_template`: the initial human (user) message prompt template.
45
+ - `human_message_prompt_template`: the human (user) message prompt template.
46
+ - `previous_messages`: the sliding window of previous messages.
47
+
48
+
49
+ """
50
  def __init__(
51
  self,
52
  commands: List[Command],
53
  **kwargs):
54
+ """
55
+ The constructor of the ControllerFlow_ExtLib class.
56
+ :param commands: a list of commands that the controller can call. Each command has a name, a description, and a list of input arguments.
57
+ :param kwargs: the configuration parameters of the ControllerFlow_ExtLib class.
58
+ """
59
  super().__init__(**kwargs)
60
  self.system_message_prompt_template = self.system_message_prompt_template.partial(
61
  commands=self._build_commands_manual(commands),
 
76
 
77
  @staticmethod
78
  def _build_commands_manual(commands: List[Command]) -> str:
79
+ """
80
+ Build the manual for the commands.
81
+ :param commands: a list of commands that the controller can call. Each command has a name, a description, and a list of input arguments.
82
+ :type commands: List[Command]
83
+ :return: the manual for the commands.
84
+ :rtype: str
85
+ """
86
  ret = ""
87
  for i, command in enumerate(commands):
88
  command_input_json_schema = json.dumps(
 
91
  return ret
92
 
93
  def _get_plan_file_location(self, input_data: Dict[str, Any]):
94
+ """ Get the plan file location from the input data.
95
+ :param input_data: the input data.
96
+ :raise AssertionError: if the plan file location is not passed to the controller.
97
+ :raise AssertionError: if the plan file location is not in the memory files.
98
+ :raise AssertionError: if the plan is not in the memory files.
99
+ :type input_data: Dict[str, Any]
100
+ :return: the plan file location.
101
+ :rtype: str
102
+ """
103
  assert "memory_files" in input_data, "memory_files not passed to Extlib/Controller"
104
  assert "plan" in input_data["memory_files"], "plan not in memory files"
105
  return input_data["memory_files"]["plan"]
106
 
107
  def _get_plan_content(self, input_data: Dict[str, Any]):
108
+ """ Get the plan content from the input data.
109
+ :param input_data: the input data.
110
+ :raise AssertionError: if the plan is not passed to the controller.
111
+ :type input_data: Dict[str, Any]
112
+ :return: the plan content.
113
+ :rtype: str
114
+ """
115
  assert "plan" in input_data, "plan not passed to Extlib/Controller"
116
  plan_content = input_data["plan"]
117
  if len(plan_content) == 0:
 
119
  return plan_content
120
 
121
  def _get_logs_content(self, input_data: Dict[str, Any]):
122
+ """ Get the logs content from the input data.
123
+ :param input_data: the input data.
124
+ :raise AssertionError: if the logs is not passed to the controller.
125
+ :type input_data: Dict[str, Any]
126
+ :return: the logs content.
127
+ :rtype: str
128
+ """
129
  assert "logs" in input_data, "logs not passed to Extlib/Controller"
130
  logs_content = input_data["logs"]
131
  if len(logs_content) == 0:
 
134
 
135
  @classmethod
136
  def instantiate_from_config(cls, config):
137
+ """Instantiate the flow from a configuration.
138
+ :param config: the configuration.
139
+ :type config: Dict[str, Any]
140
+ :return: the instantiated flow.
141
+ :rtype: ControllerFlow_ExtLib
142
+ """
143
  flow_config = deepcopy(config)
144
 
145
  kwargs = {"flow_config": flow_config}
 
162
  return cls(**kwargs)
163
 
164
  def _update_prompts_and_input(self, input_data: Dict[str, Any]):
165
+ """Update the prompts and the input data. The system prompts are updated with the new memory.
166
+ :param input_data: the input data.
167
+ :type input_data: Dict[str, Any]
168
+ """
169
  if 'goal' in input_data:
170
  input_data['goal'] += self.hint_for_model
171
  if 'result' in input_data:
 
180
  )
181
 
182
  def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
183
+ """Run the flow.
184
+ :param input_data: the input data.
185
+ :type input_data: Dict[str, Any]
186
+ :return: the output of the flow.
187
+ :rtype: Dict[str, Any]
188
+ """
189
  self._update_prompts_and_input(input_data)
190
 
191
  # ~~~when conversation is initialized, append the updated system prompts to the chat history ~~~
CtrlExMem_ExtLib.py CHANGED
@@ -5,17 +5,23 @@ from aiflows.base_flows import CircularFlow
5
 
6
  class CtrlExMem_ExtLib(CtrlExMemFlow):
7
  """This class inherits from the CtrlExMemFlow class from AbstractBossFlowModule.
8
- See: https://huggingface.co/Tachi67/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py
 
 
9
  *Input Interface*:
10
  - `plan`
11
  - `logs`
12
  - `memory_files`
13
  - `goal`
 
14
  *Output Interface*
15
  - `result` (str): The result of the flow, the result will be returned to the caller.
16
  - `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow.
 
17
  """
18
  def _on_reach_max_round(self):
 
 
19
  self._state_update_dict({
20
  "result": "the maximum amount of rounds was reached before the extend library flow has done the job",
21
  "summary": "ExtendLibraryFlow: the maximum amount of rounds was reached before the flow has done the job",
@@ -24,6 +30,14 @@ class CtrlExMem_ExtLib(CtrlExMemFlow):
24
 
25
  @CircularFlow.output_msg_payload_processor
26
  def detect_finish_or_continue(self, output_payload: Dict[str, Any], src_flow) -> Dict[str, Any]:
 
 
 
 
 
 
 
 
27
  command = output_payload["command"]
28
  if command == "finish":
29
  return {
 
5
 
6
  class CtrlExMem_ExtLib(CtrlExMemFlow):
7
  """This class inherits from the CtrlExMemFlow class from AbstractBossFlowModule.
8
+
9
+ See: https://huggingface.co/aiflows/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py
10
+
11
  *Input Interface*:
12
  - `plan`
13
  - `logs`
14
  - `memory_files`
15
  - `goal`
16
+
17
  *Output Interface*
18
  - `result` (str): The result of the flow, the result will be returned to the caller.
19
  - `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow.
20
+
21
  """
22
  def _on_reach_max_round(self):
23
+ """This method is called when the flow reaches the maximum amount of rounds.
24
+ """
25
  self._state_update_dict({
26
  "result": "the maximum amount of rounds was reached before the extend library flow has done the job",
27
  "summary": "ExtendLibraryFlow: the maximum amount of rounds was reached before the flow has done the job",
 
30
 
31
  @CircularFlow.output_msg_payload_processor
32
  def detect_finish_or_continue(self, output_payload: Dict[str, Any], src_flow) -> Dict[str, Any]:
33
+ """This method is called when the flow receives a message from the child flow.
34
+ :param output_payload: The output payload of the child flow.
35
+ :type output_payload: Dict[str, Any]
36
+ :param src_flow: The child flow.
37
+ :type src_flow: AbstractBossFlowModule
38
+ :return: The processed output payload.
39
+ :rtype: Dict[str, Any]
40
+ """
41
  command = output_payload["command"]
42
  if command == "finish":
43
  return {
ExtLibAskUserFlow.py CHANGED
@@ -8,23 +8,33 @@ from aiflows.utils import logging
8
 
9
  log = logging.get_logger(f"aiflows.{__name__}")
10
 
11
- # TODO: extract this flow to a seperate flow module for modularity.
12
  class ExtLibAskUserFlow(HumanStandardInputFlow):
13
  """This class is used to ask for user feedback whenever the controller is unsure of something, or need confirmation, etc.
14
 
15
- *Expected Input*:
16
  - `question`: The question asked by the controller
17
 
18
  *Expected Behaviour*:
19
- - The question is displayed, and the user gives feedback by inputing string.
20
 
21
- *Expected Ouput*:
22
  - `result`: The input of the user.
23
  - `summary`: The summary that will be written by the caller.
 
 
 
 
 
 
24
  """
25
  def run(self,
26
  input_data: Dict[str, Any]) -> Dict[str, Any]:
27
-
 
 
 
 
 
28
  query_message = self._get_message(self.query_message_prompt_template, input_data)
29
  state_update_message = UpdateMessage_Generic(
30
  created_by=self.flow_config['name'],
 
8
 
9
  log = logging.get_logger(f"aiflows.{__name__}")
10
 
 
11
  class ExtLibAskUserFlow(HumanStandardInputFlow):
12
  """This class is used to ask for user feedback whenever the controller is unsure of something, or need confirmation, etc.
13
 
14
+ *Input Interface*:
15
  - `question`: The question asked by the controller
16
 
17
  *Expected Behaviour*:
18
+ - The question is displayed, and the user gives feedback by input string.
19
 
20
+ *Output Interface*:
21
  - `result`: The input of the user.
22
  - `summary`: The summary that will be written by the caller.
23
+
24
+ *Configuration Parameters*:
25
+ - `query_message_prompt_template`: The template of the message that is displayed to the user.
26
+ - `request_multi_line_input`: Whether the user should be able to input multiple lines. Default: False.
27
+ - `end_of_input_string`: The string that the user can input to indicate that he/she is done with the input. Default: EOI
28
+
29
  """
30
  def run(self,
31
  input_data: Dict[str, Any]) -> Dict[str, Any]:
32
+ """Run the flow module.
33
+ :param input_data: The input data.
34
+ :type input_data: Dict[str, Any]
35
+ :return: The output data.
36
+ :rtype: Dict[str, Any]
37
+ """
38
  query_message = self._get_message(self.query_message_prompt_template, input_data)
39
  state_update_message = UpdateMessage_Generic(
40
  created_by=self.flow_config['name'],
ExtendLibraryFlow.py CHANGED
@@ -17,13 +17,29 @@ class ExtendLibraryFlow(AbstractBossFlow):
17
  5. Finish, writes code to the library.
18
  Step 3-5 is done via prompting the controller.
19
 
 
 
20
  *Input Interface (expected input)*
21
  - `goal` (str): The goal from the caller (source flow, i.e. CoderFlow)
 
22
  *Output Interface (expected output)*
23
  - `result` (str): The result of the flow, the result will be returned to the caller (i.e. CoderFlow).
24
  - `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow (i.e. CoderFlow).
 
 
 
 
 
 
 
25
  """
26
  def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
 
 
 
 
 
 
27
  # ~~~ sets the input_data in the flow_state dict ~~~
28
  self._state_update_dict(update_data=input_data)
29
 
 
17
  5. Finish, writes code to the library.
18
  Step 3-5 is done via prompting the controller.
19
 
20
+ ExtendLibraryFlow inherits from AbstractBossFlow, visit https://huggingface.co/aiflows/AbstractBossFlowModule/
21
+
22
  *Input Interface (expected input)*
23
  - `goal` (str): The goal from the caller (source flow, i.e. CoderFlow)
24
+
25
  *Output Interface (expected output)*
26
  - `result` (str): The result of the flow, the result will be returned to the caller (i.e. CoderFlow).
27
  - `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow (i.e. CoderFlow).
28
+
29
+ *Configuration Parameters*:
30
+ - `memory_files`: The memory files to be read by the flow. By convention, the memory files should contain plan, logs, and code library.
31
+ - `input_interface`: The input interface of the flow. By default, they should be `goal`.
32
+ - `output_interface`: The output interface of the flow. By default, they should be `result` and `summary`.
33
+ - `subflows_config`: Configurations w/ the subflows.
34
+
35
  """
36
  def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
37
+ """Run the flow.
38
+ :param input_data: The input data of the flow.
39
+ :type input_data: Dict[str, Any]
40
+ :return: The output data of the flow.
41
+ :rtype: Dict[str, Any]
42
+ """
43
  # ~~~ sets the input_data in the flow_state dict ~~~
44
  self._state_update_dict(update_data=input_data)
45
 
README.md CHANGED
@@ -1,4 +1,32 @@
1
- ### Structure of ExtendLibraryFlow
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  ```
4
  goal, memory_files (dict)
@@ -79,35 +107,19 @@ write_code ask_user re_plan update_plan save_code
79
  ```
80
 
81
  Memory files of ExtendLibraryFlow:
82
- - plan_extlib.txt
83
- - logs_extlib.txt
84
- - library.py
85
 
86
  About the branches:
87
- - [write_code](https://huggingface.co/Tachi67/CodeWriterFlowModule): Generates code in an interactive way, the user is able to edit or provide feedback during the process of writing code.
88
- - [ask_user](https://huggingface.co/Tachi67/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.py): Ask user for info / confirmation, etc.
89
- - [re_plan](https://huggingface.co/Tachi67/ReplanningFlowModule): One branch of the executors, when something goes wrong, re-draft the plan.
90
- - [update_plan](https://huggingface.co/Tachi67/JarvisFlowModule/blob/main/UpdatePlanAtomicFlow.py): One branch of the executors, when the controller realizes that one (or some, depending on the LLM's response) step of the plan is (are) done, it generates a new plan that marks the step(s) as done.
91
- - [save_code](https://huggingface.co/Tachi67/ExtendLibraryFlowModule/blob/main/SaveCodeAtomicFlow.py): Writes the wriiten & tested code to the code library.
92
 
93
 
94
- # Table of Contents
95
 
96
- * [SaveCodeAtomicFlow](#SaveCodeAtomicFlow)
97
- * [SaveCodeAtomicFlow](#SaveCodeAtomicFlow.SaveCodeAtomicFlow)
98
- * [run](#SaveCodeAtomicFlow.SaveCodeAtomicFlow.run)
99
- * [ExtLibAskUserFlow](#ExtLibAskUserFlow)
100
- * [ExtLibAskUserFlow](#ExtLibAskUserFlow.ExtLibAskUserFlow)
101
- * [ExtendLibraryFlow](#ExtendLibraryFlow)
102
- * [ExtendLibraryFlow](#ExtendLibraryFlow.ExtendLibraryFlow)
103
- * [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow)
104
- * [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow.UpdatePlanAtomicFlow)
105
- * [run\_ExtendLibrary](#run_ExtendLibrary)
106
- * [CtrlExMem\_ExtLib](#CtrlExMem_ExtLib)
107
- * [CtrlExMem\_ExtLib](#CtrlExMem_ExtLib.CtrlExMem_ExtLib)
108
- * [ControllerFlow\_ExtLib](#ControllerFlow_ExtLib)
109
- * [ControllerFlow\_ExtLib](#ControllerFlow_ExtLib.ControllerFlow_ExtLib)
110
- * [\_\_init\_\_](#__init__)
111
 
112
  <a id="SaveCodeAtomicFlow"></a>
113
 
@@ -130,6 +142,10 @@ This flow appends the code to the code library file.
130
  - `result` (str): the result of the flow, to be returned to the controller of the caller
131
  - `summary` (str): the summary of the flow, to be appended to logs
132
 
 
 
 
 
133
  <a id="SaveCodeAtomicFlow.SaveCodeAtomicFlow.run"></a>
134
 
135
  #### run
@@ -142,11 +158,11 @@ Run the flow
142
 
143
  **Arguments**:
144
 
145
- - `input_data`: the input data
146
 
147
  **Returns**:
148
 
149
- the output data
150
 
151
  <a id="ExtLibAskUserFlow"></a>
152
 
@@ -162,16 +178,39 @@ class ExtLibAskUserFlow(HumanStandardInputFlow)
162
 
163
  This class is used to ask for user feedback whenever the controller is unsure of something, or need confirmation, etc.
164
 
165
- *Expected Input*:
166
  - `question`: The question asked by the controller
167
 
168
  *Expected Behaviour*:
169
- - The question is displayed, and the user gives feedback by inputing string.
170
 
171
- *Expected Ouput*:
172
  - `result`: The input of the user.
173
  - `summary`: The summary that will be written by the caller.
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  <a id="ExtendLibraryFlow"></a>
176
 
177
  # ExtendLibraryFlow
@@ -197,12 +236,39 @@ Workflow of ExtendLibrary:
197
  5. Finish, writes code to the library.
198
  Step 3-5 is done via prompting the controller.
199
 
 
 
200
  *Input Interface (expected input)*
201
  - `goal` (str): The goal from the caller (source flow, i.e. CoderFlow)
 
202
  *Output Interface (expected output)*
203
  - `result` (str): The result of the flow, the result will be returned to the caller (i.e. CoderFlow).
204
  - `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow (i.e. CoderFlow).
205
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  <a id="UpdatePlanAtomicFlow"></a>
207
 
208
  # UpdatePlanAtomicFlow
@@ -215,7 +281,35 @@ Step 3-5 is done via prompting the controller.
215
  class UpdatePlanAtomicFlow(AtomicFlow)
216
  ```
217
 
218
- Refer to: https://huggingface.co/Tachi67/CoderFlowModule/blob/main/UpdatePlanAtomicFlow.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
 
220
  <a id="run_ExtendLibrary"></a>
221
 
@@ -234,16 +328,40 @@ class CtrlExMem_ExtLib(CtrlExMemFlow)
234
  ```
235
 
236
  This class inherits from the CtrlExMemFlow class from AbstractBossFlowModule.
237
- See: https://huggingface.co/Tachi67/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py
 
 
238
  *Input Interface*:
239
  - `plan`
240
  - `logs`
241
  - `memory_files`
242
  - `goal`
 
243
  *Output Interface*
244
  - `result` (str): The result of the flow, the result will be returned to the caller.
245
  - `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow.
246
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  <a id="ControllerFlow_ExtLib"></a>
248
 
249
  # ControllerFlow\_ExtLib
@@ -256,7 +374,87 @@ See: https://huggingface.co/Tachi67/AbstractBossFlowModule/blob/main/CtrlExMemFl
256
  class ControllerFlow_ExtLib(ChatAtomicFlow)
257
  ```
258
 
259
- Refer to: https://huggingface.co/Tachi67/JarvisFlowModule/blob/main/Controller_JarvisFlow.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
 
261
  <a id="__init__"></a>
262
 
 
1
+ # Table of Contents
2
+
3
+ * [Structure of ExtendLibraryFlow](#structure-of-extendlibraryflow)
4
+ * [SaveCodeAtomicFlow](#SaveCodeAtomicFlow)
5
+ * [SaveCodeAtomicFlow](#SaveCodeAtomicFlow.SaveCodeAtomicFlow)
6
+ * [run](#SaveCodeAtomicFlow.SaveCodeAtomicFlow.run)
7
+ * [ExtLibAskUserFlow](#ExtLibAskUserFlow)
8
+ * [ExtLibAskUserFlow](#ExtLibAskUserFlow.ExtLibAskUserFlow)
9
+ * [run](#ExtLibAskUserFlow.ExtLibAskUserFlow.run)
10
+ * [ExtendLibraryFlow](#ExtendLibraryFlow)
11
+ * [ExtendLibraryFlow](#ExtendLibraryFlow.ExtendLibraryFlow)
12
+ * [run](#ExtendLibraryFlow.ExtendLibraryFlow.run)
13
+ * [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow)
14
+ * [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow.UpdatePlanAtomicFlow)
15
+ * [run](#UpdatePlanAtomicFlow.UpdatePlanAtomicFlow.run)
16
+ * [run\_ExtendLibrary](#run_ExtendLibrary)
17
+ * [CtrlExMem\_ExtLib](#CtrlExMem_ExtLib)
18
+ * [CtrlExMem\_ExtLib](#CtrlExMem_ExtLib.CtrlExMem_ExtLib)
19
+ * [detect\_finish\_or\_continue](#CtrlExMem_ExtLib.CtrlExMem_ExtLib.detect_finish_or_continue)
20
+ * [ControllerFlow\_ExtLib](#ControllerFlow_ExtLib)
21
+ * [ControllerFlow\_ExtLib](#ControllerFlow_ExtLib.ControllerFlow_ExtLib)
22
+ * [\_\_init\_\_](#ControllerFlow_ExtLib.ControllerFlow_ExtLib.__init__)
23
+ * [instantiate\_from\_config](#ControllerFlow_ExtLib.ControllerFlow_ExtLib.instantiate_from_config)
24
+ * [run](#ControllerFlow_ExtLib.ControllerFlow_ExtLib.run)
25
+ * [\_\_init\_\_](#__init__)
26
+
27
+
28
+
29
+ # Structure of ExtendLibraryFlow
30
 
31
  ```
32
  goal, memory_files (dict)
 
107
  ```
108
 
109
  Memory files of ExtendLibraryFlow:
110
+ - `plan_extlib.txt`
111
+ - `logs_extlib.txt`
112
+ - `library.py`
113
 
114
  About the branches:
115
+ - [write_code](https://huggingface.co/aiflows/CodeWriterFlowModule): Generates code in an interactive way, the user is able to edit or provide feedback during the process of writing code.
116
+ - [ask_user](https://huggingface.co/aiflows/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.py): Ask user for info / confirmation, etc.
117
+ - [re_plan](https://huggingface.co/aiflows/ReplanningFlowModule): One branch of the executors, when something goes wrong, re-draft the plan.
118
+ - [update_plan](https://huggingface.co/aiflows/JarvisFlowModule/blob/main/UpdatePlanAtomicFlow.py): One branch of the executors, when the controller realizes that one (or some, depending on the LLM's response) step of the plan is (are) done, it generates a new plan that marks the step(s) as done.
119
+ - [save_code](https://huggingface.co/aiflows/ExtendLibraryFlowModule/blob/main/SaveCodeAtomicFlow.py): Writes the written & tested code to the code library.
120
 
121
 
 
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
 
124
  <a id="SaveCodeAtomicFlow"></a>
125
 
 
142
  - `result` (str): the result of the flow, to be returned to the controller of the caller
143
  - `summary` (str): the summary of the flow, to be appended to logs
144
 
145
+ *Configuration Parameters*:
146
+ - `input_interface`: the input interface of the flow
147
+ - `output_interface`: the output interface of the flow
148
+
149
  <a id="SaveCodeAtomicFlow.SaveCodeAtomicFlow.run"></a>
150
 
151
  #### run
 
158
 
159
  **Arguments**:
160
 
161
+ - `input_data` (`dict`): the input data
162
 
163
  **Returns**:
164
 
165
+ `dict`: the output data
166
 
167
  <a id="ExtLibAskUserFlow"></a>
168
 
 
178
 
179
  This class is used to ask for user feedback whenever the controller is unsure of something, or need confirmation, etc.
180
 
181
+ *Input Interface*:
182
  - `question`: The question asked by the controller
183
 
184
  *Expected Behaviour*:
185
+ - The question is displayed, and the user gives feedback by input string.
186
 
187
+ *Output Interface*:
188
  - `result`: The input of the user.
189
  - `summary`: The summary that will be written by the caller.
190
 
191
+ *Configuration Parameters*:
192
+ - `query_message_prompt_template`: The template of the message that is displayed to the user.
193
+ - `request_multi_line_input`: Whether the user should be able to input multiple lines. Default: False.
194
+ - `end_of_input_string`: The string that the user can input to indicate that he/she is done with the input. Default: EOI
195
+
196
+ <a id="ExtLibAskUserFlow.ExtLibAskUserFlow.run"></a>
197
+
198
+ #### run
199
+
200
+ ```python
201
+ def run(input_data: Dict[str, Any]) -> Dict[str, Any]
202
+ ```
203
+
204
+ Run the flow module.
205
+
206
+ **Arguments**:
207
+
208
+ - `input_data` (`Dict[str, Any]`): The input data.
209
+
210
+ **Returns**:
211
+
212
+ `Dict[str, Any]`: The output data.
213
+
214
  <a id="ExtendLibraryFlow"></a>
215
 
216
  # ExtendLibraryFlow
 
236
  5. Finish, writes code to the library.
237
  Step 3-5 is done via prompting the controller.
238
 
239
+ ExtendLibraryFlow inherits from AbstractBossFlow, visit https://huggingface.co/aiflows/AbstractBossFlowModule/
240
+
241
  *Input Interface (expected input)*
242
  - `goal` (str): The goal from the caller (source flow, i.e. CoderFlow)
243
+
244
  *Output Interface (expected output)*
245
  - `result` (str): The result of the flow, the result will be returned to the caller (i.e. CoderFlow).
246
  - `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow (i.e. CoderFlow).
247
 
248
+ *Configuration Parameters*:
249
+ - `memory_files`: The memory files to be read by the flow. By convention, the memory files should contain plan, logs, and code library.
250
+ - `input_interface`: The input interface of the flow. By default, they should be `goal`.
251
+ - `output_interface`: The output interface of the flow. By default, they should be `result` and `summary`.
252
+ - `subflows_config`: Configurations w/ the subflows.
253
+
254
+ <a id="ExtendLibraryFlow.ExtendLibraryFlow.run"></a>
255
+
256
+ #### run
257
+
258
+ ```python
259
+ def run(input_data: Dict[str, Any]) -> Dict[str, Any]
260
+ ```
261
+
262
+ Run the flow.
263
+
264
+ **Arguments**:
265
+
266
+ - `input_data` (`Dict[str, Any]`): The input data of the flow.
267
+
268
+ **Returns**:
269
+
270
+ `Dict[str, Any]`: The output data of the flow.
271
+
272
  <a id="UpdatePlanAtomicFlow"></a>
273
 
274
  # UpdatePlanAtomicFlow
 
281
  class UpdatePlanAtomicFlow(AtomicFlow)
282
  ```
283
 
284
+ Refer to: https://huggingface.co/aiflows/CoderFlowModule/blob/main/UpdatePlanAtomicFlow.py
285
+ This flow updates the plan file with the updated plan.
286
+ *Input Interface*:
287
+ - `updated_plan` (str): the updated plan
288
+
289
+ *Output Interface*:
290
+ - `result` (str): the result of the flow, to be returned to the controller of the caller
291
+
292
+ *Configuration Parameters*:
293
+ - `input_interface`: the input interface of the flow
294
+ - `output_interface`: the output interface of the flow
295
+
296
+ <a id="UpdatePlanAtomicFlow.UpdatePlanAtomicFlow.run"></a>
297
+
298
+ #### run
299
+
300
+ ```python
301
+ def run(input_data: Dict[str, Any])
302
+ ```
303
+
304
+ Run the flow
305
+
306
+ **Arguments**:
307
+
308
+ - `input_data` (`dict`): the input data
309
+
310
+ **Returns**:
311
+
312
+ `dict`: the output data
313
 
314
  <a id="run_ExtendLibrary"></a>
315
 
 
328
  ```
329
 
330
  This class inherits from the CtrlExMemFlow class from AbstractBossFlowModule.
331
+
332
+ See: https://huggingface.co/aiflows/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py
333
+
334
  *Input Interface*:
335
  - `plan`
336
  - `logs`
337
  - `memory_files`
338
  - `goal`
339
+
340
  *Output Interface*
341
  - `result` (str): The result of the flow, the result will be returned to the caller.
342
  - `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow.
343
 
344
+ <a id="CtrlExMem_ExtLib.CtrlExMem_ExtLib.detect_finish_or_continue"></a>
345
+
346
+ #### detect\_finish\_or\_continue
347
+
348
+ ```python
349
+ @CircularFlow.output_msg_payload_processor
350
+ def detect_finish_or_continue(output_payload: Dict[str, Any],
351
+ src_flow) -> Dict[str, Any]
352
+ ```
353
+
354
+ This method is called when the flow receives a message from the child flow.
355
+
356
+ **Arguments**:
357
+
358
+ - `output_payload` (`Dict[str, Any]`): The output payload of the child flow.
359
+ - `src_flow` (`AbstractBossFlowModule`): The child flow.
360
+
361
+ **Returns**:
362
+
363
+ `Dict[str, Any]`: The processed output payload.
364
+
365
  <a id="ControllerFlow_ExtLib"></a>
366
 
367
  # ControllerFlow\_ExtLib
 
374
  class ControllerFlow_ExtLib(ChatAtomicFlow)
375
  ```
376
 
377
+ Refer to: https://huggingface.co/aiflows/JarvisFlowModule/blob/main/Controller_JarvisFlow.py for a detailed doc.
378
+ This flow inherits from ChatAtomicFlow and is used as a controller of the ExtendLibraryFlow.
379
+
380
+ *Input Interface Non Initialized*:
381
+ - `goal`
382
+ - `memory_files`
383
+ - `plan`
384
+ - `logs`
385
+
386
+ *Input Interface Initialized*:
387
+ - `goal`
388
+ - `memory_files`
389
+ - `plan`
390
+ - `logs`
391
+ - `result`
392
+
393
+ *Output Interface*:
394
+ - `command`
395
+ - `command_args`
396
+
397
+ *Configuration Parameters*:
398
+ - `input_interface_non_initialized`: a list of input interface names when the conversation starts.
399
+ - `input_interface_initialized`: a list of input interface names when the conversation is initialized.
400
+ - `output_interface`: the output of the controller, it is the command and the command arguments.
401
+ - `commands`: a list of commands that the controller can call. Each command has a name, a description, and a list of input arguments.
402
+ - `system_message_prompt_template`: the system message prompt template.
403
+ - `init_human_message_prompt_template`: the initial human (user) message prompt template.
404
+ - `human_message_prompt_template`: the human (user) message prompt template.
405
+ - `previous_messages`: the sliding window of previous messages.
406
+
407
+ <a id="ControllerFlow_ExtLib.ControllerFlow_ExtLib.__init__"></a>
408
+
409
+ #### \_\_init\_\_
410
+
411
+ ```python
412
+ def __init__(commands: List[Command], **kwargs)
413
+ ```
414
+
415
+ The constructor of the ControllerFlow_ExtLib class.
416
+
417
+ **Arguments**:
418
+
419
+ - `commands`: a list of commands that the controller can call. Each command has a name, a description, and a list of input arguments.
420
+ - `kwargs`: the configuration parameters of the ControllerFlow_ExtLib class.
421
+
422
+ <a id="ControllerFlow_ExtLib.ControllerFlow_ExtLib.instantiate_from_config"></a>
423
+
424
+ #### instantiate\_from\_config
425
+
426
+ ```python
427
+ @classmethod
428
+ def instantiate_from_config(cls, config)
429
+ ```
430
+
431
+ Instantiate the flow from a configuration.
432
+
433
+ **Arguments**:
434
+
435
+ - `config` (`Dict[str, Any]`): the configuration.
436
+
437
+ **Returns**:
438
+
439
+ `ControllerFlow_ExtLib`: the instantiated flow.
440
+
441
+ <a id="ControllerFlow_ExtLib.ControllerFlow_ExtLib.run"></a>
442
+
443
+ #### run
444
+
445
+ ```python
446
+ def run(input_data: Dict[str, Any]) -> Dict[str, Any]
447
+ ```
448
+
449
+ Run the flow.
450
+
451
+ **Arguments**:
452
+
453
+ - `input_data` (`Dict[str, Any]`): the input data.
454
+
455
+ **Returns**:
456
+
457
+ `Dict[str, Any]`: the output of the flow.
458
 
459
  <a id="__init__"></a>
460
 
SaveCodeAtomicFlow.py CHANGED
@@ -11,10 +11,17 @@ class SaveCodeAtomicFlow(AtomicFlow):
11
  *Output Interface*:
12
  - `result` (str): the result of the flow, to be returned to the controller of the caller
13
  - `summary` (str): the summary of the flow, to be appended to logs
 
 
 
 
 
14
  """
15
  def _check_input(self, input_data: Dict[str, Any]):
16
  """Check if the input data is valid
17
  :param input_data: the input data
 
 
18
  :return: None
19
  """
20
  assert "code" in input_data, "code is not passed to SaveCodeAtomicFlow"
@@ -28,7 +35,9 @@ class SaveCodeAtomicFlow(AtomicFlow):
28
  def _call(self, input_data: Dict[str, Any]):
29
  """The internal logic of the flow
30
  :param input_data: the input data
 
31
  :return: the output data
 
32
  """
33
  try:
34
  code_to_append = input_data["code"]
@@ -52,7 +61,9 @@ class SaveCodeAtomicFlow(AtomicFlow):
52
  ):
53
  """Run the flow
54
  :param input_data: the input data
 
55
  :return: the output data
 
56
  """
57
  self._check_input(input_data)
58
  return self._call(input_data)
 
11
  *Output Interface*:
12
  - `result` (str): the result of the flow, to be returned to the controller of the caller
13
  - `summary` (str): the summary of the flow, to be appended to logs
14
+
15
+ *Configuration Parameters*:
16
+ - `input_interface`: the input interface of the flow
17
+ - `output_interface`: the output interface of the flow
18
+
19
  """
20
  def _check_input(self, input_data: Dict[str, Any]):
21
  """Check if the input data is valid
22
  :param input_data: the input data
23
+ :type input_data: dict
24
+ :raises AssertionError: if the input data is invalid
25
  :return: None
26
  """
27
  assert "code" in input_data, "code is not passed to SaveCodeAtomicFlow"
 
35
  def _call(self, input_data: Dict[str, Any]):
36
  """The internal logic of the flow
37
  :param input_data: the input data
38
+ :type input_data: dict
39
  :return: the output data
40
+ :rtype: dict
41
  """
42
  try:
43
  code_to_append = input_data["code"]
 
61
  ):
62
  """Run the flow
63
  :param input_data: the input data
64
+ :type input_data: dict
65
  :return: the output data
66
+ :rtype: dict
67
  """
68
  self._check_input(input_data)
69
  return self._call(input_data)
UpdatePlanAtomicFlow.py CHANGED
@@ -1,12 +1,35 @@
1
  from typing import Dict, Any
2
  from aiflows.base_flows.atomic import AtomicFlow
3
  class UpdatePlanAtomicFlow(AtomicFlow):
4
- """Refer to: https://huggingface.co/Tachi67/CoderFlowModule/blob/main/UpdatePlanAtomicFlow.py"""
 
 
 
 
 
 
 
 
 
 
 
5
  def _check_input(self, input_data: Dict[str, Any]):
 
 
 
 
 
 
6
  assert "memory_files" in input_data, "memory_files not passed to UpdatePlanAtomicFlow"
7
  assert "plan" in input_data["memory_files"], "plan not in memory_files"
8
 
9
  def _call(self, input_data: Dict[str, Any]):
 
 
 
 
 
 
10
  try:
11
  plan_file_location = input_data["memory_files"]["plan"]
12
  plan_to_write = input_data["updated_plan"]
@@ -26,5 +49,11 @@ class UpdatePlanAtomicFlow(AtomicFlow):
26
  self,
27
  input_data: Dict[str, Any]
28
  ):
 
 
 
 
 
 
29
  self._check_input(input_data)
30
  return self._call(input_data)
 
1
  from typing import Dict, Any
2
  from aiflows.base_flows.atomic import AtomicFlow
3
  class UpdatePlanAtomicFlow(AtomicFlow):
4
+ """Refer to: https://huggingface.co/aiflows/CoderFlowModule/blob/main/UpdatePlanAtomicFlow.py
5
+ This flow updates the plan file with the updated plan.
6
+ *Input Interface*:
7
+ - `updated_plan` (str): the updated plan
8
+
9
+ *Output Interface*:
10
+ - `result` (str): the result of the flow, to be returned to the controller of the caller
11
+
12
+ *Configuration Parameters*:
13
+ - `input_interface`: the input interface of the flow
14
+ - `output_interface`: the output interface of the flow
15
+ """
16
  def _check_input(self, input_data: Dict[str, Any]):
17
+ """Check if the input data is valid
18
+ :param input_data: the input data
19
+ :type input_data: dict
20
+ :raises AssertionError: if the input data is invalid
21
+ :return: None
22
+ """
23
  assert "memory_files" in input_data, "memory_files not passed to UpdatePlanAtomicFlow"
24
  assert "plan" in input_data["memory_files"], "plan not in memory_files"
25
 
26
  def _call(self, input_data: Dict[str, Any]):
27
+ """The internal logic of the flow
28
+ :param input_data: the input data
29
+ :type input_data: dict
30
+ :return: the output data
31
+ :rtype: dict
32
+ """
33
  try:
34
  plan_file_location = input_data["memory_files"]["plan"]
35
  plan_to_write = input_data["updated_plan"]
 
49
  self,
50
  input_data: Dict[str, Any]
51
  ):
52
+ """Run the flow
53
+ :param input_data: the input data
54
+ :type input_data: dict
55
+ :return: the output data
56
+ :rtype: dict
57
+ """
58
  self._check_input(input_data)
59
  return self._call(input_data)