Upload 6 files
Browse filesFiles changed (6)
- InteractivePlanGenFlow.pyAdded+57
- InteractivePlanGenFlow.yamlAdded+60
- README.md+70-3
- __init__.pyAdded+11
- pip_requirements.txtAdded+15
- run.pyAdded+55
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657from copy import deepcopyfrom typing import Any, Dict
from aiflows.base_flows import SequentialFlowfrom 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 output123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960name: "InteractivePlanGenFlow"description: "Generate step by step plan as goal requests, open up a temp file for the user to examine and provide feedback"
_target_: flow_modules.aiflows.InteractivePlanGenFlowModule.InteractivePlanGenFlow.instantiate_from_default_config
input_interface: - "goal" - "plan_file_location"
output_interface: - "plan" - "feedback" - "temp_plan_file_location"
subflows_config: PlanGenerator: _target_: flow_modules.aiflows.PlanGeneratorFlowModule.PlanGeneratorAtomicFlow.instantiate_from_default_config backend: api_infos: ??? model_name: openai: gpt-4 azure: azure/gpt-4
PlanFileEditor: _target_: flow_modules.aiflows.PlanFileEditFlowModule.PlanFileEditAtomicFlow.instantiate_from_default_config
ParseFeedback: _target_: flow_modules.aiflows.ParseFeedbackFlowModule.ParseFeedbackAtomicFlow.instantiate_from_default_config input_interface: - "temp_plan_file_location" output_interface: - "plan" - "feedback"
early_exit_key: "EARLY_EXIT"
topology: - goal: "Generate plan to achieve the task." input_interface: _target_: aiflows.interfaces.KeyInterface additional_transformations: - _target_: aiflows.data_transformations.KeyMatchInput flow: PlanGenerator reset: false
- goal: "Write the plan generated to a temp file with instructions to the user" input_interface: _target_: aiflows.interfaces.KeyInterface additional_transformations: - _target_: aiflows.data_transformations.KeyMatchInput flow: PlanFileEditor reset: false
- goal: "Parse user feedback from the temp file" input_interface: _target_: aiflows.interfaces.KeyInterface additional_transformations: - _target_: aiflows.data_transformations.KeyMatchInput flow: ParseFeedback reset: false123---license: mit---12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970### Structure of InteractivePlanGenFlow```goal|||v+------------------+| PlanGenerator | Generates plan given goal. (https://huggingface.co/Tachi67/PlanGeneratorFlowModule)+------------------+|| (plan)|v+-------------------+| PlanFileEdit | Edit a temp file with the plan generated. (https://huggingface.co/Tachi67/PlanFileEditFlowModule)+-------------------+|| (temp_plan_file_location)|v+------------------+| ParseFeedback | Opens up the temp file until user closes the file, parse for user feedback. (https://huggingface.co/Tachi67/ParseFeedbackFlowModule)+------------------+|| (plan, feedback)|vplan, feedback```# Table of Contents* [InteractivePlanGenFlow](#InteractivePlanGenFlow)* [InteractivePlanGenFlow](#InteractivePlanGenFlow.InteractivePlanGenFlow)* [\_\_init\_\_](#__init__)<a id="InteractivePlanGenFlow"></a># InteractivePlanGenFlow<a id="InteractivePlanGenFlow.InteractivePlanGenFlow"></a>## InteractivePlanGenFlow Objects```pythonclass 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`<a id="__init__"></a># \_\_init\_\_
1234567891011# ~~~ Specify the dependencies ~~~dependencies = [ {"url": "aiflows/PlanGeneratorFlowModule", "revision": "main"}, {"url": "aiflows/PlanFileEditFlowModule", "revision": "main"}, {"url": "aiflows/ParseFeedbackFlowModule", "revision": "main"},]from aiflows import flow_verse
flow_verse.sync_dependencies(dependencies)
from .InteractivePlanGenFlow import InteractivePlanGenFlow123456789101112131415colorama==0.4.6pytest==7.3.1pytest-cov==4.1.0hydra-core==1.3.2hydra-colorlog==1.1.0wrapt-timeout-decorator==1.3.12.2diskcache==5.6.1openai==1.0.0huggingface_hub==0.19.4jsonlines==3.1.0jinja2==3.1.2mock==5.0.2rich==12.6.0litellm==1.0.0aiflows12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455import os
import hydra
from aiflows.backends.api_info import ApiInfofrom aiflows.messages import InputMessagefrom aiflows.utils.general_helpers import read_yaml_file, quick_load
from aiflows import loggingfrom aiflows.flow_cache import CACHING_PARAMETERS, clear_cache
CACHING_PARAMETERS.do_caching = False # Set to True in order to disable caching
logging.set_verbosity_debug()logging.auto_set_dir()
dependencies = [ {"url": "aiflows/InteractivePlanGenFlowModule", "revision": "main"},]
from aiflows import flow_verse
flow_verse.sync_dependencies(dependencies)
if __name__ == "__main__": # ~~~ make sure to set the openai api key in the envs ~~~ key = os.getenv("OPENAI_API_KEY") api_information = [ApiInfo(backend_used="openai", api_key=os.getenv("OPENAI_API_KEY"))] current_dir = os.getcwd() cfg_path = os.path.join(current_dir, "InteractivePlanGenFlow.yaml") cfg = read_yaml_file(cfg_path)
with open(os.path.join(current_dir, "example_plan.txt"), "r") as f: pass
# configuring api information quick_load(cfg, api_information)
InteractivePlanGenFlow = hydra.utils.instantiate(cfg, _recursive_=False, _convert_="partial")
input_data = { "goal": "write a function to add up two numbers", "plan_file_location": os.path.join(current_dir, "example_plan.txt") } input_message = InputMessage.build( data_dict=input_data, src_flow="Launcher", dst_flow=InteractivePlanGenFlow.name )
# ~~~ calling the flow ~~~ output_message = InteractivePlanGenFlow(input_message)
print(output_message.data)InteractivePlanGenFlow.pyAdded+57
InteractivePlanGenFlow.yamlAdded+60
README.md+70-3
__init__.pyAdded+11
pip_requirements.txtAdded+15
run.pyAdded+55