add more comments and docs & error fix w/ logger
Browse files- CodeWriterCtrlFlow.py +25 -1
- CodeWriterFlow.py +27 -0
- README.md +90 -11
CodeWriterCtrlFlow.py
CHANGED
|
@@ -14,7 +14,31 @@ class Command:
|
|
| 14 |
input_args: List[str]
|
| 15 |
|
| 16 |
class CodeWriterCtrlFlow(ChatAtomicFlow):
|
| 17 |
-
"""refer to https://huggingface.co/Tachi67/JarvisFlowModule/blob/main/Controller_JarvisFlow.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
def __init__(
|
| 19 |
self,
|
| 20 |
commands: List[Command],
|
|
|
|
| 14 |
input_args: List[str]
|
| 15 |
|
| 16 |
class CodeWriterCtrlFlow(ChatAtomicFlow):
|
| 17 |
+
"""refer to https://huggingface.co/Tachi67/JarvisFlowModule/blob/main/Controller_JarvisFlow.py
|
| 18 |
+
|
| 19 |
+
This class controls the execution of the CodeWriterFlow.
|
| 20 |
+
|
| 21 |
+
*Input Interface Non Initialized*:
|
| 22 |
+
- `goal`
|
| 23 |
+
|
| 24 |
+
*Input Interface Initialized*:
|
| 25 |
+
- `goal`
|
| 26 |
+
- `code`
|
| 27 |
+
- `feedback`
|
| 28 |
+
|
| 29 |
+
*Output Interface*:
|
| 30 |
+
- `command`
|
| 31 |
+
- `command_args`
|
| 32 |
+
|
| 33 |
+
*Config Parameters*:
|
| 34 |
+
- `backend`: the backend used to call the LLM.
|
| 35 |
+
- `commands`: a list of commands that the controller can use.
|
| 36 |
+
- `system_message_prompt_template`: the template of the system message prompt.
|
| 37 |
+
- `init_human_message_prompt_template`: the template of the init human (user) message prompt.
|
| 38 |
+
- `human_message_prompt_template`: the template of the human (user) message prompt.
|
| 39 |
+
- `previous_messages`: the sliding window of previous messages.
|
| 40 |
+
|
| 41 |
+
"""
|
| 42 |
def __init__(
|
| 43 |
self,
|
| 44 |
commands: List[Command],
|
CodeWriterFlow.py
CHANGED
|
@@ -4,6 +4,9 @@ import os
|
|
| 4 |
from flow_modules.aiflows.ContentWriterFlowModule import ContentWriterFlow
|
| 5 |
from aiflows.base_flows import CircularFlow
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
class CodeWriterFlow(ContentWriterFlow):
|
| 9 |
"""This flow inherits from ContentWriterFlow, it is used to write code in an interactive way.
|
|
@@ -17,8 +20,22 @@ class CodeWriterFlow(ContentWriterFlow):
|
|
| 17 |
- `result`
|
| 18 |
- `summary`
|
| 19 |
- `status`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
"""
|
|
|
|
| 21 |
def _on_reach_max_round(self):
|
|
|
|
|
|
|
| 22 |
self._state_update_dict({
|
| 23 |
"code": "The maximum amount of rounds was reached before the model generated the code.",
|
| 24 |
"status": "unfinished"
|
|
@@ -26,6 +43,12 @@ class CodeWriterFlow(ContentWriterFlow):
|
|
| 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 |
# ~~~ delete the temp code file ~~~
|
|
@@ -72,6 +95,10 @@ class CodeWriterFlow(ContentWriterFlow):
|
|
| 72 |
return output_payload
|
| 73 |
|
| 74 |
def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
# ~~~ sets the input_data in the flow_state dict ~~~
|
| 76 |
self._state_update_dict(update_data=input_data)
|
| 77 |
|
|
|
|
| 4 |
from flow_modules.aiflows.ContentWriterFlowModule import ContentWriterFlow
|
| 5 |
from aiflows.base_flows import CircularFlow
|
| 6 |
|
| 7 |
+
from aiflows.utils import logging
|
| 8 |
+
log = logging.get_logger(f"aiflows.{__name__}")
|
| 9 |
+
|
| 10 |
|
| 11 |
class CodeWriterFlow(ContentWriterFlow):
|
| 12 |
"""This flow inherits from ContentWriterFlow, it is used to write code in an interactive way.
|
|
|
|
| 20 |
- `result`
|
| 21 |
- `summary`
|
| 22 |
- `status`
|
| 23 |
+
|
| 24 |
+
*Configuration Parameters*:
|
| 25 |
+
- `name`: Name of the flow
|
| 26 |
+
- `description`: Description of the flow
|
| 27 |
+
- `_target_`: The instantiation target of the flow
|
| 28 |
+
- `input_interface`: The input to the flow. Inherited from ContentWriterFlow, in this case, it is `goal`.
|
| 29 |
+
- `output_interface`: The output of the flow.
|
| 30 |
+
- `subflows_config`: Configurations of subflows
|
| 31 |
+
- `early_exit_keys`: The keys that will trigger an early exit of the flow
|
| 32 |
+
- `topology`: Configures the topology of the subflows, please have a special look at the I/O interfaces of the subflows.
|
| 33 |
+
|
| 34 |
"""
|
| 35 |
+
|
| 36 |
def _on_reach_max_round(self):
|
| 37 |
+
"""This function is called when the maximum amount of rounds was reached before the model generated the code.
|
| 38 |
+
"""
|
| 39 |
self._state_update_dict({
|
| 40 |
"code": "The maximum amount of rounds was reached before the model generated the code.",
|
| 41 |
"status": "unfinished"
|
|
|
|
| 43 |
|
| 44 |
@CircularFlow.output_msg_payload_processor
|
| 45 |
def detect_finish_or_continue(self, output_payload: Dict[str, Any], src_flow) -> Dict[str, Any]:
|
| 46 |
+
"""This function is used to detect whether the code generation process is finished or not.
|
| 47 |
+
It is configured in the topology of the subflows, see CodeWriterFlow.yaml for more details.
|
| 48 |
+
:param output_payload: The output payload of the subflow
|
| 49 |
+
:param src_flow: The subflow that generated the output payload
|
| 50 |
+
:return: The output payload of the subflow
|
| 51 |
+
"""
|
| 52 |
command = output_payload["command"]
|
| 53 |
if command == "finish":
|
| 54 |
# ~~~ delete the temp code file ~~~
|
|
|
|
| 95 |
return output_payload
|
| 96 |
|
| 97 |
def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
|
| 98 |
+
"""The run function of the flow.
|
| 99 |
+
:param input_data: The input data of the flow
|
| 100 |
+
:return: The output data of the flow
|
| 101 |
+
"""
|
| 102 |
# ~~~ sets the input_data in the flow_state dict ~~~
|
| 103 |
self._state_update_dict(update_data=input_data)
|
| 104 |
|
README.md
CHANGED
|
@@ -1,4 +1,20 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
```
|
| 4 |
goal
|
|
@@ -46,17 +62,7 @@ About the branches:
|
|
| 46 |
How it works:
|
| 47 |
Controller calls write_code until user is satisfied in the feedback, then controller calls test to test the code, if test passes, finish.
|
| 48 |
|
| 49 |
-
# Table of Contents
|
| 50 |
|
| 51 |
-
* [run\_codewriter](#run_codewriter)
|
| 52 |
-
* [CodeWriterCtrlFlow](#CodeWriterCtrlFlow)
|
| 53 |
-
* [CodeWriterCtrlFlow](#CodeWriterCtrlFlow.CodeWriterCtrlFlow)
|
| 54 |
-
* [CodeWriterAskUserFlow](#CodeWriterAskUserFlow)
|
| 55 |
-
* [CodeWriterAskUserFlow](#CodeWriterAskUserFlow.CodeWriterAskUserFlow)
|
| 56 |
-
* [run](#CodeWriterAskUserFlow.CodeWriterAskUserFlow.run)
|
| 57 |
-
* [CodeWriterFlow](#CodeWriterFlow)
|
| 58 |
-
* [CodeWriterFlow](#CodeWriterFlow.CodeWriterFlow)
|
| 59 |
-
* [\_\_init\_\_](#__init__)
|
| 60 |
|
| 61 |
<a id="run_codewriter"></a>
|
| 62 |
|
|
@@ -76,6 +82,28 @@ class CodeWriterCtrlFlow(ChatAtomicFlow)
|
|
| 76 |
|
| 77 |
refer to https://huggingface.co/Tachi67/JarvisFlowModule/blob/main/Controller_JarvisFlow.py
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
<a id="CodeWriterAskUserFlow"></a>
|
| 80 |
|
| 81 |
# CodeWriterAskUserFlow
|
|
@@ -139,6 +167,57 @@ In the subflow of the executor, we specify an InteractiveCodeGenFlow (https://hu
|
|
| 139 |
- `summary`
|
| 140 |
- `status`
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
<a id="__init__"></a>
|
| 143 |
|
| 144 |
# \_\_init\_\_
|
|
|
|
| 1 |
+
|
| 2 |
+
# Table of Contents
|
| 3 |
+
|
| 4 |
+
* [Structure of CodeWriterFlow](#structure-of-codewriterflow)
|
| 5 |
+
* [run\_codewriter](#run_codewriter)
|
| 6 |
+
* [CodeWriterCtrlFlow](#CodeWriterCtrlFlow)
|
| 7 |
+
* [CodeWriterCtrlFlow](#CodeWriterCtrlFlow.CodeWriterCtrlFlow)
|
| 8 |
+
* [CodeWriterAskUserFlow](#CodeWriterAskUserFlow)
|
| 9 |
+
* [CodeWriterAskUserFlow](#CodeWriterAskUserFlow.CodeWriterAskUserFlow)
|
| 10 |
+
* [run](#CodeWriterAskUserFlow.CodeWriterAskUserFlow.run)
|
| 11 |
+
* [CodeWriterFlow](#CodeWriterFlow)
|
| 12 |
+
* [CodeWriterFlow](#CodeWriterFlow.CodeWriterFlow)
|
| 13 |
+
* [detect\_finish\_or\_continue](#CodeWriterFlow.CodeWriterFlow.detect_finish_or_continue)
|
| 14 |
+
* [run](#CodeWriterFlow.CodeWriterFlow.run)
|
| 15 |
+
* [\_\_init\_\_](#__init__)
|
| 16 |
+
|
| 17 |
+
# Structure of CodeWriterFlow
|
| 18 |
|
| 19 |
```
|
| 20 |
goal
|
|
|
|
| 62 |
How it works:
|
| 63 |
Controller calls write_code until user is satisfied in the feedback, then controller calls test to test the code, if test passes, finish.
|
| 64 |
|
|
|
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
<a id="run_codewriter"></a>
|
| 68 |
|
|
|
|
| 82 |
|
| 83 |
refer to https://huggingface.co/Tachi67/JarvisFlowModule/blob/main/Controller_JarvisFlow.py
|
| 84 |
|
| 85 |
+
This class controls the execution of the CodeWriterFlow.
|
| 86 |
+
|
| 87 |
+
*Input Interface Non Initialized*:
|
| 88 |
+
- `goal`
|
| 89 |
+
|
| 90 |
+
*Input Interface Initialized*:
|
| 91 |
+
- `goal`
|
| 92 |
+
- `code`
|
| 93 |
+
- `feedback`
|
| 94 |
+
|
| 95 |
+
*Output Interface*:
|
| 96 |
+
- `command`
|
| 97 |
+
- `command_args`
|
| 98 |
+
|
| 99 |
+
*Config Parameters*:
|
| 100 |
+
- `backend`: the backend used to call the LLM.
|
| 101 |
+
- `commands`: a list of commands that the controller can use.
|
| 102 |
+
- `system_message_prompt_template`: the template of the system message prompt.
|
| 103 |
+
- `init_human_message_prompt_template`: the template of the init human (user) message prompt.
|
| 104 |
+
- `human_message_prompt_template`: the template of the human (user) message prompt.
|
| 105 |
+
- `previous_messages`: the sliding window of previous messages.
|
| 106 |
+
|
| 107 |
<a id="CodeWriterAskUserFlow"></a>
|
| 108 |
|
| 109 |
# CodeWriterAskUserFlow
|
|
|
|
| 167 |
- `summary`
|
| 168 |
- `status`
|
| 169 |
|
| 170 |
+
*Configuration Parameters*:
|
| 171 |
+
- `name`: Name of the flow
|
| 172 |
+
- `description`: Description of the flow
|
| 173 |
+
- `_target_`: The instantiation target of the flow
|
| 174 |
+
- `input_interface`: The input to the flow. Inherited from ContentWriterFlow, in this case, it is `goal`.
|
| 175 |
+
- `output_interface`: The output of the flow.
|
| 176 |
+
- `subflows_config`: Configurations of subflows
|
| 177 |
+
- `early_exit_keys`: The keys that will trigger an early exit of the flow
|
| 178 |
+
- `topology`: Configures the topology of the subflows, please have a special look at the I/O interfaces of the subflows.
|
| 179 |
+
|
| 180 |
+
<a id="CodeWriterFlow.CodeWriterFlow.detect_finish_or_continue"></a>
|
| 181 |
+
|
| 182 |
+
#### detect\_finish\_or\_continue
|
| 183 |
+
|
| 184 |
+
```python
|
| 185 |
+
@CircularFlow.output_msg_payload_processor
|
| 186 |
+
def detect_finish_or_continue(output_payload: Dict[str, Any],
|
| 187 |
+
src_flow) -> Dict[str, Any]
|
| 188 |
+
```
|
| 189 |
+
|
| 190 |
+
This function is used to detect whether the code generation process is finished or not.
|
| 191 |
+
|
| 192 |
+
It is configured in the topology of the subflows, see CodeWriterFlow.yaml for more details.
|
| 193 |
+
|
| 194 |
+
**Arguments**:
|
| 195 |
+
|
| 196 |
+
- `output_payload`: The output payload of the subflow
|
| 197 |
+
- `src_flow`: The subflow that generated the output payload
|
| 198 |
+
|
| 199 |
+
**Returns**:
|
| 200 |
+
|
| 201 |
+
The output payload of the subflow
|
| 202 |
+
|
| 203 |
+
<a id="CodeWriterFlow.CodeWriterFlow.run"></a>
|
| 204 |
+
|
| 205 |
+
#### run
|
| 206 |
+
|
| 207 |
+
```python
|
| 208 |
+
def run(input_data: Dict[str, Any]) -> Dict[str, Any]
|
| 209 |
+
```
|
| 210 |
+
|
| 211 |
+
The run function of the flow.
|
| 212 |
+
|
| 213 |
+
**Arguments**:
|
| 214 |
+
|
| 215 |
+
- `input_data`: The input data of the flow
|
| 216 |
+
|
| 217 |
+
**Returns**:
|
| 218 |
+
|
| 219 |
+
The output data of the flow
|
| 220 |
+
|
| 221 |
<a id="__init__"></a>
|
| 222 |
|
| 223 |
# \_\_init\_\_
|