File size: 1,783 Bytes
51219b7
 
 
6c41309
 
51219b7
 
 
 
 
0144a65
 
 
 
 
 
 
 
 
 
 
 
 
 
5121f3a
51219b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from copy import deepcopy
from typing import Any, Dict

from aiflows.base_flows import SequentialFlow
from aiflows.utils import logging

logging.set_verbosity_debug()
log = logging.get_logger(__name__)

class InteractivePlanGenFlow(SequentialFlow):
    """This flow writes code in an interactive manner. It is a sequential flow composed of:
    1. PlanGenerator: generates plan based on the goal.
    2. PlanFileEditor: writes the generated plan to a temp file for the user to see, edit and provide feedback.
    3. ParseFeedback: opens up the temp file with vscode and parses the feedback from the user.
    
    *Input Interface*:
    - `goal`
    - `plan_file_location`
    
    *Output Interface*:
    - `plan`
    - `feedback`
    - `temp_plan_file_location`
    """
    REQUIRED_KEYS_CONFIG = ["max_rounds", "early_exit_key", "topology"]

    def __init__(
            self,
            **kwargs
    ):
        super().__init__(**kwargs)

    @classmethod
    def instantiate_from_config(cls, config):
        flow_config = deepcopy(config)

        kwargs = {"flow_config": flow_config}

        # ~~~ Set up subflows ~~~
        kwargs.update({"subflows": cls._set_up_subflows(flow_config)})

        # ~~~ Instantiate flow ~~~
        return cls(**kwargs)

    def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
        # ~~~ sets the input_data in the flow_state dict ~~~
        self._state_update_dict(update_data=input_data)

        max_rounds = self.flow_config.get("max_rounds", 1)
        if max_rounds is None:
            log.info(f"Running {self.flow_config['name']} without `max_rounds` until the early exit condition is met.")

        self._sequential_run(max_rounds=max_rounds)

        output = self._get_output_from_state()

        return output