add more comments and docs & error fix w/ logger
Browse filesFiles changed (3)
- CodeWriterCtrlFlow.py+25-1
- CodeWriterFlow.py+27
- README.md+90-11
13 unmodified lines141516171718192021222324252627282930313233343536373839404142434413 unmodified lines input_args: List[str]
class CodeWriterCtrlFlow(ChatAtomicFlow): """refer to https://huggingface.co/Tachi67/JarvisFlowModule/blob/main/Controller_JarvisFlow.py""" """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.
""" def __init__( self, commands: List[Command],3 unmodified lines4567891011127 unmodified lines202122232425262728293031323334353637383940411 unmodified line43444546474849505152535440 unmodified lines95969798991001011021031043 unmodified linesfrom flow_modules.aiflows.ContentWriterFlowModule import ContentWriterFlowfrom aiflows.base_flows import CircularFlow
from aiflows.utils import logginglog = logging.get_logger(f"aiflows.{__name__}")
class CodeWriterFlow(ContentWriterFlow): """This flow inherits from ContentWriterFlow, it is used to write code in an interactive way.7 unmodified lines - `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.
"""
def _on_reach_max_round(self): """This function is called when the maximum amount of rounds was reached before the model generated the code. """ self._state_update_dict({ "code": "The maximum amount of rounds was reached before the model generated the code.", "status": "unfinished"1 unmodified line
@CircularFlow.output_msg_payload_processor def detect_finish_or_continue(self, 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. :param output_payload: The output payload of the subflow :param src_flow: The subflow that generated the output payload :return: The output payload of the subflow """ command = output_payload["command"] if command == "finish": # ~~~ delete the temp code file ~~~40 unmodified lines return output_payload
def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]: """The run function of the flow. :param input_data: The input data of the flow :return: The output data of the flow """ # ~~~ sets the input_data in the flow_state dict ~~~ self._state_update_dict(update_data=input_data)
1234567891011121314151611718192041 unmodified lines626364496551525354555657585966676813 unmodified lines82838485868788899091929394959697989910010110210310410510610710810957 unmodified lines167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
# 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# Structure of CodeWriterFlow
``` goal41 unmodified linesHow 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.
# Table of Contents
* [run\_codewriter](#run_codewriter)* [CodeWriterCtrlFlow](#CodeWriterCtrlFlow) * [CodeWriterCtrlFlow](#CodeWriterCtrlFlow.CodeWriterCtrlFlow)* [CodeWriterAskUserFlow](#CodeWriterAskUserFlow) * [CodeWriterAskUserFlow](#CodeWriterAskUserFlow.CodeWriterAskUserFlow) * [run](#CodeWriterAskUserFlow.CodeWriterAskUserFlow.run)* [CodeWriterFlow](#CodeWriterFlow) * [CodeWriterFlow](#CodeWriterFlow.CodeWriterFlow)* [\_\_init\_\_](#__init__)
<a id="run_codewriter"></a>
13 unmodified lines
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>
# CodeWriterAskUserFlow57 unmodified lines- `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_processordef 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
```pythondef 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\_\_CodeWriterCtrlFlow.py+25-1
CodeWriterFlow.py+27
README.md+90-11