Skip to content

Commit 4c817cd

Browse files
committed
[joonspk-research#78] Add procrastination between daily plan items, improve chronological order check
1 parent 503518c commit 4c817cd

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

reverie/backend_server/persona/prompt_template/run_gpt_prompt.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import ast
1212
import pprint
1313
from typing import Any, Dict, Optional
14+
from random import Random
1415

1516
sys.path.append('../../')
1617

@@ -126,7 +127,8 @@ def validate_json(self, json: JSONType):
126127
if not isinstance(json, list):
127128
return "Invalid JSON format (expected a JSON array)"
128129
if not all(isinstance(item, dict) and 'start' in item and 'end' in item and 'activity' in item for item in json):
129-
return "Invalid JSON format (expected an array of objects with 'time' and 'activity' fields)"
130+
return "Invalid JSON format (expected an array of objects with 'start', 'end' and 'activity' fields)"
131+
wake_up_time = string_to_time(json[0]["start"])
130132
prev_time = None
131133
prev_task = None
132134
for item in json:
@@ -137,13 +139,25 @@ def validate_json(self, json: JSONType):
137139
# For night owls, activities may continue past midnight and resume before the "wake-up" time.
138140
# This condition allows for time entries after midnight but before the first entry's time,
139141
# accommodating a schedule that doesn't strictly follow chronological order across days.
140-
if prev_time and time < prev_time and time > string_to_time(json[0]["start"]):
142+
is_past_midnight = time < wake_up_time and prev_time > wake_up_time
143+
if prev_time and time < prev_time and not is_past_midnight:
141144
raise ValueError(f'Tasks are not in chronological order. "{prev_task}" intersects with "{item["activity"]}"')
142145
prev_time = string_to_time(item["end"])
143146
prev_task = item["activity"]
144147

145148
def extract_json(self, json: JSONType):
146-
return [f"{item['start']} - {item['activity']}" for item in json]
149+
rng = Random(str(json))
150+
activities = ["Relax", "Rest", "Chill", "Procrastinate"]
151+
result = []
152+
for i, item in enumerate(json):
153+
if i != 0:
154+
start = item['start']
155+
prev_end = json[i-1]['end']
156+
if string_to_time(start) != string_to_time(prev_end):
157+
random_activity = rng.choice(activities)
158+
result.append(f"{prev_end} - {random_activity}")
159+
result.append(f"{item['start']} - {item['activity']}")
160+
return result
147161
# return [line for line in output.split('\n') if line.strip() and line[0].isdigit()]
148162

149163
def fallback(self, persona, wake_up_hour):
@@ -301,7 +315,7 @@ class run_gpt_prompt_action_sector(InferenceStrategy):
301315
We need to choose an appropriate Sector for the task at hand.
302316
303317
* Stay in the current sector if the activity can be done there. Only go out if the activity needs to take place in another place.
304-
* Must be one of the sectors from "All Sectors," verbatim.
318+
* Must be one of the sectors from "All Sectors," verbatim. It must be a Sector, and not an Arena.
305319
* If none of those fit very well, we must still choose the one that's the closest fit.
306320
* Return the answer as a JSON object with a single key "area". The value is the chosen area name.
307321

0 commit comments

Comments
 (0)