|
|
|
# Table of Contents |
|
|
|
* [Structure of CodeWriterFlow](#structure-of-codewriterflow) |
|
* [run\_codewriter](#run_codewriter) |
|
* [CodeWriterCtrlFlow](#CodeWriterCtrlFlow) |
|
* [CodeWriterCtrlFlow](#CodeWriterCtrlFlow.CodeWriterCtrlFlow) |
|
* [CodeWriterAskUserFlow](#CodeWriterAskUserFlow) |
|
* [CodeWriterAskUserFlow](#CodeWriterAskUserFlow.CodeWriterAskUserFlow) |
|
* [run](#CodeWriterAskUserFlow.CodeWriterAskUserFlow.run) |
|
* [CodeWriterFlow](#CodeWriterFlow) |
|
* [CodeWriterFlow](#CodeWriterFlow.CodeWriterFlow) |
|
* [detect\_finish\_or\_continue](#CodeWriterFlow.CodeWriterFlow.detect_finish_or_continue) |
|
* [run](#CodeWriterFlow.CodeWriterFlow.run) |
|
* [\_\_init\_\_](#__init__) |
|
|
|
# Structure of CodeWriterFlow |
|
|
|
``` |
|
goal |
|
| |
|
v |
|
+---------------+ |
|
| Controller | --------<<<<-----------+ |
|
+---------------+ | |
|
| | |
|
| (command, command args) | |
|
| | |
|
v | |
|
+------------------+ | |
|
| Executor | Each branch is an | |
|
| (Tree Structure) | executor | |
|
+------------------+ | |
|
| ^ |
|
| (summary) | |
|
| | |
|
v | |
|
| | |
|
+-> goes back to the Controller>-+ |
|
|
|
``` |
|
|
|
Structure of the Executors: |
|
``` |
|
+-------------------+ |
|
| Branching | |
|
| Executor | |
|
+-------------------+ |
|
/ | \ |
|
/ | \ |
|
/ | \ |
|
/ | \ |
|
write_code ask_user test |
|
|
|
``` |
|
|
|
About the branches: |
|
- [ask_user](https://huggingface.co/Tachi67/CodeWriterFlowModule/blob/main/CodeWriterAskUserFlow.py): Ask user for info / confirmation, etc. |
|
- [write_code](https://huggingface.co/Tachi67/InteractiveCodeGenFlowModule): Generates code (user edit is allowed) and fetches user feedback. |
|
- [test](https://huggingface.co/Tachi67/TestCodeFlowModule): Test the code, user can provide test suites, if nothing is provided, syntax of the code is checked. |
|
|
|
How it works: |
|
Controller calls write_code until user is satisfied in the feedback, then controller calls test to test the code, if test passes, finish. |
|
|
|
|
|
|
|
<a id="run_codewriter"></a> |
|
|
|
# run\_codewriter |
|
|
|
<a id="CodeWriterCtrlFlow"></a> |
|
|
|
# CodeWriterCtrlFlow |
|
|
|
<a id="CodeWriterCtrlFlow.CodeWriterCtrlFlow"></a> |
|
|
|
## CodeWriterCtrlFlow Objects |
|
|
|
```python |
|
class CodeWriterCtrlFlow(ChatAtomicFlow) |
|
``` |
|
|
|
refer to https://huggingface.co/Tachi67/JarvisFlowModule/blob/main/Controller_JarvisFlow.py |
|
|
|
This class controls the execution of the CodeWriterFlow. |
|
|
|
*Input Interface Non Initialized*: |
|
- `goal` |
|
|
|
*Input Interface Initialized*: |
|
- `goal` |
|
- `code` |
|
- `feedback` |
|
|
|
*Output Interface*: |
|
- `command` |
|
- `command_args` |
|
|
|
*Config Parameters*: |
|
- `backend`: the backend used to call the LLM. |
|
- `commands`: a list of commands that the controller can use. |
|
- `system_message_prompt_template`: the template of the system message prompt. |
|
- `init_human_message_prompt_template`: the template of the init human (user) message prompt. |
|
- `human_message_prompt_template`: the template of the human (user) message prompt. |
|
- `previous_messages`: the sliding window of previous messages. |
|
|
|
<a id="CodeWriterAskUserFlow"></a> |
|
|
|
# CodeWriterAskUserFlow |
|
|
|
<a id="CodeWriterAskUserFlow.CodeWriterAskUserFlow"></a> |
|
|
|
## CodeWriterAskUserFlow Objects |
|
|
|
```python |
|
class CodeWriterAskUserFlow(HumanStandardInputFlow) |
|
``` |
|
|
|
This class is used to ask for user feedback whenever the controller is unsure of something, or need confirmation, etc. |
|
*Expected Input*: |
|
- `question`: The question asked by the controller |
|
*Expected Behaviour*: |
|
- The question is displayed, and the user gives feedback by inputing string. |
|
*Expected Ouput*: |
|
- `feedback`: The input of the user. |
|
- `code`: No code was written. |
|
|
|
<a id="CodeWriterAskUserFlow.CodeWriterAskUserFlow.run"></a> |
|
|
|
#### run |
|
|
|
```python |
|
def run(input_data: Dict[str, Any]) -> Dict[str, Any] |
|
``` |
|
|
|
Run the flow. |
|
|
|
**Arguments**: |
|
|
|
- `input_data`: The input data. |
|
|
|
**Returns**: |
|
|
|
The output data. |
|
|
|
<a id="CodeWriterFlow"></a> |
|
|
|
# CodeWriterFlow |
|
|
|
<a id="CodeWriterFlow.CodeWriterFlow"></a> |
|
|
|
## CodeWriterFlow Objects |
|
|
|
```python |
|
class CodeWriterFlow(ContentWriterFlow) |
|
``` |
|
|
|
This flow inherits from ContentWriterFlow, it is used to write code in an interactive way. |
|
In the subflow of the executor, we specify an InteractiveCodeGenFlow (https://huggingface.co/Tachi67/InteractiveCodeGenFlowModule) |
|
|
|
*Input Interface*: |
|
- `goal` |
|
|
|
*Output Interface*: |
|
- `code` |
|
- `result` |
|
- `summary` |
|
- `status` |
|
|
|
*Configuration Parameters*: |
|
- `name`: Name of the flow |
|
- `description`: Description of the flow |
|
- `_target_`: The instantiation target of the flow |
|
- `input_interface`: The input to the flow. Inherited from ContentWriterFlow, in this case, it is `goal`. |
|
- `output_interface`: The output of the flow. |
|
- `subflows_config`: Configurations of subflows |
|
- `early_exit_keys`: The keys that will trigger an early exit of the flow |
|
- `topology`: Configures the topology of the subflows, please have a special look at the I/O interfaces of the subflows. |
|
|
|
<a id="CodeWriterFlow.CodeWriterFlow.detect_finish_or_continue"></a> |
|
|
|
#### detect\_finish\_or\_continue |
|
|
|
```python |
|
@CircularFlow.output_msg_payload_processor |
|
def detect_finish_or_continue(output_payload: Dict[str, Any], |
|
src_flow) -> Dict[str, Any] |
|
``` |
|
|
|
This function is used to detect whether the code generation process is finished or not. |
|
|
|
It is configured in the topology of the subflows, see CodeWriterFlow.yaml for more details. |
|
|
|
**Arguments**: |
|
|
|
- `output_payload`: The output payload of the subflow |
|
- `src_flow`: The subflow that generated the output payload |
|
|
|
**Returns**: |
|
|
|
The output payload of the subflow |
|
|
|
<a id="CodeWriterFlow.CodeWriterFlow.run"></a> |
|
|
|
#### run |
|
|
|
```python |
|
def run(input_data: Dict[str, Any]) -> Dict[str, Any] |
|
``` |
|
|
|
The run function of the flow. |
|
|
|
**Arguments**: |
|
|
|
- `input_data`: The input data of the flow |
|
|
|
**Returns**: |
|
|
|
The output data of the flow |
|
|
|
<a id="__init__"></a> |
|
|
|
# \_\_init\_\_ |
|
|
|
|