11
11
import ast
12
12
import pprint
13
13
from typing import Any , Dict , Optional
14
+ from random import Random
14
15
15
16
sys .path .append ('../../' )
16
17
@@ -126,7 +127,8 @@ def validate_json(self, json: JSONType):
126
127
if not isinstance (json , list ):
127
128
return "Invalid JSON format (expected a JSON array)"
128
129
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" ])
130
132
prev_time = None
131
133
prev_task = None
132
134
for item in json :
@@ -137,13 +139,25 @@ def validate_json(self, json: JSONType):
137
139
# For night owls, activities may continue past midnight and resume before the "wake-up" time.
138
140
# This condition allows for time entries after midnight but before the first entry's time,
139
141
# 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 :
141
144
raise ValueError (f'Tasks are not in chronological order. "{ prev_task } " intersects with "{ item ["activity" ]} "' )
142
145
prev_time = string_to_time (item ["end" ])
143
146
prev_task = item ["activity" ]
144
147
145
148
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
147
161
# return [line for line in output.split('\n') if line.strip() and line[0].isdigit()]
148
162
149
163
def fallback (self , persona , wake_up_hour ):
@@ -301,7 +315,7 @@ class run_gpt_prompt_action_sector(InferenceStrategy):
301
315
We need to choose an appropriate Sector for the task at hand.
302
316
303
317
* 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.
305
319
* If none of those fit very well, we must still choose the one that's the closest fit.
306
320
* Return the answer as a JSON object with a single key "area". The value is the chosen area name.
307
321
0 commit comments