Update ParseFeedbackAtomicFlow.py
Browse files- ParseFeedbackAtomicFlow.py +14 -1
ParseFeedbackAtomicFlow.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
from typing import Dict, Any
|
| 2 |
from flows.base_flows.atomic import AtomicFlow
|
|
|
|
|
|
|
| 3 |
|
| 4 |
|
| 5 |
class ParseFeedbackAtomicFlow(AtomicFlow):
|
|
@@ -56,6 +58,13 @@ class ParseFeedbackAtomicFlow(AtomicFlow):
|
|
| 56 |
elif code_file_exists and plan_file_exists:
|
| 57 |
raise AssertionError("Both code file and plan file are passed to ParseFeedbackAtomic, which one to parse?")
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
def run(
|
| 60 |
self,
|
| 61 |
input_data: Dict[str, Any]
|
|
@@ -63,13 +72,17 @@ class ParseFeedbackAtomicFlow(AtomicFlow):
|
|
| 63 |
response = {}
|
| 64 |
self._check_input(input_data)
|
| 65 |
if "temp_code_file_location" in input_data:
|
| 66 |
-
temp_code_file_location = input_data['
|
|
|
|
|
|
|
| 67 |
code_content = self._read_content(temp_code_file_location, "code")
|
| 68 |
user_thoughts = self._parse_user_thoughts(temp_code_file_location)
|
| 69 |
response = {"code": code_content, "human_feedback": user_thoughts}
|
| 70 |
|
| 71 |
elif "plan_file_location" in input_data:
|
| 72 |
plan_file_location = input_data['plan_file_location']
|
|
|
|
|
|
|
| 73 |
plan_content = self._read_content(plan_file_location, "plan")
|
| 74 |
user_thoughts = self._parse_user_thoughts(plan_file_location)
|
| 75 |
response = {"plan": plan_content, "human_feedback": user_thoughts}
|
|
|
|
| 1 |
from typing import Dict, Any
|
| 2 |
from flows.base_flows.atomic import AtomicFlow
|
| 3 |
+
import time
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
|
| 7 |
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 _wait_for_file_update(self, file_location, last_check_time, check_interval=1):
|
| 62 |
+
while True:
|
| 63 |
+
time.sleep(check_interval)
|
| 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]
|
|
|
|
| 72 |
response = {}
|
| 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 = input_data["temp_code_file_written_timestamp"]
|
| 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, "human_feedback": user_thoughts}
|
| 81 |
|
| 82 |
elif "plan_file_location" in input_data:
|
| 83 |
plan_file_location = input_data['plan_file_location']
|
| 84 |
+
last_check_time = input_data["plan_file_written_timestamp"]
|
| 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, "human_feedback": user_thoughts}
|