|
from typing import Dict, Any |
|
from aiflows.base_flows.atomic import AtomicFlow |
|
class UpdatePlanAtomicFlow(AtomicFlow): |
|
"""Refer to: https://huggingface.co/aiflows/CoderFlowModule/blob/main/UpdatePlanAtomicFlow.py |
|
This flow updates the plan file with the updated plan. |
|
*Input Interface*: |
|
- `updated_plan` (str): the updated plan |
|
|
|
*Output Interface*: |
|
- `result` (str): the result of the flow, to be returned to the controller of the caller |
|
|
|
*Configuration Parameters*: |
|
- `input_interface`: the input interface of the flow |
|
- `output_interface`: the output interface of the flow |
|
""" |
|
def _check_input(self, input_data: Dict[str, Any]): |
|
"""Check if the input data is valid |
|
:param input_data: the input data |
|
:type input_data: dict |
|
:raises AssertionError: if the input data is invalid |
|
:return: None |
|
""" |
|
assert "memory_files" in input_data, "memory_files not passed to UpdatePlanAtomicFlow" |
|
assert "plan" in input_data["memory_files"], "plan not in memory_files" |
|
|
|
def _call(self, input_data: Dict[str, Any]): |
|
"""The internal logic of the flow |
|
:param input_data: the input data |
|
:type input_data: dict |
|
:return: the output data |
|
:rtype: dict |
|
""" |
|
try: |
|
plan_file_location = input_data["memory_files"]["plan"] |
|
plan_to_write = input_data["updated_plan"] |
|
with open(plan_file_location, 'w') as file: |
|
file.write(plan_to_write + "\n") |
|
return { |
|
"result": "updated plan saved to the plan file and has overriden the previous plan", |
|
"summary": f"ExtendLibrary/UpdatePlanFlow: updated plan saved to {plan_file_location}" |
|
} |
|
except Exception as e: |
|
return { |
|
"result": f"Error occurred: {str(e)}", |
|
"summary": f"ExtendLibrary/UpdatePlanFlow: error occurred while writing updated plan: {str(e)}" |
|
} |
|
|
|
def run( |
|
self, |
|
input_data: Dict[str, Any] |
|
): |
|
"""Run the flow |
|
:param input_data: the input data |
|
:type input_data: dict |
|
:return: the output data |
|
:rtype: dict |
|
""" |
|
self._check_input(input_data) |
|
return self._call(input_data) |
|
|