Upload 3 files
Browse filesFiles changed (3)
- InteractiveCodeGenFlow.pyAdded+52
- InteractiveCodeGenFlow.yamlAdded+66
- __init__.pyAdded+12
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152from copy import deepcopyfrom typing import Any, Dict
from flows.base_flows import SequentialFlowfrom flows.utils import logging
logging.set_verbosity_debug()log = logging.get_logger(__name__)
class InteractiveCodeGenFlow(SequentialFlow): REQUIRED_KEYS_CONFIG = ["max_rounds", "early_exit_key", "topology", "memory_files"]
def __init__( self, memory_files: Dict[str, Any], **kwargs ): super().__init__(**kwargs) self.memory_files = memory_files
@classmethod def instantiate_from_config(cls, config): flow_config = deepcopy(config)
kwargs = {"flow_config": flow_config}
# ~~~ Set up memory file ~~~ memory_files = flow_config["memory_files"] kwargs.update({"memory_files": memory_files})
# ~~~ 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)
# ~~~ set the memory file to the flow state ~~~ self._state_update_dict(update_data={"memory_files": self.memory_files})
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 output123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566name: "InteractiveCodeGenFlow"description: "Generate code as goal requests, open up a temp file for the user to examine and provide feedback"
_target_: Tachi67.InteractiveCodeGenFlowModule.InteractiveCodeGenFlow.instantiate_from_default_config
memory_files: ???
input_interface: - "goal"
output_interface: - "code" - "human_feedback"
subflows_config: MemoryReading: _target_: Tachi67.MemoryReadingFlowModule.MemoryReadingAtomicFlow.instantiate_from_default_config
CodeGenerator: _target_: Tachi67.CodeGeneratorFlowModule.CodeGeneratorAtomicFlow.instantiate_from_default_config backend: api_infos: ??? model_name: openai: gpt-4 azure: azure/gpt-4
CodeFileEditor: _target_: Tachi67.CodeFileEditFlowModule.CodeFileEditAtomicFlow.instantiate_from_default_config
ParseFeedback: _target_: Tachi67.ParseFeedbackFlowModule.ParseFeedbackAtomicFlow.instantiate_from_default_config
early_exit_key: "EARLY_EXIT"
topology: - goal: "Read in necessary memory" input_interface: _target_: flows.interfaces.KeyInterface additional_transformations: - _target_: flows.data_transformations.KeyMatchInput flow: MemoryReading reset: false
- goal: "Generate code to achieve the task." input_interface: _target_: flows.interfaces.KeyInterface additional_transformations: - _target_: flows.data_transformations.KeyMatchInput flow: CodeGenerator reset: false
- goal: "Write the code generated to a temp file with instructions to the user" input_interface: _target_: flows.interfaces.KeyInterface additional_transformations: - _target_: flows.data_transformations.KeyMatchInput flow: CodeFileEditor reset: false
- goal: "Parse user feedback from the temp file" input_interface: _target_: flows.interfaces.KeyInterface additional_transformations: - _target_: flows.data_transformations.KeyMatchInput flow: ParseFeedback reset: false123456789101112# ~~~ Specify the dependencies ~~~dependencies = [ {"url": "Tachi67/MemoryReadingFlowModule", "revision": "main"}, {"url": "Tachi67/CodeGeneratorFlowModule", "revision": "main"}, {"url": "Tachi67/CodeFileEditFlowModule", "revision": "main"}, {"url": "Tachi67/ParseFeedbackFlowModule", "revision": "main"},]from flows import flow_verse
flow_verse.sync_dependencies(dependencies)
from .InteractiveCodeGenFlow import InteractiveCodeGenFlowInteractiveCodeGenFlow.pyAdded+52
InteractiveCodeGenFlow.yamlAdded+66
__init__.pyAdded+12