From 058b0161df44def081d24034fc540434ddbb2f6c Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Sat, 10 Aug 2024 15:00:28 -0400 Subject: [PATCH] allow increment to go backward with n-1 and also support any int c for the increment or decrement. modified: ../app.py modified: guarded_ai.py --- app.py | 9 +++++++-- research/guarded_ai.py | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 7b6413b..4cecc59 100644 --- a/app.py +++ b/app.py @@ -2164,8 +2164,13 @@ def handle_activity_response(room_name, user_response, username): for key, value in transition["metadata_add"].items(): if value == "the-users-response": value = user_response - elif value == "n+1": - value = activity_state.dict_metadata.get(key, 0) + 1 + elif isinstance(value, str) and (value.startswith("n+") or value.startswith("n-")): + # Extract the numeric part c and apply the operation +/- + c = int(value[1:]) + if value.startswith("n+"): + value = metadata.get(key, 0) + c + elif value.startswith("n-"): + value = metadata.get(key, 0) - c new_metadata[key] = value activity_state.add_metadata(key, value) diff --git a/research/guarded_ai.py b/research/guarded_ai.py index 23d2570..628c19e 100644 --- a/research/guarded_ai.py +++ b/research/guarded_ai.py @@ -226,8 +226,13 @@ def simulate_activity(yaml_file_path): for key, value in transition["metadata_add"].items(): if value == "the-users-response": value = user_response - elif value == "n+1": - value = metadata.get(key, 0) + 1 + elif isinstance(value, str) and (value.startswith("n+") or value.startswith("n-")): + # Extract the numeric part c and apply the operation +/- + c = int(value[1:]) + if value.startswith("n+"): + value = metadata.get(key, 0) + c + elif value.startswith("n-"): + value = metadata.get(key, 0) - c metadata[key] = value if "metadata_tmp_add" in transition: