metadata_add and metadata_remove to allow for items to be consumed.
modified: app.py modified: research/activity14-choose-adventure.yaml modified: research/activity15-choose-adventure.yaml modified: research/activity16.yaml
This commit is contained in:
parent
7198f2109e
commit
7ceb9303ea
4 changed files with 48 additions and 35 deletions
37
app.py
37
app.py
|
|
@ -117,11 +117,17 @@ class ActivityState(db.Model):
|
|||
def dict_metadata(self, value):
|
||||
self.json_metadata = json.dumps(value)
|
||||
|
||||
def update_metadata(self, key, value):
|
||||
def add_metadata(self, key, value):
|
||||
metadata = self.dict_metadata
|
||||
metadata[key] = value
|
||||
self.dict_metadata = metadata
|
||||
|
||||
def remove_metadata(self, key):
|
||||
metadata = self.dict_metadata
|
||||
if key in metadata:
|
||||
del metadata[key]
|
||||
self.dict_metadata = metadata
|
||||
|
||||
|
||||
def get_room(room_name):
|
||||
"""Utility function to get room from room name."""
|
||||
|
|
@ -1718,7 +1724,7 @@ def get_activity_content(file_path):
|
|||
"""
|
||||
if app.config["LOCAL_ACTIVITIES"]:
|
||||
# Load the activity YAML from a local file
|
||||
with open(file_path, 'r') as file:
|
||||
with open(file_path, "r") as file:
|
||||
activity_yaml = file.read()
|
||||
else:
|
||||
# Load the activity YAML from S3
|
||||
|
|
@ -2061,15 +2067,19 @@ def handle_activity_response(room_name, user_response, username):
|
|||
)
|
||||
|
||||
# Update metadata based on user actions
|
||||
if "metadata_updates" in step["transitions"][category]:
|
||||
if "metadata_add" in step["transitions"][category]:
|
||||
for key, value in step["transitions"][category][
|
||||
"metadata_updates"
|
||||
"metadata_add"
|
||||
].items():
|
||||
activity_state.update_metadata(key, value)
|
||||
activity_state.add_metadata(key, value)
|
||||
|
||||
# Commit the changes after the loop
|
||||
db.session.add(activity_state)
|
||||
db.session.commit()
|
||||
if "metadata_remove" in step["transitions"][category]:
|
||||
for key in step["transitions"][category]["metadata_remove"]:
|
||||
activity_state.remove_metadata(key)
|
||||
|
||||
# Commit the changes after the loop
|
||||
db.session.add(activity_state)
|
||||
db.session.commit()
|
||||
|
||||
# if "correct" or max_attempts reached.
|
||||
if (
|
||||
|
|
@ -2314,10 +2324,7 @@ def categorize_response(question, response, buckets, tokens_for_ai):
|
|||
temperature=0,
|
||||
)
|
||||
category = (
|
||||
completion.choices[0]
|
||||
.message.content.strip()
|
||||
.lower()
|
||||
.replace(" ", "_")
|
||||
completion.choices[0].message.content.strip().lower().replace(" ", "_")
|
||||
)
|
||||
return category
|
||||
except Exception as e:
|
||||
|
|
@ -2384,7 +2391,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")
|
||||
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
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ sections:
|
|||
next_section_and_step: "section_2:step_1"
|
||||
ai_feedback:
|
||||
tokens_for_ai: "Provide positive reinforcement and guide the user to make the next choice. Use emojis like 👍 and 🌟."
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
key: true
|
||||
examine_book:
|
||||
content_blocks:
|
||||
|
|
@ -40,7 +40,7 @@ sections:
|
|||
next_section_and_step: "section_3:step_1"
|
||||
ai_feedback:
|
||||
tokens_for_ai: "Provide positive reinforcement and guide the user to make the next choice. Use emojis like 👍 and 🌟."
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
password: true
|
||||
try_open_safe:
|
||||
content_blocks:
|
||||
|
|
@ -86,7 +86,7 @@ sections:
|
|||
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. Use emojis like 👍 and 🌟."
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
key: true
|
||||
continue_exploring:
|
||||
content_blocks:
|
||||
|
|
@ -139,7 +139,7 @@ sections:
|
|||
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. Use emojis like 👍 and 🌟."
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
password: true
|
||||
continue_exploring:
|
||||
content_blocks:
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ sections:
|
|||
content_blocks:
|
||||
- "You chose to take the key. 🔑"
|
||||
next_section_and_step: "section_1:step_1"
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
key: true
|
||||
continue_exploring:
|
||||
next_section_and_step: "section_1:step_1"
|
||||
|
|
@ -84,7 +84,7 @@ sections:
|
|||
next_section_and_step: "section_1:step_1"
|
||||
ai_feedback:
|
||||
tokens_for_ai: "The player found a hidden coin. Congratulate them by name with your feedback. Use emojis like 👍 and 🌟."
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
coin: true
|
||||
go_back:
|
||||
next_section_and_step: "section_1:step_1"
|
||||
|
|
@ -121,7 +121,7 @@ sections:
|
|||
content_blocks:
|
||||
- "You chose to take note of the password. 🔑"
|
||||
next_section_and_step: "section_1:step_1"
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
password: true
|
||||
continue_exploring:
|
||||
next_section_and_step: "section_1:step_1"
|
||||
|
|
@ -133,7 +133,7 @@ sections:
|
|||
next_section_and_step: "section_1:step_1"
|
||||
ai_feedback:
|
||||
tokens_for_ai: "The player found a hidden paper with a cryptic message. Congratulate them by name with your feedback. Use emojis like 👍 and 🌟."
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
paper: true
|
||||
go_back:
|
||||
next_section_and_step: "section_1:step_1"
|
||||
|
|
@ -175,7 +175,7 @@ sections:
|
|||
next_section_and_step: "section_4:step_1"
|
||||
ai_feedback:
|
||||
tokens_for_ai: "Provide positive reinforcement and guide the user to the final encounter. Be flexible to classify actions that lead to finding hidden items. Use emojis like 👍 and 🌟."
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
second_safe: true
|
||||
exit_key: true
|
||||
continue_exploring:
|
||||
|
|
@ -188,6 +188,8 @@ sections:
|
|||
metadata_conditions:
|
||||
coin: true
|
||||
second_safe: true
|
||||
metadata_remove:
|
||||
- coin
|
||||
next_section_and_step: "section_5:step_1"
|
||||
ai_feedback:
|
||||
tokens_for_ai: "Provide positive reinforcement and guide the user to the final encounter. Be flexible to classify actions that lead to finding hidden items. Use emojis like 👍 and 🌟."
|
||||
|
|
@ -267,52 +269,52 @@ sections:
|
|||
prize_1:
|
||||
content_blocks:
|
||||
- "You won Prize 1: A golden keychain. 🗝️"
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
prize: golden_keychain
|
||||
prize_2:
|
||||
content_blocks:
|
||||
- "You won Prize 2: A mysterious amulet. 🧿"
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
prize: mysterious_amulet
|
||||
prize_3:
|
||||
content_blocks:
|
||||
- "You won Prize 3: A rare gemstone. 💎"
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
prize: rare_gemstone
|
||||
prize_4:
|
||||
content_blocks:
|
||||
- "You won Prize 4: An ancient scroll. 📜"
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
prize: ancient_scroll
|
||||
prize_5:
|
||||
content_blocks:
|
||||
- "You won Prize 5: A magical wand. 🪄"
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
prize: magical_wand
|
||||
prize_6:
|
||||
content_blocks:
|
||||
- "You won Prize 6: A treasure map. 🗺️"
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
prize: treasure_map
|
||||
prize_7:
|
||||
content_blocks:
|
||||
- "You won Prize 7: A silver coin. 🪙"
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
prize: silver_coin
|
||||
prize_8:
|
||||
content_blocks:
|
||||
- "You won Prize 8: A mystical ring. 💍"
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
prize: mystical_ring
|
||||
prize_9:
|
||||
content_blocks:
|
||||
- "You won Prize 9: A rare book. 📚"
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
prize: rare_book
|
||||
prize_10:
|
||||
content_blocks:
|
||||
- "You won Prize 10: A magical potion. 🧪"
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
prize: magical_potion
|
||||
|
||||
- section_id: "section_7"
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ sections:
|
|||
next_section_and_step: "introduction:intro_step_2"
|
||||
ai_feedback:
|
||||
tokens_for_ai: "Provide positive reinforcement and guide the user back to the introduction. Use emojis like 👍 and 🌟."
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
lesson_1_completed: true
|
||||
not_understand:
|
||||
content_blocks:
|
||||
|
|
@ -188,7 +188,7 @@ sections:
|
|||
next_section_and_step: "introduction:intro_step_2"
|
||||
ai_feedback:
|
||||
tokens_for_ai: "Provide positive reinforcement and guide the user back to the introduction. Use emojis like 👍 and 🌟."
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
lesson_2_completed: true
|
||||
not_understand:
|
||||
content_blocks:
|
||||
|
|
@ -260,7 +260,7 @@ sections:
|
|||
next_section_and_step: "introduction:intro_step_2"
|
||||
ai_feedback:
|
||||
tokens_for_ai: "Provide positive reinforcement and guide the user back to the introduction. Use emojis like 👍 and 🌟."
|
||||
metadata_updates:
|
||||
metadata_add:
|
||||
lesson_3_completed: true
|
||||
not_understand:
|
||||
content_blocks:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue