File size: 1,367 Bytes
bd7cdc8
515c88e
bd7cdc8
3f7dcd4
bd7cdc8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from typing import Dict, Any
from aiflows.base_flows.atomic import AtomicFlow
class UpdatePlanAtomicFlow(AtomicFlow):
    """Refer to: https://huggingface.co/Tachi67/CoderFlowModule/blob/main/UpdatePlanAtomicFlow.py"""
    def _check_input(self, input_data: Dict[str, Any]):
        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]):
        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]
    ):
        self._check_input(input_data)
        return self._call(input_data)