add more comments & docs
Browse filesFiles changed (6)
- CoderFlow.py+4
- Controller_CoderFlow.py+83-1
- CtrlExMem_CoderFlow.py+17-2
- Planner_CoderFlow.py+19-1
- README.md+189-23
- UpdatePlanAtomicFlow.py+23-1
19 unmodified lines2021222324252627282919 unmodified lines - `result` (str): The result of the flow, the result will be returned to the caller (i.e. JarvisFlow). - `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow (i.e. JarvisFlow).
*Configuration Parameters*: (Also see super class: AbstractBossFlow) - `memory_files` (dict): The memory files of the flow. The memory files are the files that the flow reads and writes. Typically it should contain plan, logs, and code_library.
Typical workflow of Coder: 0. JarvisFlow calls Coder with a goal. 1. MemoryReading reads plans, logs and code library.14 unmodified lines15161718181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636416 unmodified lines8182838485868788899091922 unmodified lines95969798991001011021031041051061071081091101111121131141151161171181191201211221231243 unmodified lines12812913013113213313413513613713813914016 unmodified lines15715815916016116216316416516616716812 unmodified lines18118218318418518618718818919019119214 unmodified lines input_args: List[str]
class Controller_CoderFlow(ChatAtomicFlow): """Refer to: https://huggingface.co/Tachi67/JarvisFlowModule/blob/main/Controller_JarvisFlow.py""" """Refer to: https://huggingface.co/aiflows/JarvisFlowModule/blob/main/Controller_JarvisFlow.py This flow is used to control the coder flow.
*Input Interface Non Initialized*: - `goal` - `plan` - `code_library` - `logs` - `memory_files`
*Input Interface Initialized*: - `goal` - `plan` - `code_library` - `logs` - `memory_files` - `result`
*Output Interface*: - `command` - `command_args`
*Configuration Parameters*: - `Input Interface Non Initialized`: Input interface before the conversation is initialized. - `Input Interface Initialized`: Input interface after the conversation is initialized. - `Output Interface`: Output interface. - `backend`: The backend of the LLM. - `command`: A list of available commands for the controller to call. - `system_message_prompt_template`: The template of the system message prompt. - `init_human_message_prompt_template`: The template of the initial human message prompt. - `human_message_prompt_template`: The template of the human message prompt. - `previous_messages`: The sliding window of previous messages.
""" def __init__( self, commands: List[Command], **kwargs): """Initialize the flow. :param commands: A list of available commands for the controller to call. :type commands: List[Command] :param kwargs: Refer to the configuration parameters. :type kwargs: Dict[str, Any] """ super().__init__(**kwargs) self.system_message_prompt_template = self.system_message_prompt_template.partial( commands=self._build_commands_manual(commands),16 unmodified lines
@staticmethod def _build_commands_manual(commands: List[Command]) -> str: """Build the manual for the commands. :param commands: A list of available commands for the controller to call. :type commands: List[Command] :return: The manual for the commands. :rtype: str """ ret = "" for i, command in enumerate(commands): command_input_json_schema = json.dumps(2 unmodified lines return ret
def _get_content_file_location(self, input_data, content_name): """Get the location of the file that contains the content: plan, logs, code_library :param input_data: The input data. :type input_data: Dict[str, Any] :param content_name: The name of the content. :type content_name: str :raises AssertionError: If the content is not in the memory files. :return: The location of the file that contains the content. :rtype: str """ # get the location of the file that contains the content: plan, logs, code_library assert "memory_files" in input_data, "memory_files not passed to Coder/Controller" assert content_name in input_data["memory_files"], f"{content_name} not in memory files" return input_data["memory_files"][content_name]
def _get_content(self, input_data, content_name): """Get the content of the file that contains the content: plan, logs, code_library :param input_data: The input data. :type input_data: Dict[str, Any] :param content_name: The name of the content. :type content_name: str :raises AssertionError: If the content is not in the memory files. :return: The content of the file that contains the content. :rtype: str """ # get the content of the file that contains the content: plan, logs, code_library assert content_name in input_data, f"{content_name} not passed to Coder/Controller" content = input_data[content_name]3 unmodified lines
@classmethod def instantiate_from_config(cls, config): """Instantiate the flow from the configuration. :param config: The configuration. :type config: Dict[str, Any] :return: The instantiated flow. :rtype: Controller_CoderFlow """
flow_config = deepcopy(config)
kwargs = {"flow_config": flow_config}16 unmodified lines return cls(**kwargs)
def _update_prompts_and_input(self, input_data: Dict[str, Any]): """Update the prompts and input data. :param input_data: The input data. :type input_data: Dict[str, Any] :raises AssertionError: If the input data is not valid. """
if 'goal' in input_data: input_data['goal'] += self.hint_for_model if 'result' in input_data:12 unmodified lines )
def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]: """Run the flow. :param input_data: The input data. :type input_data: Dict[str, Any] :return: The output data. :rtype: Dict[str, Any] """ self._update_prompts_and_input(input_data)
# ~~~when conversation is initialized, append the updated system prompts to the chat history ~~~4 unmodified lines56788910115 unmodified lines1718192020212223242526272829303132332 unmodified lines363738394041424344454647484 unmodified lines
class CtrlExMem_CoderFlow(CtrlExMemFlow): """This class inherits from the CtrlExMemFlow class from AbstractBossFlowModule. See: https://huggingface.co/Tachi67/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py See: https://huggingface.co/aiflows/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py
*Input Interface*: - `plan`5 unmodified lines *Output Interface* - `result` (str): The result of the flow, the result will be returned to the caller. - `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow.
*Configuration Parameters*: - See the configuration parameters of the CtrlExMemFlow class from AbstractBoss (https://huggingface.co/aiflows/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py). - `input_interface`: the input interface of the flow - `output_interface`: the output interface of the flow - `subflows_config`: the configuration of the subflows
""" def _on_reach_max_round(self): """This method is called when the flow reaches the maximum amount of rounds. """ self._state_update_dict({ "result": "the maximum amount of rounds was reached before the coder flow has done the job", "summary": "CoderFlow: the maximum amount of rounds was reached before the flow has done the job",2 unmodified lines
@CircularFlow.output_msg_payload_processor def detect_finish_or_continue(self, output_payload: Dict[str, Any], src_flow) -> Dict[str, Any]: """This method is called when the flow receives a message from a subflow. This method will check the message and decide whether the flow should continue or finish. :param output_payload: the output payload of the subflow :param src_flow: the source flow of the message :return: the output payload of the flow :rtype: Dict[str, Any] """ command = output_payload["command"] if command == "finish": return {5 unmodified lines678991011121314151617181920212223242526272829305 unmodified lines
class Planner_CoderFlow(PlanWriterFlow): """Planner of the coder flow, it inherits from PlanWriterFlow, see: https://huggingface.co/Tachi67/PlanWriterFlowModule """Planner of the coder flow, it inherits from PlanWriterFlow, see: https://huggingface.co/aiflows/PlanWriterFlowModule This flow is responsible for generating the plan for the coder flow.
*Input Interface* - `goal` - `memory_files` - `code_library`
*Output Interface* - `plan` - `summary` - `status`
*Configuration Parameters*: - Look at the configuration parameters of PlanWriterFlowModule for detailed info. (https://huggingface.co/aiflows/PlanWriterFlowModule) - `input_interface`: the input interface of the flow, default: `["goal", "memory_files", "code_library"]` - `output_interface`: the output interface of the flow, default: `["plan", "summary", "status"]` - `subflows_config`: configuration of the subflows. - `topology`: topology of the subflows. """ def _on_reach_max_round(self): self._state_update_dict({12345678910111213141516171819202122232412526272879 unmodified lines10810911087888990911111121131141151161171181199612098991001011021031041051061071081091101211221238 unmodified lines1321331341251351361371386 unmodified lines14514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817910 unmodified lines1901911921541931941951961971981992002012022032042052062072082092102112122132147 unmodified lines22222322416822522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031117 unmodified lines32933033133233333433533633733833934034134234334434534634734834935035135235335435535621 unmodified lines378379380381382383384385386387# Table of Contents
* [Structure of Coder](#structure-of-coder)* [CtrlExMem\_CoderFlow](#CtrlExMem_CoderFlow) * [CtrlExMem\_CoderFlow](#CtrlExMem_CoderFlow.CtrlExMem_CoderFlow) * [detect\_finish\_or\_continue](#CtrlExMem_CoderFlow.CtrlExMem_CoderFlow.detect_finish_or_continue)* [run\_coder](#run_coder)* [Planner\_CoderFlow](#Planner_CoderFlow) * [Planner\_CoderFlow](#Planner_CoderFlow.Planner_CoderFlow)* [Controller\_CoderFlow](#Controller_CoderFlow) * [Controller\_CoderFlow](#Controller_CoderFlow.Controller_CoderFlow) * [\_\_init\_\_](#Controller_CoderFlow.Controller_CoderFlow.__init__) * [instantiate\_from\_config](#Controller_CoderFlow.Controller_CoderFlow.instantiate_from_config) * [run](#Controller_CoderFlow.Controller_CoderFlow.run)* [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow) * [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow.UpdatePlanAtomicFlow) * [run](#UpdatePlanAtomicFlow.UpdatePlanAtomicFlow.run)* [CoderFlow](#CoderFlow) * [CoderFlow](#CoderFlow.CoderFlow) * [run](#CoderFlow.CoderFlow.run)* [\_\_init\_\_](#__init__)
### Structure of Coder# Structure of Coder
``` goal, memory_files (dict)79 unmodified lines- library.py
About the branches:- [ExtendLibrary](https://huggingface.co/Tachi67/ExtendLibraryFlowModule): Writes and tests code functions in an interactive fashion, finally saves the written function to the code library.- [ask_user](https://huggingface.co/Tachi67/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.py): Ask user for info / confirmation, etc.- [re_plan](https://huggingface.co/Tachi67/ReplanningFlowModule): One branch of the executors, when something goes wrong, re-draft the plan.- [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.- [run_code](https://huggingface.co/Tachi67/RunCodeFlowModule): Runs the code written by the Controller, will first open up a temp file with the code for user confirmation and editing, then the code is passed to the [InterpreterFlow](https://huggingface.co/Tachi67/InterpreterFlowModule).- [ExtendLibrary](https://huggingface.co/aiflows/ExtendLibraryFlowModule): Writes and tests code functions in an interactive fashion, finally saves the written function to the code library.- [ask_user](https://huggingface.co/aiflows/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.py): Ask user for info / confirmation, etc.- [re_plan](https://huggingface.co/aiflows/ReplanningFlowModule): One branch of the executors, when something goes wrong, re-draft the plan.- [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.- [run_code](https://huggingface.co/aiflows/RunCodeFlowModule): Runs the code written by the Controller, will first open up a temp file with the code for user confirmation and editing, then the code is passed to the [InterpreterFlow](https://huggingface.co/aiflows/InterpreterFlowModule).
# Table of Contents
* [CtrlExMem\_CoderFlow](#CtrlExMem_CoderFlow) * [CtrlExMem\_CoderFlow](#CtrlExMem_CoderFlow.CtrlExMem_CoderFlow)* [run\_coder](#run_coder)* [Planner\_CoderFlow](#Planner_CoderFlow) * [Planner\_CoderFlow](#Planner_CoderFlow.Planner_CoderFlow)* [Controller\_CoderFlow](#Controller_CoderFlow) * [Controller\_CoderFlow](#Controller_CoderFlow.Controller_CoderFlow)* [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow) * [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow.UpdatePlanAtomicFlow)* [CoderFlow](#CoderFlow) * [CoderFlow](#CoderFlow.CoderFlow) * [run](#CoderFlow.CoderFlow.run)* [\_\_init\_\_](#__init__)
<a id="CtrlExMem_CoderFlow"></a>
8 unmodified lines```
This class inherits from the CtrlExMemFlow class from AbstractBossFlowModule.See: https://huggingface.co/Tachi67/AbstractBossFlowModule/blob/main/CtrlExMemFlow.pySee: https://huggingface.co/aiflows/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py
*Input Interface*:- `plan`6 unmodified lines- `result` (str): The result of the flow, the result will be returned to the caller.- `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow.
*Configuration Parameters*:- See the configuration parameters of the CtrlExMemFlow class from AbstractBoss (https://huggingface.co/aiflows/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py).- `input_interface`: the input interface of the flow- `output_interface`: the output interface of the flow- `subflows_config`: the configuration of the subflows
<a id="CtrlExMem_CoderFlow.CtrlExMem_CoderFlow.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 method is called when the flow receives a message from a subflow.
This method will check the message and decide whether the flow should continue or finish.
**Arguments**:
- `output_payload`: the output payload of the subflow- `src_flow`: the source flow of the message
**Returns**:
`Dict[str, Any]`: the output payload of the flow
<a id="run_coder"></a>
# run\_coder10 unmodified linesclass Planner_CoderFlow(PlanWriterFlow)```
Planner of the coder flow, it inherits from PlanWriterFlow, see: https://huggingface.co/Tachi67/PlanWriterFlowModulePlanner of the coder flow, it inherits from PlanWriterFlow, see: https://huggingface.co/aiflows/PlanWriterFlowModuleThis flow is responsible for generating the plan for the coder flow.
*Input Interface*- `goal`- `memory_files`- `code_library`
*Output Interface*- `plan`- `summary`- `status`
*Configuration Parameters*:- Look at the configuration parameters of PlanWriterFlowModule for detailed info. (https://huggingface.co/aiflows/PlanWriterFlowModule)- `input_interface`: the input interface of the flow, default: `["goal", "memory_files", "code_library"]`- `output_interface`: the output interface of the flow, default: `["plan", "summary", "status"]`- `subflows_config`: configuration of the subflows.- `topology`: topology of the subflows.
<a id="Controller_CoderFlow"></a>
7 unmodified linesclass Controller_CoderFlow(ChatAtomicFlow)```
Refer to: https://huggingface.co/Tachi67/JarvisFlowModule/blob/main/Controller_JarvisFlow.pyRefer to: https://huggingface.co/aiflows/JarvisFlowModule/blob/main/Controller_JarvisFlow.pyThis flow is used to control the coder flow.
*Input Interface Non Initialized*:- `goal`- `plan`- `code_library`- `logs`- `memory_files`
*Input Interface Initialized*:- `goal`- `plan`- `code_library`- `logs`- `memory_files`- `result`
*Output Interface*:- `command`- `command_args`
*Configuration Parameters*:- `Input Interface Non Initialized`: Input interface before the conversation is initialized.- `Input Interface Initialized`: Input interface after the conversation is initialized.- `Output Interface`: Output interface.- `backend`: The backend of the LLM.- `command`: A list of available commands for the controller to call.- `system_message_prompt_template`: The template of the system message prompt.- `init_human_message_prompt_template`: The template of the initial human message prompt.- `human_message_prompt_template`: The template of the human message prompt.- `previous_messages`: The sliding window of previous messages.
<a id="Controller_CoderFlow.Controller_CoderFlow.__init__"></a>
#### \_\_init\_\_
```pythondef __init__(commands: List[Command], **kwargs)```
Initialize the flow.
**Arguments**:
- `commands` (`List[Command]`): A list of available commands for the controller to call.- `kwargs` (`Dict[str, Any]`): Refer to the configuration parameters.
<a id="Controller_CoderFlow.Controller_CoderFlow.instantiate_from_config"></a>
#### instantiate\_from\_config
```python@classmethoddef instantiate_from_config(cls, config)```
Instantiate the flow from the configuration.
**Arguments**:
- `config` (`Dict[str, Any]`): The configuration.
**Returns**:
`Controller_CoderFlow`: The instantiated flow.
<a id="Controller_CoderFlow.Controller_CoderFlow.run"></a>
#### run
```pythondef run(input_data: Dict[str, Any]) -> Dict[str, Any]```
Run the flow.
**Arguments**:
- `input_data` (`Dict[str, Any]`): The input data.
**Returns**:
`Dict[str, Any]`: The output data.
<a id="UpdatePlanAtomicFlow"></a>
17 unmodified lines*Output Interface*- `result`: the result of the update plan operation
*Configuration Parameters*:- `input_interface`: the input interface of the flow, default: `["updated_plan"]`- `output_interface`: the output interface of the flow, default: `["result"]`
<a id="UpdatePlanAtomicFlow.UpdatePlanAtomicFlow.run"></a>
#### run
```pythondef run(input_data: Dict[str, Any])```
The run function of the flow.
**Arguments**:
- `input_data` (`Dict[str, Any]`): the input data to the flow
**Returns**:
`Dict[str, Any]`: the output data of the flow
<a id="CoderFlow"></a>
# CoderFlow21 unmodified lines- `result` (str): The result of the flow, the result will be returned to the caller (i.e. JarvisFlow).- `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow (i.e. JarvisFlow).
*Configuration Parameters*: (Also see super class: AbstractBossFlow)- `memory_files` (dict): The memory files of the flow. The memory files are the files that the flow reads and writes. Typically it should contain plan, logs, and code_library.
Typical workflow of Coder:0. JarvisFlow calls Coder with a goal.1. MemoryReading reads plans, logs and code library.11236 unmodified lines101112131415161718192021222324252627282930313233343536373813 unmodified lines5253545556575859606162#TODO: generalize updateplanatomicflow with the one in extendlibraryfrom typing import Dict, Anyfrom aiflows.base_flows.atomic import AtomicFlowclass UpdatePlanAtomicFlow(AtomicFlow):6 unmodified lines *Output Interface* - `result`: the result of the update plan operation
*Configuration Parameters*: - `input_interface`: the input interface of the flow, default: `["updated_plan"]` - `output_interface`: the output interface of the flow, default: `["result"]`
""" def _check_input(self, input_data: Dict[str, Any]): """Check if the input data is valid. :param input_data: the input data to the flow :type input_data: Dict[str, Any] :raises AssertionError: if the input data is not valid :raises AssertionError: if the input data does not contain the required keys """ assert "memory_files" in input_data, "memory_files not passed to UpdatePlanAtomicFlow.yaml" assert "plan" in input_data["memory_files"], "plan not in memory_files"
def _call(self, input_data: Dict[str, Any]): """The main function of the flow. :param input_data: the input data to the flow :type input_data: Dict[str, Any] :return: the output data of the flow :rtype: Dict[str, Any] """ try: plan_file_location = input_data["memory_files"]["plan"] plan_to_write = input_data["updated_plan"]13 unmodified lines self, input_data: Dict[str, Any] ): """The run function of the flow. :param input_data: the input data to the flow :type input_data: Dict[str, Any] :return: the output data of the flow :rtype: Dict[str, Any] """ self._check_input(input_data) return self._call(input_data)CoderFlow.py+4
Controller_CoderFlow.py+83-1
CtrlExMem_CoderFlow.py+17-2
Planner_CoderFlow.py+19-1
README.md+189-23
UpdatePlanAtomicFlow.py+23-1