Upload 7 files
Browse files- ParseFeedbackAtomicFlow.py +42 -0
- README.md +34 -1
ParseFeedbackAtomicFlow.py
CHANGED
|
@@ -14,8 +14,22 @@ class ParseFeedbackAtomicFlow(AtomicFlow):
|
|
| 14 |
*Output Interface*:
|
| 15 |
- `code`: The content of the code file.
|
| 16 |
- `feedback`: The feedback from the user.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
"""
|
| 18 |
def _read_content(self, file_location, file_type):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
if file_type == "code":
|
| 20 |
header_string = "# Code:\n"
|
| 21 |
elif file_type == "plan":
|
|
@@ -39,6 +53,13 @@ class ParseFeedbackAtomicFlow(AtomicFlow):
|
|
| 39 |
return ret
|
| 40 |
|
| 41 |
def _parse_user_thoughts(self, file_location):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
with open(file_location, "r") as file:
|
| 43 |
content = file.read()
|
| 44 |
|
|
@@ -61,6 +82,13 @@ class ParseFeedbackAtomicFlow(AtomicFlow):
|
|
| 61 |
return thoughts
|
| 62 |
|
| 63 |
def _check_input(self, input_data: Dict[str, Any]):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
code_file_exists = "temp_code_file_location" in input_data
|
| 65 |
plan_file_exists = "temp_plan_file_location" in input_data
|
| 66 |
if code_file_exists == False and plan_file_exists == False:
|
|
@@ -69,6 +97,13 @@ class ParseFeedbackAtomicFlow(AtomicFlow):
|
|
| 69 |
raise AssertionError("Both code file and plan file are passed to ParseFeedbackAtomic, which one to parse?")
|
| 70 |
|
| 71 |
def _open_file_and_wait_for_file_update(self, file_location, check_interval=1):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
process = subprocess.Popen(["code", "--wait", file_location])
|
| 73 |
while True:
|
| 74 |
if process.poll() is not None:
|
|
@@ -79,6 +114,13 @@ class ParseFeedbackAtomicFlow(AtomicFlow):
|
|
| 79 |
self,
|
| 80 |
input_data: Dict[str, Any]
|
| 81 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
response = {}
|
| 83 |
self._check_input(input_data)
|
| 84 |
if "temp_code_file_location" in input_data:
|
|
|
|
| 14 |
*Output Interface*:
|
| 15 |
- `code`: The content of the code file.
|
| 16 |
- `feedback`: The feedback from the user.
|
| 17 |
+
|
| 18 |
+
*Configuration Parameters*:
|
| 19 |
+
- `input_interface`: The input interface of the flow.
|
| 20 |
+
- `output_interface`: The output interface of the flow.
|
| 21 |
+
|
| 22 |
"""
|
| 23 |
def _read_content(self, file_location, file_type):
|
| 24 |
+
"""
|
| 25 |
+
Read the content of the file and return the content of the file.
|
| 26 |
+
:param file_location: The location of the file.
|
| 27 |
+
:type file_location: str
|
| 28 |
+
:param file_type: The type of the file, should be either "code" or "plan".
|
| 29 |
+
:type file_type: str
|
| 30 |
+
:return: The content of the file.
|
| 31 |
+
:rtype: str
|
| 32 |
+
"""
|
| 33 |
if file_type == "code":
|
| 34 |
header_string = "# Code:\n"
|
| 35 |
elif file_type == "plan":
|
|
|
|
| 53 |
return ret
|
| 54 |
|
| 55 |
def _parse_user_thoughts(self, file_location):
|
| 56 |
+
"""
|
| 57 |
+
Parse the user thoughts from the file.
|
| 58 |
+
:param file_location: The location of the file.
|
| 59 |
+
:type file_location: str
|
| 60 |
+
:return: The user thoughts.
|
| 61 |
+
:rtype: str
|
| 62 |
+
"""
|
| 63 |
with open(file_location, "r") as file:
|
| 64 |
content = file.read()
|
| 65 |
|
|
|
|
| 82 |
return thoughts
|
| 83 |
|
| 84 |
def _check_input(self, input_data: Dict[str, Any]):
|
| 85 |
+
"""
|
| 86 |
+
Check if the input is valid.
|
| 87 |
+
:param input_data: The input data.
|
| 88 |
+
:type input_data: Dict[str, Any]
|
| 89 |
+
:raises AssertionError: If neither code file nor plan file is passed to ParseFeedbackAtomicFlow.
|
| 90 |
+
:raises AssertionError: If both code file and plan file are passed to ParseFeedbackAtomicFlow.
|
| 91 |
+
"""
|
| 92 |
code_file_exists = "temp_code_file_location" in input_data
|
| 93 |
plan_file_exists = "temp_plan_file_location" in input_data
|
| 94 |
if code_file_exists == False and plan_file_exists == False:
|
|
|
|
| 97 |
raise AssertionError("Both code file and plan file are passed to ParseFeedbackAtomic, which one to parse?")
|
| 98 |
|
| 99 |
def _open_file_and_wait_for_file_update(self, file_location, check_interval=1):
|
| 100 |
+
"""
|
| 101 |
+
Open the file in VSCode and wait for the user to close the file.
|
| 102 |
+
:param file_location: The location of the file.
|
| 103 |
+
:type file_location: str
|
| 104 |
+
:param check_interval: The interval between two checks, defaults to 1.
|
| 105 |
+
:type check_interval: int, optional
|
| 106 |
+
"""
|
| 107 |
process = subprocess.Popen(["code", "--wait", file_location])
|
| 108 |
while True:
|
| 109 |
if process.poll() is not None:
|
|
|
|
| 114 |
self,
|
| 115 |
input_data: Dict[str, Any]
|
| 116 |
):
|
| 117 |
+
"""
|
| 118 |
+
Run the flow.
|
| 119 |
+
:param input_data: The input data.
|
| 120 |
+
:type input_data: Dict[str, Any]
|
| 121 |
+
:return: The output data.
|
| 122 |
+
:rtype: Dict[str, Any]
|
| 123 |
+
"""
|
| 124 |
response = {}
|
| 125 |
self._check_input(input_data)
|
| 126 |
if "temp_code_file_location" in input_data:
|
README.md
CHANGED
|
@@ -2,6 +2,9 @@
|
|
| 2 |
|
| 3 |
* [ParseFeedbackAtomicFlow](#ParseFeedbackAtomicFlow)
|
| 4 |
* [ParseFeedbackAtomicFlow](#ParseFeedbackAtomicFlow.ParseFeedbackAtomicFlow)
|
|
|
|
|
|
|
|
|
|
| 5 |
* [\_\_init\_\_](#__init__)
|
| 6 |
|
| 7 |
<a id="ParseFeedbackAtomicFlow"></a>
|
|
@@ -23,9 +26,39 @@ The flow will open the file in VSCode and wait for the user to edit the file. On
|
|
| 23 |
- `temp_code_file_location`: Notice that if we are parsing the plan file, this should be changed to `temp_plan_file_location`.
|
| 24 |
|
| 25 |
*Output Interface*:
|
| 26 |
-
- `code`: The content of the code file.
|
| 27 |
- `feedback`: The feedback from the user.
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
<a id="__init__"></a>
|
| 30 |
|
| 31 |
# \_\_init\_\_
|
|
|
|
| 2 |
|
| 3 |
* [ParseFeedbackAtomicFlow](#ParseFeedbackAtomicFlow)
|
| 4 |
* [ParseFeedbackAtomicFlow](#ParseFeedbackAtomicFlow.ParseFeedbackAtomicFlow)
|
| 5 |
+
* [run](#ParseFeedbackAtomicFlow.ParseFeedbackAtomicFlow.run)
|
| 6 |
+
* [example\_code\_file](#example_code_file)
|
| 7 |
+
* [run](#run)
|
| 8 |
* [\_\_init\_\_](#__init__)
|
| 9 |
|
| 10 |
<a id="ParseFeedbackAtomicFlow"></a>
|
|
|
|
| 26 |
- `temp_code_file_location`: Notice that if we are parsing the plan file, this should be changed to `temp_plan_file_location`.
|
| 27 |
|
| 28 |
*Output Interface*:
|
| 29 |
+
- `code`: The content of the code file.
|
| 30 |
- `feedback`: The feedback from the user.
|
| 31 |
|
| 32 |
+
*Configuration Parameters*:
|
| 33 |
+
- `input_interface`: The input interface of the flow.
|
| 34 |
+
- `output_interface`: The output interface of the flow.
|
| 35 |
+
|
| 36 |
+
<a id="ParseFeedbackAtomicFlow.ParseFeedbackAtomicFlow.run"></a>
|
| 37 |
+
|
| 38 |
+
#### run
|
| 39 |
+
|
| 40 |
+
```python
|
| 41 |
+
def run(input_data: Dict[str, Any])
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
Run the flow.
|
| 45 |
+
|
| 46 |
+
**Arguments**:
|
| 47 |
+
|
| 48 |
+
- `input_data` (`Dict[str, Any]`): The input data.
|
| 49 |
+
|
| 50 |
+
**Returns**:
|
| 51 |
+
|
| 52 |
+
`Dict[str, Any]`: The output data.
|
| 53 |
+
|
| 54 |
+
<a id="example_code_file"></a>
|
| 55 |
+
|
| 56 |
+
# example\_code\_file
|
| 57 |
+
|
| 58 |
+
<a id="run"></a>
|
| 59 |
+
|
| 60 |
+
# run
|
| 61 |
+
|
| 62 |
<a id="__init__"></a>
|
| 63 |
|
| 64 |
# \_\_init\_\_
|