Allowing for non-linear progression depending on buckets category

new field in the transitions is next_section_and_step which is optional
and defaults to None but also can be "section_3:step_1"

	modified:   app.py
	new file:   research/activity0.yaml
	new file:   research/activity13-choose-adventure.yaml
	modified:   research/guarded_ai.py
This commit is contained in:
Russell Ballestrini 2024-07-28 10:36:09 -04:00
parent 7e97acf477
commit cfa5d77a42
4 changed files with 772 additions and 51 deletions

45
app.py
View file

@ -1741,7 +1741,6 @@ def start_activity(room_name, s3_file_path, username):
room=room_name,
)
def handle_activity_response(room_name, user_response, username):
with app.app_context():
room = get_room(room_name)
@ -1787,7 +1786,7 @@ def handle_activity_response(room_name, user_response, username):
)
# Provide feedback based on the category
feedback = provide_feedback(
feedback, next_section_and_step = provide_feedback(
activity_content,
section["section_id"],
step["step_id"],
@ -1811,15 +1810,30 @@ def handle_activity_response(room_name, user_response, username):
room=room_name,
)
# if correct or max_attempts reached.
# if "correct" or max_attempts reached.
if (
category == "correct"
category
not in [
"off_topic",
"asking_clarifying_questions",
"partial_understanding",
]
or activity_state.attempts >= activity_state.max_attempts
):
# Move to the next step or section
next_section, next_step = get_next_step(
activity_content, section["section_id"], step["step_id"]
)
if next_section_and_step:
current_section_id, current_step_id = next_section_and_step.split(":")
next_section = next(
s for s in activity_content["sections"] if s["section_id"] == current_section_id
)
next_step = next(
s for s in next_section["steps"] if s["step_id"] == current_step_id
)
else:
# Move to the next step or section
next_section, next_step = get_next_step(
activity_content, section["section_id"], step["step_id"]
)
if next_step:
activity_state.section_id = next_section["section_id"]
activity_state.step_id = next_step["step_id"]
@ -1864,8 +1878,8 @@ def handle_activity_response(room_name, user_response, username):
room=room_name,
)
else:
# Activity completed
# Display activity info before completing
# Activity completed!
# Display activity info before deleting.
display_activity_info(room_name, username)
socketio.emit(
@ -1970,6 +1984,7 @@ def display_activity_info(room_name, username):
Provide a score out of 10 for each criterion and an overall grade for each user.
Finally order each user by who is winning. Number of correct answers and accuracy & include an enumeration of the feats!
Take into account how many attempts the user took to get a passing answer when ranking.
Don't just try to give the user a "B" or 35/40, really figure out a good placement considering some people don't know how to type.
""",
)
@ -2109,7 +2124,6 @@ def generate_ai_feedback(category, question, user_response, tokens_for_ai):
return f"Error: {e}"
# Provide feedback based on the category
def provide_feedback(
yaml_content, section_id, step_id, category, question, user_response
):
@ -2117,15 +2131,15 @@ def provide_feedback(
(s for s in yaml_content["sections"] if s["section_id"] == section_id), None
)
if not section:
return "Section not found."
return "Section not found.", None
step = next((s for s in section["steps"] if s["step_id"] == step_id), None)
if not step:
return "Step not found."
return "Step not found.", None
transition = step["transitions"].get(category, None)
if not transition:
return "Category not found."
return "Category not found.", None
feedback = "\n".join(transition["content_blocks"])
if "ai_feedback" in transition:
@ -2137,7 +2151,8 @@ def provide_feedback(
)
feedback += f"\n\nAI Feedback: {ai_feedback}"
return feedback
next_section_and_step = transition.get("next_section_and_step", None)
return feedback, next_section_and_step
if __name__ == "__main__":

302
research/activity0.yaml Normal file
View file

@ -0,0 +1,302 @@
default_max_attempts_per_step: 3
sections:
- section_id: "section_1"
title: "Introduction to The GNU Manifesto"
steps:
- step_id: "step_1"
title: "What is The GNU Manifesto?"
content_blocks:
- "<img src='https://www.gnu.org/graphics/heckert_gnu.transp.small.png'>"
- "Welcome to the GNU Manifesto course! 👋"
- "The GNU Manifesto was written by Richard Stallman in 1985 to ask for support in developing the GNU operating system."
- "Think about why someone might want to create a free operating system. Consider issues like software freedom, collaboration, and accessibility."
tokens_for_ai: "Guide the student to think about the reasons for creating a free operating system. If any part of the user's answer is correct and on-topic, categorize it as 'correct'."
question: "Why do you think Richard Stallman wanted to create a free operating system? 🤔"
buckets:
- correct
- partial_understanding
- off_topic
- asking_clarifying_questions
transitions:
correct:
content_blocks:
- "Great! You have a good understanding of why Richard Stallman wanted to create a free operating system. 🎉"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and encourage the student to continue learning. Use emojis like 👍 and 🌟."
partial_understanding:
content_blocks:
- "You have a partial understanding. Let's clarify a few points. 🤔"
ai_feedback:
tokens_for_ai: "Provide additional information to clarify the student's understanding in a friendly and supportive manner. Use emojis like 🤔 and 📚."
off_topic:
content_blocks:
- "It seems like your response is off-topic. Let's try to stay focused on the reasons for creating a free operating system. 🔄"
ai_feedback:
tokens_for_ai: "Gently guide the student back to the topic of the reasons for creating a free operating system in a supportive manner. Use emojis like 🔄 and 🧭."
asking_clarifying_questions:
content_blocks:
- "I see you have some questions. Let's address them. ❓"
ai_feedback:
tokens_for_ai: "Answer the student's clarifying questions and provide additional information in a friendly and engaging manner. Use emojis like ❓ and 💬."
- step_id: "step_2"
title: "Importance of The GNU Manifesto"
content_blocks:
- "The GNU Manifesto is important because it laid the foundation for the Free Software Movement."
- "It emphasizes the importance of software freedom, collaboration, and user rights."
- "Think about how having free software might benefit users and developers. Consider aspects like cost, accessibility, and innovation."
tokens_for_ai: "Guide the student to think about the benefits of free software. If any part of the user's answer is correct and on-topic, categorize it as 'correct'."
question: "How do you think free software benefits users and developers? 🤔"
buckets:
- correct
- partial_understanding
- off_topic
- asking_clarifying_questions
transitions:
correct:
content_blocks:
- "Excellent! You understand the benefits of free software. 🎉"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and encourage the student to continue learning. Use emojis like 👍 and 🌟."
partial_understanding:
content_blocks:
- "You have a partial understanding. Let's clarify a few points. 🤔"
ai_feedback:
tokens_for_ai: "Provide additional information to clarify the student's understanding in a friendly and supportive manner. Use emojis like 🤔 and 📚."
off_topic:
content_blocks:
- "It seems like your response is off-topic. Let's try to stay focused on the benefits of free software. 🔄"
ai_feedback:
tokens_for_ai: "Gently guide the student back to the topic of the benefits of free software in a supportive manner. Use emojis like 🔄 and 🧭."
asking_clarifying_questions:
content_blocks:
- "I see you have some questions. Let's address them. ❓"
ai_feedback:
tokens_for_ai: "Answer the student's clarifying questions and provide additional information in a friendly and engaging manner. Use emojis like ❓ and 💬."
- section_id: "section_2"
title: "Key Concepts of The GNU Manifesto"
steps:
- step_id: "step_1"
title: "What is GNU?"
content_blocks:
- "GNU stands for 'Gnu's Not Unix' and is a free Unix-compatible software system."
- "Richard Stallman and other volunteers are developing GNU to provide a free alternative to proprietary Unix systems."
- "Think about why it might be important for GNU to be compatible with Unix. Consider aspects like user familiarity, software compatibility, and ease of adoption."
tokens_for_ai: "Guide the student to think about the importance of GNU being compatible with Unix. If any part of the user's answer is correct and on-topic, categorize it as 'correct'."
question: "Why do you think it is important for GNU to be compatible with Unix? 🤔"
buckets:
- correct
- partial_understanding
- off_topic
- asking_clarifying_questions
transitions:
correct:
content_blocks:
- "Great! You understand the importance of GNU being compatible with Unix. 🎉"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and encourage the student to continue learning. Use emojis like 👍 and 🌟."
partial_understanding:
content_blocks:
- "You have a partial understanding. Let's clarify a few points. 🤔"
ai_feedback:
tokens_for_ai: "Provide additional information to clarify the student's understanding in a friendly and supportive manner. Use emojis like 🤔 and 📚."
off_topic:
content_blocks:
- "It seems like your response is off-topic. Let's try to stay focused on the importance of GNU being compatible with Unix. 🔄"
ai_feedback:
tokens_for_ai: "Gently guide the student back to the topic of the importance of GNU being compatible with Unix in a supportive manner. Use emojis like 🔄 and 🧭."
asking_clarifying_questions:
content_blocks:
- "I see you have some questions. Let's address them. ❓"
ai_feedback:
tokens_for_ai: "Answer the student's clarifying questions and provide additional information in a friendly and engaging manner. Use emojis like ❓ and 💬."
- step_id: "step_2"
title: "Why GNU Will Be Free"
content_blocks:
- "GNU is not in the public domain, but it will be free for everyone to use, modify, and redistribute."
- "No distributor will be allowed to restrict its further redistribution, ensuring that all versions of GNU remain free."
- "Think about why it might be important for GNU to remain free. Consider aspects like user rights, collaboration, and innovation."
tokens_for_ai: "Guide the student to think about the importance of GNU remaining free. If any part of the user's answer is correct and on-topic, categorize it as 'correct'."
question: "Why do you think it is important for GNU to remain free? 🤔"
buckets:
- correct
- partial_understanding
- off_topic
- asking_clarifying_questions
transitions:
correct:
content_blocks:
- "Excellent! You understand the importance of GNU remaining free. 🎉"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and encourage the student to continue learning. Use emojis like 👍 and 🌟."
partial_understanding:
content_blocks:
- "You have a partial understanding. Let's clarify a few points. 🤔"
ai_feedback:
tokens_for_ai: "Provide additional information to clarify the student's understanding in a friendly and supportive manner. Use emojis like 🤔 and 📚."
off_topic:
content_blocks:
- "It seems like your response is off-topic. Let's try to stay focused on the importance of GNU remaining free. 🔄"
ai_feedback:
tokens_for_ai: "Gently guide the student back to the topic of the importance of GNU remaining free in a supportive manner. Use emojis like 🔄 and 🧭."
asking_clarifying_questions:
content_blocks:
- "I see you have some questions. Let's address them. ❓"
ai_feedback:
tokens_for_ai: "Answer the student's clarifying questions and provide additional information in a friendly and engaging manner. Use emojis like ❓ and 💬."
- section_id: "section_3"
title: "Contributing to GNU"
steps:
- step_id: "step_1"
title: "How to Contribute"
content_blocks:
- "There are many ways to contribute to the GNU Project, including donating money, programs, and work."
- "Think about why it might be important for people to contribute to the GNU Project. Consider aspects like community, collaboration, and shared goals."
tokens_for_ai: "Guide the student to think about the importance of contributing to the GNU Project. If any part of the user's answer is correct and on-topic, categorize it as 'correct'."
question: "Why do you think it is important for people to contribute to the GNU Project? 🤔"
buckets:
- correct
- partial_understanding
- off_topic
- asking_clarifying_questions
transitions:
correct:
content_blocks:
- "Great! You understand the importance of contributing to the GNU Project. 🎉"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and encourage the student to continue learning. Use emojis like 👍 and 🌟."
partial_understanding:
content_blocks:
- "You have a partial understanding. Let's clarify a few points. 🤔"
ai_feedback:
tokens_for_ai: "Provide additional information to clarify the student's understanding in a friendly and supportive manner. Use emojis like 🤔 and 📚."
off_topic:
content_blocks:
- "It seems like your response is off-topic. Let's try to stay focused on the importance of contributing to the GNU Project. 🔄"
ai_feedback:
tokens_for_ai: "Gently guide the student back to the topic of the importance of contributing to the GNU Project in a supportive manner. Use emojis like 🔄 and 🧭."
asking_clarifying_questions:
content_blocks:
- "I see you have some questions. Let's address them. ❓"
ai_feedback:
tokens_for_ai: "Answer the student's clarifying questions and provide additional information in a friendly and engaging manner. Use emojis like ❓ and 💬."
- step_id: "step_2"
title: "Ways to Contribute"
content_blocks:
- "You can contribute to the GNU Project by writing code, fixing bugs, improving documentation, and more."
- "Think about how your skills and interests might align with the needs of the GNU Project. How can you make a meaningful contribution?"
tokens_for_ai: "Guide the student to think about how they can contribute to the GNU Project based on their skills and interests. If any part of the user's answer is correct and on-topic, categorize it as 'correct'."
question: "How do you think you can contribute to the GNU Project based on your skills and interests? 🤔"
buckets:
- correct
- partial_understanding
- off_topic
- asking_clarifying_questions
transitions:
correct:
content_blocks:
- "Excellent! You have a good idea of how you can contribute to the GNU Project. 🎉"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and encourage the student to continue learning. Use emojis like 👍 and 🌟."
partial_understanding:
content_blocks:
- "You have a partial understanding. Let's clarify a few points. 🤔"
ai_feedback:
tokens_for_ai: "Provide additional information to clarify the student's understanding in a friendly and supportive manner. Use emojis like 🤔 and 📚."
off_topic:
content_blocks:
- "It seems like your response is off-topic. Let's try to stay focused on how you can contribute to the GNU Project. 🔄"
ai_feedback:
tokens_for_ai: "Gently guide the student back to the topic of how they can contribute to the GNU Project in a supportive manner. Use emojis like 🔄 and 🧭."
asking_clarifying_questions:
content_blocks:
- "I see you have some questions. Let's address them. ❓"
ai_feedback:
tokens_for_ai: "Answer the student's clarifying questions and provide additional information in a friendly and engaging manner. Use emojis like ❓ and 💬."
- section_id: "section_4"
title: "Legacy of The GNU Manifesto"
steps:
- step_id: "step_1"
title: "Impact on Software Development"
content_blocks:
- "The GNU Manifesto has had a profound impact on software development, promoting the principles of free software and user rights."
- "Think about how the principles of the GNU Manifesto might have influenced modern software development practices. Consider aspects like open source, collaboration, and innovation."
tokens_for_ai: "Guide the student to think about the impact of the GNU Manifesto on modern software development. If any part of the user's answer is correct and on-topic, categorize it as 'correct'."
question: "How do you think the principles of the GNU Manifesto have influenced modern software development practices? 🤔"
buckets:
- correct
- partial_understanding
- off_topic
- asking_clarifying_questions
transitions:
correct:
content_blocks:
- "Great! You understand the impact of the GNU Manifesto on modern software development. 🎉"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and encourage the student to continue learning. Use emojis like 👍 and 🌟."
partial_understanding:
content_blocks:
- "You have a partial understanding. Let's clarify a few points. 🤔"
ai_feedback:
tokens_for_ai: "Provide additional information to clarify the student's understanding in a friendly and supportive manner. Use emojis like 🤔 and 📚."
off_topic:
content_blocks:
- "It seems like your response is off-topic. Let's try to stay focused on the impact of the GNU Manifesto. 🔄"
ai_feedback:
tokens_for_ai: "Gently guide the student back to the topic of the impact of the GNU Manifesto in a supportive manner. Use emojis like 🔄 and 🧭."
asking_clarifying_questions:
content_blocks:
- "I see you have some questions. Let's address them. ❓"
ai_feedback:
tokens_for_ai: "Answer the student's clarifying questions and provide additional information in a friendly and engaging manner. Use emojis like ❓ and 💬."
- step_id: "step_2"
title: "Future of Free Software"
content_blocks:
- "The principles of the GNU Manifesto continue to inspire the Free Software Movement and the development of free software."
- "Think about how the principles of free software might shape the future of technology. Consider aspects like user rights, innovation, and collaboration."
tokens_for_ai: "Guide the student to think about the future of free software and its impact on technology. If any part of the user's answer is correct and on-topic, categorize it as 'correct'."
question: "How do you think the principles of free software will shape the future of technology? 🤔"
buckets:
- correct
- partial_understanding
- off_topic
- asking_clarifying_questions
transitions:
correct:
content_blocks:
- "Excellent! You understand how the principles of free software might shape the future of technology. 🎉"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and encourage the student to continue learning. Use emojis like 👍 and 🌟."
partial_understanding:
content_blocks:
- "You have a partial understanding. Let's clarify a few points. 🤔"
ai_feedback:
tokens_for_ai: "Provide additional information to clarify the student's understanding in a friendly and supportive manner. Use emojis like 🤔 and 📚."
off_topic:
content_blocks:
- "It seems like your response is off-topic. Let's try to stay focused on the future of free software. 🔄"
ai_feedback:
tokens_for_ai: "Gently guide the student back to the topic of the future of free software in a supportive manner. Use emojis like 🔄 and 🧭."
asking_clarifying_questions:
content_blocks:
- "I see you have some questions. Let's address them. ❓"
ai_feedback:
tokens_for_ai: "Answer the student's clarifying questions and provide additional information in a friendly and engaging manner. Use emojis like ❓ and 💬."
- section_id: "section_5"
title: "Congratulations!"
steps:
- step_id: "step_1"
title: "Well Done!"
content_blocks:
- "Congratulations on completing the GNU Manifesto course! 🎉"
- "You have learned about the key concepts, principles, and impact of the GNU Manifesto."
- "This knowledge will help you understand the importance of software freedom and the Free Software Movement."
- "We are proud of your dedication and hard work. Well done! 🌟"

View file

@ -0,0 +1,367 @@
default_max_attempts_per_step: 3
tokens_for_ai_rubric: "You are a master storyteller. Your task is to create a coherent and engaging story based on the following chat history. The story should seamlessly integrate the user's responses and the AI's feedback, ensuring that the narrative flows naturally. Pay special attention to the user's choices and how they shape the story. Use descriptive language to bring the scenes to life and make the story immersive. The story should have a clear beginning, middle, and end, reflecting the user's journey and the outcomes of their decisions. Here is the chat history.
sections:
- section_id: "section_1"
title: "The Adventure Begins"
steps:
- step_id: "step_1"
title: "Setting the Scene"
content_blocks:
- "Welcome to the Story Builder game! 🌟"
- "You are about to embark on an exciting adventure. Your choices will shape the story."
- "Let's begin by setting the scene. Imagine you are in a dense forest, and you come across a fork in the path."
- "To the left, the path leads deeper into the forest, where you hear the sound of a flowing river. To the right, the path leads to a clearing with a mysterious glowing light."
tokens_for_ai: "Guide the user to make a choice between the two paths. Provide feedback based on their choice."
question: "Which path do you choose? Left (forest) or Right (clearing)? 🤔"
buckets:
- left_forest
- right_clearing
- off_topic
- asking_clarifying_questions
transitions:
left_forest:
content_blocks:
- "You chose to go left, deeper into the forest. 🌲"
- "As you walk, the sound of the river grows louder. You soon find yourself at the edge of a beautiful, sparkling river."
- "You notice a small boat tied to a tree. Do you take the boat and explore the river, or do you follow the riverbank on foot?"
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 🌟."
right_clearing:
content_blocks:
- "You chose to go right, towards the clearing. 🌟"
- "As you approach the clearing, the glowing light becomes brighter. You find a magical portal shimmering in the air."
- "Do you step through the portal to see where it leads, or do you stay and explore the clearing?"
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 🌟."
off_topic:
content_blocks:
- "It seems like your response is off-topic. Let's try to stay focused on the story. 🔄"
ai_feedback:
tokens_for_ai: "Gently guide the user back to the story in a supportive manner. Use emojis like 🔄 and 🧭."
asking_clarifying_questions:
content_blocks:
- "I see you have some questions. Let's address them. ❓"
ai_feedback:
tokens_for_ai: "Answer the user's clarifying questions and provide additional information in a friendly and engaging manner. Use emojis like ❓ and 💬."
- section_id: "section_2"
title: "The Forest Path"
steps:
- step_id: "step_1"
title: "Encounter at the River"
content_blocks:
- "You chose to go left, deeper into the forest. 🌲"
- "As you walk, the sound of the river grows louder. You soon find yourself at the edge of a beautiful, sparkling river."
- "You notice a small boat tied to a tree. Do you take the boat and explore the river, or do you follow the riverbank on foot?"
tokens_for_ai: "Guide the user to make a choice between taking the boat or following the riverbank. Provide feedback based on their choice."
question: "What do you choose? Take the boat or Follow the riverbank? 🤔"
buckets:
- take_boat
- follow_riverbank
- off_topic
- asking_clarifying_questions
transitions:
take_boat:
content_blocks:
- "You chose to take the boat and explore the river. 🚣"
- "As you paddle down the river, you encounter a group of friendly forest creatures who offer to guide you to a hidden treasure."
- "Congratulations! You have discovered a hidden treasure with the help of your new friends. 🎉"
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. Use emojis like 👍 and 🌟."
follow_riverbank:
content_blocks:
- "You chose to follow the riverbank on foot. 🌲"
- "As you walk along the river, you find a hidden cave entrance. Inside, you discover ancient artifacts and a map to a secret location."
- "Congratulations! You have discovered ancient artifacts and a secret map. 🎉"
next_section_and_step: "section_5:step_1"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and guide the user to make the next choice. Use emojis like 👍 and 🌟."
off_topic:
content_blocks:
- "It seems like your response is off-topic. Let's try to stay focused on the story. 🔄"
ai_feedback:
tokens_for_ai: "Gently guide the user back to the story in a supportive manner. Use emojis like 🔄 and 🧭."
asking_clarifying_questions:
content_blocks:
- "I see you have some questions. Let's address them. ❓"
ai_feedback:
tokens_for_ai: "Answer the user's clarifying questions and provide additional information in a friendly and engaging manner. Use emojis like ❓ and 💬."
- section_id: "section_3"
title: "The Clearing Path"
steps:
- step_id: "step_1"
title: "The Magical Portal"
content_blocks:
- "You chose to go right, towards the clearing. 🌟"
- "As you approach the clearing, the glowing light becomes brighter. You find a magical portal shimmering in the air."
- "Do you step through the portal to see where it leads, or do you stay and explore the clearing?"
tokens_for_ai: "Guide the user to make a choice between stepping through the portal or exploring the clearing. Provide feedback based on their choice."
question: "What do you choose? Step through the portal or Explore the clearing? 🤔"
buckets:
- step_through_portal
- explore_clearing
- off_topic
- asking_clarifying_questions
transitions:
step_through_portal:
content_blocks:
- "You chose to step through the portal. 🌟"
- "You find yourself in a magical realm filled with wonders and mysteries. A wise old wizard offers to teach you powerful spells."
- "Congratulations! You have entered a magical realm and begun your training as a wizard. 🎉"
next_section_and_step: "section_6:step_1"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and guide the user to make the next choice. Use emojis like 👍 and 🌟."
explore_clearing:
content_blocks:
- "You chose to explore the clearing. 🌲"
- "You find a hidden garden filled with rare and beautiful plants. A friendly gardener offers to share their knowledge with you."
- "Congratulations! You have discovered a hidden garden and gained valuable knowledge. 🎉"
next_section_and_step: "section_7:step_1"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and guide the user to make the next choice. Use emojis like 👍 and 🌟."
off_topic:
content_blocks:
- "It seems like your response is off-topic. Let's try to stay focused on the story. 🔄"
ai_feedback:
tokens_for_ai: "Gently guide the user back to the story in a supportive manner. Use emojis like 🔄 and 🧭."
asking_clarifying_questions:
content_blocks:
- "I see you have some questions. Let's address them. ❓"
ai_feedback:
tokens_for_ai: "Answer the user's clarifying questions and provide additional information in a friendly and engaging manner. Use emojis like ❓ and 💬."
- section_id: "section_4"
title: "The Boat Adventure"
steps:
- step_id: "step_1"
title: "The Hidden Treasure"
content_blocks:
- "You chose to take the boat and explore the river. 🚣"
- "As you paddle down the river, you encounter a group of friendly forest creatures who offer to guide you to a hidden treasure."
- "You find the hidden treasure chest. Do you open the treasure or leave it?"
tokens_for_ai: "Guide the user to make a choice between opening the treasure or leaving it. Provide feedback based on their choice."
question: "What do you choose? Open the treasure or Leave it? 🤔"
buckets:
- open_treasure
- leave_treasure
- off_topic
- asking_clarifying_questions
transitions:
open_treasure:
content_blocks:
- "You chose to open the treasure. 🎉"
- "Inside, you find gold coins, precious gems, and a magical artifact that grants you a special power."
- "Congratulations! You have discovered a hidden treasure and gained a special power. 🎉"
next_section_and_step: "section_8:step_1"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and guide the user to the final encounter. Use emojis like 👍 and 🌟."
leave_treasure:
content_blocks:
- "You chose to leave the treasure. 🌲"
- "You decide that the adventure itself is the real treasure and continue your journey with a sense of fulfillment."
- "Congratulations! You have completed the adventure with a sense of fulfillment. 🎉"
next_section_and_step: "section_8:step_1"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and guide the user to the final encounter. Use emojis like 👍 and 🌟."
off_topic:
content_blocks:
- "It seems like your response is off-topic. Let's try to stay focused on the story. 🔄"
ai_feedback:
tokens_for_ai: "Gently guide the user back to the story in a supportive manner. Use emojis like 🔄 and 🧭."
asking_clarifying_questions:
content_blocks:
- "I see you have some questions. Let's address them. ❓"
ai_feedback:
tokens_for_ai: "Answer the user's clarifying questions and provide additional information in a friendly and engaging manner. Use emojis like ❓ and 💬."
- section_id: "section_5"
title: "The Riverbank Adventure"
steps:
- step_id: "step_1"
title: "The Hidden Cave"
content_blocks:
- "You chose to follow the riverbank on foot. 🌲"
- "As you walk along the river, you find a hidden cave entrance. Inside, you discover ancient artifacts and a map to a secret location."
- "Do you enter the cave or continue walking along the riverbank?"
tokens_for_ai: "Guide the user to make a choice between entering the cave or continuing to walk. Provide feedback based on their choice."
question: "What do you choose? Enter the cave or Continue walking? 🤔"
buckets:
- enter_cave
- continue_walking
- off_topic
- asking_clarifying_questions
transitions:
enter_cave:
content_blocks:
- "You chose to enter the cave. 🌲"
- "Inside, you find ancient artifacts and a map to a secret location. You feel a sense of discovery and excitement."
- "Congratulations! You have discovered ancient artifacts and a secret map. 🎉"
next_section_and_step: "section_8:step_1"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and guide the user to the final encounter. Use emojis like 👍 and 🌟."
continue_walking:
content_blocks:
- "You chose to continue walking along the riverbank. 🌲"
- "As you walk, you find a beautiful waterfall and a hidden path leading to a secret garden."
- "Congratulations! You have discovered a hidden garden and gained valuable knowledge. 🎉"
next_section_and_step: "section_8:step_1"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and guide the user to the final encounter. Use emojis like 👍 and 🌟."
off_topic:
content_blocks:
- "It seems like your response is off-topic. Let's try to stay focused on the story. 🔄"
ai_feedback:
tokens_for_ai: "Gently guide the user back to the story in a supportive manner. Use emojis like 🔄 and 🧭."
asking_clarifying_questions:
content_blocks:
- "I see you have some questions. Let's address them. ❓"
ai_feedback:
tokens_for_ai: "Answer the user's clarifying questions and provide additional information in a friendly and engaging manner. Use emojis like ❓ and 💬."
- section_id: "section_6"
title: "The Portal Adventure"
steps:
- step_id: "step_1"
title: "The Magical Realm"
content_blocks:
- "You chose to step through the portal. 🌟"
- "You find yourself in a magical realm filled with wonders and mysteries. A wise old wizard offers to teach you powerful spells."
- "Do you learn spells from the wizard or explore the magical realm on your own?"
tokens_for_ai: "Guide the user to make a choice between learning spells or exploring the realm. Provide feedback based on their choice."
question: "What do you choose? Learn spells or Explore the realm? 🤔"
buckets:
- learn_spells
- explore_realm
- off_topic
- asking_clarifying_questions
transitions:
learn_spells:
content_blocks:
- "You chose to learn spells from the wizard. 🌟"
- "The wizard teaches you powerful spells that grant you special abilities. You feel a sense of empowerment and wonder."
- "Congratulations! You have learned powerful spells and gained special abilities. 🎉"
next_section_and_step: "section_8:step_1"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and guide the user to the final encounter. Use emojis like 👍 and 🌟."
explore_realm:
content_blocks:
- "You chose to explore the magical realm on your own. 🌟"
- "As you explore, you discover hidden treasures and magical creatures. You feel a sense of adventure and excitement."
- "Congratulations! You have discovered hidden treasures and magical creatures. 🎉"
next_section_and_step: "section_8:step_1"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and guide the user to the final encounter. Use emojis like 👍 and 🌟."
off_topic:
content_blocks:
- "It seems like your response is off-topic. Let's try to stay focused on the story. 🔄"
ai_feedback:
tokens_for_ai: "Gently guide the user back to the story in a supportive manner. Use emojis like 🔄 and 🧭."
asking_clarifying_questions:
content_blocks:
- "I see you have some questions. Let's address them. ❓"
ai_feedback:
tokens_for_ai: "Answer the user's clarifying questions and provide additional information in a friendly and engaging manner. Use emojis like ❓ and 💬."
- section_id: "section_7"
title: "The Clearing Adventure"
steps:
- step_id: "step_1"
title: "The Hidden Garden"
content_blocks:
- "You chose to explore the clearing. 🌲"
- "You find a hidden garden filled with rare and beautiful plants. A friendly gardener offers to share their knowledge with you."
- "Do you talk to the gardener or explore the garden on your own?"
tokens_for_ai: "Guide the user to make a choice between talking to the gardener or exploring the garden. Provide feedback based on their choice."
question: "What do you choose? Talk to the gardener or Explore the garden? 🤔"
buckets:
- talk_gardener
- explore_garden
- off_topic
- asking_clarifying_questions
transitions:
talk_gardener:
content_blocks:
- "You chose to talk to the gardener. 🌲"
- "The gardener shares their knowledge of rare plants and their magical properties. You feel a sense of wonder and curiosity."
- "Congratulations! You have gained valuable knowledge about rare plants and their magical properties. 🎉"
next_section_and_step: "section_8:step_1"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and guide the user to the final encounter. Use emojis like 👍 and 🌟."
explore_garden:
content_blocks:
- "You chose to explore the garden on your own. 🌲"
- "As you explore, you discover hidden paths and secret areas filled with rare plants and magical creatures. You feel a sense of adventure and excitement."
- "Congratulations! You have discovered hidden paths and secret areas in the garden. 🎉"
next_section_and_step: "section_8:step_1"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and guide the user to the final encounter. Use emojis like 👍 and 🌟."
off_topic:
content_blocks:
- "It seems like your response is off-topic. Let's try to stay focused on the story. 🔄"
ai_feedback:
tokens_for_ai: "Gently guide the user back to the story in a supportive manner. Use emojis like 🔄 and 🧭."
asking_clarifying_questions:
content_blocks:
- "I see you have some questions. Let's address them. ❓"
ai_feedback:
tokens_for_ai: "Answer the user's clarifying questions and provide additional information in a friendly and engaging manner. Use emojis like ❓ and 💬."
- section_id: "section_8"
title: "The Final Choices"
steps:
- step_id: "step_1"
title: "The Final Encounter"
content_blocks:
- "You have reached the final part of your adventure. Your choices have led you to this moment."
- "You are presented with a final choice: accept a reward for your journey or decline it and continue your adventure."
- "Think about what you have learned and experienced. What will you choose?"
tokens_for_ai: "Guide the user to make a final choice between accepting the reward or declining it. Provide feedback based on their choice."
question: "What do you choose? Accept the reward or Decline the reward? 🤔"
buckets:
- accept_reward
- decline_reward
- off_topic
- asking_clarifying_questions
transitions:
accept_reward:
content_blocks:
- "You chose to accept the reward. 🎉"
- "You are given a magical artifact that grants you special powers and a sense of accomplishment."
- "Congratulations! You have completed your adventure and received a magical reward. 🎉"
next_section_and_step: "section_9:step_1"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and conclude the story. Use emojis like 👍 and 🌟."
decline_reward:
content_blocks:
- "You chose to decline the reward. 🌲"
- "You decide that the journey itself was the true reward and continue your adventure with a sense of fulfillment."
- "Congratulations! You have completed your adventure with a sense of fulfillment. 🎉"
next_section_and_step: "section_9:step_1"
ai_feedback:
tokens_for_ai: "Provide positive reinforcement and conclude the story. Use emojis like 👍 and 🌟."
off_topic:
content_blocks:
- "It seems like your response is off-topic. Let's try to stay focused on the story. 🔄"
ai_feedback:
tokens_for_ai: "Gently guide the user back to the story in a supportive manner. Use emojis like 🔄 and 🧭."
asking_clarifying_questions:
content_blocks:
- "I see you have some questions. Let's address them. ❓"
ai_feedback:
tokens_for_ai: "Answer the user's clarifying questions and provide additional information in a friendly and engaging manner. Use emojis like ❓ and 💬."
- section_id: "section_9"
title: "Congratulations!"
steps:
- step_id: "step_1"
title: "Well Done!"
content_blocks:
- "Congratulations on completing the Story Builder game! 🎉"
- "You have made choices that shaped an exciting adventure."
- "We hope you enjoyed the journey and the story you helped create."
- "We are proud of your creativity and imagination. Well done! 🌟"

View file

@ -90,7 +90,8 @@ def provide_feedback(
)
feedback += f"\n\nAI Feedback: {ai_feedback}"
return feedback
next_section_and_step = transition.get("next_section_and_step", None)
return feedback, next_section_and_step
# Simulate the activity
@ -98,49 +99,85 @@ def simulate_activity(yaml_file_path):
yaml_content = load_yaml_activity(yaml_file_path)
max_attempts = yaml_content.get("default_max_attempts_per_step", 3)
for section in yaml_content["sections"]:
print(f"\nSection: {section['title']}\n")
for step in section["steps"]:
# Print all content blocks once per step
if "content_blocks" in step:
for block in step["content_blocks"]:
print(block)
current_section_index = 0
current_step_index = 0
while current_section_index < len(yaml_content["sections"]):
section = yaml_content["sections"][current_section_index]
if current_step_index >= len(section["steps"]):
current_section_index += 1
current_step_index = 0
continue
step = section["steps"][current_step_index]
# Print all content blocks once per step
if "content_blocks" in step:
for block in step["content_blocks"]:
print(block)
if "question" in step:
question = step["question"]
else:
# Skip classification and feedback if there's no question
current_step_index += 1
continue
attempts = 0
while attempts < max_attempts:
if "question" in step:
question = step["question"]
else:
# Skip classification and feedback if there's no question
continue
print(f"\nQuestion: {question}")
attempts = 0
while attempts < max_attempts:
if "question" in step:
print(f"\nQuestion: {question}")
user_response = input("\nYour Response: ")
user_response = input("\nYour Response: ")
category = categorize_response(
question, user_response, step["buckets"], step["tokens_for_ai"]
)
print(f"\nCategory: {category}")
category = categorize_response(
question, user_response, step["buckets"], step["tokens_for_ai"]
)
print(f"\nCategory: {category}")
feedback, next_section_and_step = provide_feedback(
yaml_content,
section["section_id"],
step["step_id"],
category,
question,
user_response,
)
print(f"\nFeedback: {feedback}")
feedback = provide_feedback(
yaml_content,
section["section_id"],
step["step_id"],
category,
question,
user_response,
)
print(f"\nFeedback: {feedback}")
if category not in [
"off_topic",
"asking_clarifying_questions",
"partial_understanding",
]:
break
if category == "correct":
break
attempts += 1
attempts += 1
if attempts == max_attempts:
print("\nMaximum attempts reached. Moving to the next step.")
if attempts == max_attempts:
print("\nMaximum attempts reached. Moving to the next step.")
if next_section_and_step:
current_section_id, current_step_id = next_section_and_step.split(":")
current_section_index = next(
(
index
for index, s in enumerate(yaml_content["sections"])
if s["section_id"] == current_section_id
),
current_section_index,
)
current_step_index = next(
(
index
for index, s in enumerate(section["steps"])
if s["step_id"] == current_step_id
),
current_step_index,
)
else:
current_step_index += 1
if __name__ == "__main__":
simulate_activity("activity12.yaml")
#simulate_activity("activity13-choose-adventure.yaml")
simulate_activity("activity0.yaml")