now you can load local activities via --local-activities

modified:   app.py
	modified:   research/activity15-choose-adventure.yaml
This commit is contained in:
Russell Ballestrini 2024-08-03 09:03:32 -04:00
parent 257e5a6a04
commit 65404a4ecd
2 changed files with 30 additions and 26 deletions

37
app.py
View file

@ -1712,6 +1712,24 @@ def cancel_generation(room_name):
)
def get_activity_content(file_path):
"""
Load the activity content from either S3 or the local filesystem based on the configuration.
"""
if app.config["LOCAL_ACTIVITIES"]:
# Load the activity YAML from a local file
with open(file_path, 'r') as file:
activity_yaml = file.read()
else:
# Load the activity YAML from S3
s3_client = boto3.client("s3")
bucket_name = os.environ.get("S3_BUCKET_NAME")
response = s3_client.get_object(Bucket=bucket_name, Key=file_path)
activity_yaml = response["Body"].read().decode("utf-8")
return yaml.safe_load(activity_yaml)
def loop_through_steps_until_question(
activity_content, activity_state, room_name, username
):
@ -1810,12 +1828,7 @@ def loop_through_steps_until_question(
def start_activity(room_name, s3_file_path, username):
s3_client = boto3.client("s3")
bucket_name = os.environ.get("S3_BUCKET_NAME")
response = s3_client.get_object(Bucket=bucket_name, Key=s3_file_path)
activity_yaml = response["Body"].read().decode("utf-8")
activity_content = yaml.safe_load(activity_yaml)
activity_content = get_activity_content(s3_file_path)
with app.app_context():
# Save the initial state to the database
@ -1919,16 +1932,10 @@ def handle_activity_response(room_name, user_response, username):
if not activity_state:
return
# Load the activity YAML from S3
s3_client = boto3.client("s3")
bucket_name = os.environ.get("S3_BUCKET_NAME")
s3_file_path = activity_state.s3_file_path
# Load the activity content
activity_content = get_activity_content(activity_state.s3_file_path)
try:
response = s3_client.get_object(Bucket=bucket_name, Key=s3_file_path)
activity_yaml = response["Body"].read().decode("utf-8")
activity_content = yaml.safe_load(activity_yaml)
# Find the current section and step
section = next(
s
@ -2379,9 +2386,11 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--profile", help="AWS profile name", default=None)
parser.add_argument("--local-activities", action="store_true", help="Use local activity files instead of S3")
args = parser.parse_args()
# Set profile_name as a global attribute of the app object
app.config["PROFILE_NAME"] = args.profile
app.config["LOCAL_ACTIVITIES"] = args.local_activities
socketio.run(app, host="0.0.0.0", port=5001, use_reloader=True)

View file

@ -7,10 +7,15 @@ sections:
- section_id: "section_1"
title: "The Escape Room Begins"
steps:
- step_id: "step_1"
- step_id: "step_0"
title: "Waking Up"
content_blocks:
- "You wake up in a dimly lit room with no memory of how you got there. The room is small and has a single door that is locked."
- step_id: "step_1"
title: "Explore"
content_blocks:
- "You see a rug on the floor, a bookshelf with a book, and a safe on the wall."
- "There is also an exit door, but it seems to be blocked by something."
- "What do you do first? Look under the rug, examine the book, try to open the safe, or try to leave the room?"
@ -39,12 +44,8 @@ sections:
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and guide the user to make the next choice. Be flexible to classify actions that lead to finding hidden items. Use emojis like 👍 and 🌟."
try_open_safe:
content_blocks:
- "You chose to try to open the safe. 🔒"
- "The safe is locked and requires both a key and a password to open."
next_section_and_step: "section_4:step_1"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and guide the user to make the next choice. Be flexible to classify actions that lead to finding hidden items. Use emojis like 👍 and 🌟."
try_leave_room:
metadata_conditions:
exit_key: true
@ -95,8 +96,6 @@ sections:
key: true
continue_exploring:
next_section_and_step: "section_1:step_1"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and guide the user to make the next choice. Be flexible to classify actions that lead to finding hidden items. Use emojis like 👍 and 🌟."
find_coin:
content_blocks:
- "You chose to take a closer look under the rug. 🧺"
@ -150,8 +149,6 @@ sections:
password: true
continue_exploring:
next_section_and_step: "section_1:step_1"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and guide the user to make the next choice. Be flexible to classify actions that lead to finding hidden items. Use emojis like 👍 and 🌟."
find_paper:
content_blocks:
- "You chose to take a closer look at the book. 📖"
@ -211,8 +208,6 @@ sections:
exit_key: true
continue_exploring:
next_section_and_step: "section_1:step_1"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and guide the user to make the next choice. Be flexible to classify actions that lead to finding hidden items. Use emojis like 👍 and 🌟."
go_back:
next_section_and_step: "section_3:step_1"
ai_feedback: