Upload 3 files
Browse files- InteractiveCodeGenFlow.py +52 -0
- InteractiveCodeGenFlow.yaml +66 -0
- __init__.py +12 -0
InteractiveCodeGenFlow.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from copy import deepcopy
|
| 2 |
+
from typing import Any, Dict
|
| 3 |
+
|
| 4 |
+
from flows.base_flows import SequentialFlow
|
| 5 |
+
from flows.utils import logging
|
| 6 |
+
|
| 7 |
+
logging.set_verbosity_debug()
|
| 8 |
+
log = logging.get_logger(__name__)
|
| 9 |
+
|
| 10 |
+
class InteractiveCodeGenFlow(SequentialFlow):
|
| 11 |
+
REQUIRED_KEYS_CONFIG = ["max_rounds", "early_exit_key", "topology", "memory_files"]
|
| 12 |
+
|
| 13 |
+
def __init__(
|
| 14 |
+
self,
|
| 15 |
+
memory_files: Dict[str, Any],
|
| 16 |
+
**kwargs
|
| 17 |
+
):
|
| 18 |
+
super().__init__(**kwargs)
|
| 19 |
+
self.memory_files = memory_files
|
| 20 |
+
|
| 21 |
+
@classmethod
|
| 22 |
+
def instantiate_from_config(cls, config):
|
| 23 |
+
flow_config = deepcopy(config)
|
| 24 |
+
|
| 25 |
+
kwargs = {"flow_config": flow_config}
|
| 26 |
+
|
| 27 |
+
# ~~~ Set up memory file ~~~
|
| 28 |
+
memory_files = flow_config["memory_files"]
|
| 29 |
+
kwargs.update({"memory_files": memory_files})
|
| 30 |
+
|
| 31 |
+
# ~~~ Set up subflows ~~~
|
| 32 |
+
kwargs.update({"subflows": cls._set_up_subflows(flow_config)})
|
| 33 |
+
|
| 34 |
+
# ~~~ Instantiate flow ~~~
|
| 35 |
+
return cls(**kwargs)
|
| 36 |
+
|
| 37 |
+
def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
|
| 38 |
+
# ~~~ sets the input_data in the flow_state dict ~~~
|
| 39 |
+
self._state_update_dict(update_data=input_data)
|
| 40 |
+
|
| 41 |
+
# ~~~ set the memory file to the flow state ~~~
|
| 42 |
+
self._state_update_dict(update_data={"memory_files": self.memory_files})
|
| 43 |
+
|
| 44 |
+
max_rounds = self.flow_config.get("max_rounds", 1)
|
| 45 |
+
if max_rounds is None:
|
| 46 |
+
log.info(f"Running {self.flow_config['name']} without `max_rounds` until the early exit condition is met.")
|
| 47 |
+
|
| 48 |
+
self._sequential_run(max_rounds=max_rounds)
|
| 49 |
+
|
| 50 |
+
output = self._get_output_from_state()
|
| 51 |
+
|
| 52 |
+
return output
|
InteractiveCodeGenFlow.yaml
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: "InteractiveCodeGenFlow"
|
| 2 |
+
description: "Generate code as goal requests, open up a temp file for the user to examine and provide feedback"
|
| 3 |
+
|
| 4 |
+
_target_: Tachi67.InteractiveCodeGenFlowModule.InteractiveCodeGenFlow.instantiate_from_default_config
|
| 5 |
+
|
| 6 |
+
memory_files: ???
|
| 7 |
+
|
| 8 |
+
input_interface:
|
| 9 |
+
- "goal"
|
| 10 |
+
|
| 11 |
+
output_interface:
|
| 12 |
+
- "code"
|
| 13 |
+
- "human_feedback"
|
| 14 |
+
|
| 15 |
+
subflows_config:
|
| 16 |
+
MemoryReading:
|
| 17 |
+
_target_: Tachi67.MemoryReadingFlowModule.MemoryReadingAtomicFlow.instantiate_from_default_config
|
| 18 |
+
|
| 19 |
+
CodeGenerator:
|
| 20 |
+
_target_: Tachi67.CodeGeneratorFlowModule.CodeGeneratorAtomicFlow.instantiate_from_default_config
|
| 21 |
+
backend:
|
| 22 |
+
api_infos: ???
|
| 23 |
+
model_name:
|
| 24 |
+
openai: gpt-4
|
| 25 |
+
azure: azure/gpt-4
|
| 26 |
+
|
| 27 |
+
CodeFileEditor:
|
| 28 |
+
_target_: Tachi67.CodeFileEditFlowModule.CodeFileEditAtomicFlow.instantiate_from_default_config
|
| 29 |
+
|
| 30 |
+
ParseFeedback:
|
| 31 |
+
_target_: Tachi67.ParseFeedbackFlowModule.ParseFeedbackAtomicFlow.instantiate_from_default_config
|
| 32 |
+
|
| 33 |
+
early_exit_key: "EARLY_EXIT"
|
| 34 |
+
|
| 35 |
+
topology:
|
| 36 |
+
- goal: "Read in necessary memory"
|
| 37 |
+
input_interface:
|
| 38 |
+
_target_: flows.interfaces.KeyInterface
|
| 39 |
+
additional_transformations:
|
| 40 |
+
- _target_: flows.data_transformations.KeyMatchInput
|
| 41 |
+
flow: MemoryReading
|
| 42 |
+
reset: false
|
| 43 |
+
|
| 44 |
+
- goal: "Generate code to achieve the task."
|
| 45 |
+
input_interface:
|
| 46 |
+
_target_: flows.interfaces.KeyInterface
|
| 47 |
+
additional_transformations:
|
| 48 |
+
- _target_: flows.data_transformations.KeyMatchInput
|
| 49 |
+
flow: CodeGenerator
|
| 50 |
+
reset: false
|
| 51 |
+
|
| 52 |
+
- goal: "Write the code generated to a temp file with instructions to the user"
|
| 53 |
+
input_interface:
|
| 54 |
+
_target_: flows.interfaces.KeyInterface
|
| 55 |
+
additional_transformations:
|
| 56 |
+
- _target_: flows.data_transformations.KeyMatchInput
|
| 57 |
+
flow: CodeFileEditor
|
| 58 |
+
reset: false
|
| 59 |
+
|
| 60 |
+
- goal: "Parse user feedback from the temp file"
|
| 61 |
+
input_interface:
|
| 62 |
+
_target_: flows.interfaces.KeyInterface
|
| 63 |
+
additional_transformations:
|
| 64 |
+
- _target_: flows.data_transformations.KeyMatchInput
|
| 65 |
+
flow: ParseFeedback
|
| 66 |
+
reset: false
|
__init__.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ~~~ Specify the dependencies ~~~
|
| 2 |
+
dependencies = [
|
| 3 |
+
{"url": "Tachi67/MemoryReadingFlowModule", "revision": "main"},
|
| 4 |
+
{"url": "Tachi67/CodeGeneratorFlowModule", "revision": "main"},
|
| 5 |
+
{"url": "Tachi67/CodeFileEditFlowModule", "revision": "main"},
|
| 6 |
+
{"url": "Tachi67/ParseFeedbackFlowModule", "revision": "main"},
|
| 7 |
+
]
|
| 8 |
+
from flows import flow_verse
|
| 9 |
+
|
| 10 |
+
flow_verse.sync_dependencies(dependencies)
|
| 11 |
+
|
| 12 |
+
from .InteractiveCodeGenFlow import InteractiveCodeGenFlow
|