Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
abrichr committed May 26, 2023
1 parent 97e0838 commit 98abc16
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
1 change: 1 addition & 0 deletions puterbot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"OPENAI_MODEL_NAME": "gpt-3.5-turbo",
# may incur significant performance penalty
"RECORD_READ_ACTIVE_ELEMENT_STATE": False,
# TODO: remove?
"REPLAY_STRIP_ELEMENT_STATE": True,
}

Expand Down
3 changes: 2 additions & 1 deletion puterbot/playback.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def play_key_event(event, keyboard_controller, canonical=True):


def play_action_event(event, mouse_controller, keyboard_controller):
if event.children:
# currently we use children to replay type events
if event.children and event.name in KEY_EVENTS:
for child in event.children:
play_action_event(child, mouse_controller, keyboard_controller)
else:
Expand Down
2 changes: 1 addition & 1 deletion puterbot/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ def record(

plot_performance(recording_timestamp, perf_q)

logger.info("done")
logger.info(f"saved {recording_timestamp=}")


if __name__ == "__main__":
Expand Down
22 changes: 15 additions & 7 deletions puterbot/strategies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def __init__(
):
self.recording = recording
self.max_frame_times = max_frame_times
self.processed_action_events = recording.processed_action_events
self.action_events = []
self.screenshots = []
self.window_events = []
Expand All @@ -53,9 +52,14 @@ def run(self):
)
except StopIteration:
break
if self.action_events:
prev_action_event = self.action_events[-1]
assert prev_action_event.timestamp <= action_event.timestamp, (
prev_action_event, action_event
)
self.log_fps()
self.action_events.append(action_event)
if action_event:
self.action_events.append(action_event)
action_event_dict = utils.rows2dicts(
[action_event],
drop_constant=False,
Expand All @@ -64,11 +68,15 @@ def run(self):
f"action_event=\n"
f"{pformat(action_event_dict)}"
)
playback.play_action_event(
action_event,
mouse_controller,
keyboard_controller,
)
try:
playback.play_action_event(
action_event,
mouse_controller,
keyboard_controller,
)
except Exception as exc:
logger.exception(exc)
import ipdb; ipdb.set_trace()

def log_fps(self):
t = time.time()
Expand Down
13 changes: 9 additions & 4 deletions puterbot/strategies/naive.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


DISPLAY_EVENTS = False
PROCESS_EVENTS = False
PROCESS_EVENTS = True
REPLAY_EVENTS = True
SLEEP = False

Expand All @@ -25,23 +25,28 @@ def __init__(
recording: models.Recording,
display_events=DISPLAY_EVENTS,
replay_events=REPLAY_EVENTS,
process_events=PROCESS_EVENTS,
sleep=SLEEP,
):
super().__init__(recording)
self.display_events = display_events
self.replay_events = replay_events
self.process_events = process_events
self.sleep = sleep
self.prev_timestamp = None
self.action_event_idx = -1
event_dicts = utils.rows2dicts(self.processed_action_events)
logger.info(f"event_dicts=\n{pformat(event_dicts)}")
#event_dicts = utils.rows2dicts(self.processed_action_events)
#logger.info(f"event_dicts=\n{pformat(event_dicts)}")

def get_next_action_event(
self,
screenshot: models.Screenshot,
window_event: models.WindowEvent,
):
action_events = self.processed_action_events if PROCESS_EVENTS else self.recording.action_events
if self.process_events:
action_events = self.recording.processed_action_events
else:
action_events = self.recording.action_events
self.action_event_idx += 1
num_action_events = len(action_events)
if self.action_event_idx >= num_action_events:
Expand Down

0 comments on commit 98abc16

Please sign in to comment.