Update ParseFeedbackAtomicFlow.py
Browse files
ParseFeedbackAtomicFlow.py
CHANGED
|
@@ -58,13 +58,13 @@ class ParseFeedbackAtomicFlow(AtomicFlow):
|
|
| 58 |
elif code_file_exists and plan_file_exists:
|
| 59 |
raise AssertionError("Both code file and plan file are passed to ParseFeedbackAtomic, which one to parse?")
|
| 60 |
|
| 61 |
-
def
|
|
|
|
| 62 |
while True:
|
| 63 |
-
|
| 64 |
-
current_time = os.path.getmtime(file_location)
|
| 65 |
-
if current_time != last_check_time:
|
| 66 |
break
|
| 67 |
-
|
|
|
|
| 68 |
def run(
|
| 69 |
self,
|
| 70 |
input_data: Dict[str, Any]
|
|
@@ -73,16 +73,14 @@ class ParseFeedbackAtomicFlow(AtomicFlow):
|
|
| 73 |
self._check_input(input_data)
|
| 74 |
if "temp_code_file_location" in input_data:
|
| 75 |
temp_code_file_location = input_data['temp_code_file_location']
|
| 76 |
-
last_check_time
|
| 77 |
-
self._wait_for_file_update(temp_code_file_location, last_check_time)
|
| 78 |
code_content = self._read_content(temp_code_file_location, "code")
|
| 79 |
user_thoughts = self._parse_user_thoughts(temp_code_file_location)
|
| 80 |
response = {"code": code_content, "feedback": user_thoughts}
|
| 81 |
|
| 82 |
elif "temp_plan_file_location" in input_data:
|
| 83 |
plan_file_location = input_data["temp_plan_file_location"]
|
| 84 |
-
last_check_time
|
| 85 |
-
self._wait_for_file_update(plan_file_location, last_check_time)
|
| 86 |
plan_content = self._read_content(plan_file_location, "plan")
|
| 87 |
user_thoughts = self._parse_user_thoughts(plan_file_location)
|
| 88 |
response = {"plan": plan_content, "feedback": user_thoughts}
|
|
|
|
| 58 |
elif code_file_exists and plan_file_exists:
|
| 59 |
raise AssertionError("Both code file and plan file are passed to ParseFeedbackAtomic, which one to parse?")
|
| 60 |
|
| 61 |
+
def _open_file_and_wait_for_file_update(self, file_location, check_interval=1):
|
| 62 |
+
process = subprocess.Popen(["code", "--wait", file_location])
|
| 63 |
while True:
|
| 64 |
+
if process.poll() is not None:
|
|
|
|
|
|
|
| 65 |
break
|
| 66 |
+
time.sleep(check_interval)
|
| 67 |
+
|
| 68 |
def run(
|
| 69 |
self,
|
| 70 |
input_data: Dict[str, Any]
|
|
|
|
| 73 |
self._check_input(input_data)
|
| 74 |
if "temp_code_file_location" in input_data:
|
| 75 |
temp_code_file_location = input_data['temp_code_file_location']
|
| 76 |
+
self._open_file_and_wait_for_file_update(temp_code_file_location, last_check_time)
|
|
|
|
| 77 |
code_content = self._read_content(temp_code_file_location, "code")
|
| 78 |
user_thoughts = self._parse_user_thoughts(temp_code_file_location)
|
| 79 |
response = {"code": code_content, "feedback": user_thoughts}
|
| 80 |
|
| 81 |
elif "temp_plan_file_location" in input_data:
|
| 82 |
plan_file_location = input_data["temp_plan_file_location"]
|
| 83 |
+
self._open_file_and_wait_for_file_update(plan_file_location, last_check_time)
|
|
|
|
| 84 |
plan_content = self._read_content(plan_file_location, "plan")
|
| 85 |
user_thoughts = self._parse_user_thoughts(plan_file_location)
|
| 86 |
response = {"plan": plan_content, "feedback": user_thoughts}
|