diff --git a/app.py b/app.py index 8d722d8..85abb25 100644 --- a/app.py +++ b/app.py @@ -2018,24 +2018,26 @@ def handle_activity_response(room_name, user_response, username): category, step["question"], user_response, + username, ) # Store and emit the feedback - new_message = Message( - username="System", content=feedback, room_id=room.id - ) - db.session.add(new_message) - db.session.commit() + if feedback: + new_message = Message( + username="System", content=feedback, room_id=room.id + ) + db.session.add(new_message) + db.session.commit() - socketio.emit( - "message", - { - "id": new_message.id, - "username": "System", - "content": feedback, - }, - room=room_name, - ) + socketio.emit( + "message", + { + "id": new_message.id, + "username": "System", + "content": feedback, + }, + room=room_name, + ) # Emit the transition content blocks if they exist if "content_blocks" in step["transitions"][category]: @@ -2325,7 +2327,7 @@ def categorize_response(question, response, buckets, tokens_for_ai): # Generate AI feedback -def generate_ai_feedback(category, question, user_response, tokens_for_ai): +def generate_ai_feedback(category, question, user_response, tokens_for_ai, username): openai_client, model_name = get_openai_client_and_model() messages = [ { @@ -2334,7 +2336,7 @@ def generate_ai_feedback(category, question, user_response, tokens_for_ai): }, { "role": "user", - "content": f"Question: {question}\nResponse: {user_response}\nCategory: {category}", + "content": f"Username: {username}\nQuestion: {question}\nResponse: {user_response}\nCategory: {category}", }, ] @@ -2349,7 +2351,7 @@ def generate_ai_feedback(category, question, user_response, tokens_for_ai): def provide_feedback( - yaml_content, section_id, step_id, category, question, user_response + yaml_content, section_id, step_id, category, question, user_response, username ): section = next( (s for s in yaml_content["sections"] if s["section_id"] == section_id), None @@ -2371,7 +2373,7 @@ def provide_feedback( step["tokens_for_ai"] + " " + transition["ai_feedback"]["tokens_for_ai"] ) ai_feedback = generate_ai_feedback( - category, question, user_response, tokens_for_ai + category, question, user_response, tokens_for_ai, username ) feedback += f"\n\nAI Feedback: {ai_feedback}" diff --git a/research/activity15-choose-adventure.yaml b/research/activity15-choose-adventure.yaml index 1789648..8a77ba0 100644 --- a/research/activity15-choose-adventure.yaml +++ b/research/activity15-choose-adventure.yaml @@ -17,10 +17,9 @@ sections: 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?" - tokens_for_ai: "Guide the user to make a choice between looking under the rug, examining the book, trying to open the safe, or trying to leave the room. Provide feedback based on their choice. Use off_topic sparringly if the response choice doesn't fit any other topic. Be flexible to classify actions that lead to finding hidden items." - question: "What do you choose? Look under the rug, Examine the book, Try to open the safe, or Try to leave the room? ๐Ÿค”" + - "There is also an exit door, but it seems to be locked." + tokens_for_ai: "Guide the user to make a choice between looking under the rug, examining the book, trying to open the safe, or trying to leave the room. Use off_topic sparringly if the response choice doesn't fit any other topic." + question: "What do you do? Look under the rug, Examine the book, Try to open the safe, or Try to leave the room? ๐Ÿค”" buckets: - look_under_rug - examine_book @@ -30,19 +29,9 @@ sections: - off_topic transitions: look_under_rug: - content_blocks: - - "You chose to look under the rug. ๐Ÿงบ" - - "You find something hidden under the rug." 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. Be flexible to classify actions that lead to finding hidden items. Use emojis like ๐Ÿ‘ and ๐ŸŒŸ." examine_book: - content_blocks: - - "You chose to examine the book. ๐Ÿ“–" - - "The book contains something interesting." 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. Be flexible to classify actions that lead to finding hidden items. Use emojis like ๐Ÿ‘ and ๐ŸŒŸ." try_open_safe: next_section_and_step: "section_4:step_1" @@ -57,13 +46,9 @@ sections: ai_feedback: tokens_for_ai: "The user has exited with the exit_key! The game is over, 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 ๐Ÿ’ฌ." @@ -75,7 +60,6 @@ sections: content_blocks: - "You chose to look under the rug. ๐Ÿงบ" - "You find a key hidden under the rug." - - "Do you take the key or continue exploring the room?" tokens_for_ai: "Guide the user to make a choice between taking the key or continuing to explore the room. Be flexible to classify actions that lead to finding hidden items. Use off_topic sparringly if the response choice doesn't fit any other topic. Provide feedback based on their choice." question: "What do you choose? Take the key or Continue exploring? ๐Ÿค”" buckets: @@ -90,8 +74,6 @@ sections: content_blocks: - "You chose to take the key. ๐Ÿ”‘" 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 ๐ŸŒŸ." metadata_updates: key: true continue_exploring: @@ -100,9 +82,10 @@ sections: content_blocks: - "You chose to take a closer look under the rug. ๐Ÿงบ" - "You find a small, mysterious coin with strange engravings." + - "You now have the coin!" 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 ๐ŸŒŸ." + tokens_for_ai: "The player found a hidden coin. Congratulate them by name with your feedback. Use emojis like ๐Ÿ‘ and ๐ŸŒŸ." metadata_updates: coin: true go_back: @@ -115,8 +98,6 @@ sections: 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 ๐Ÿ’ฌ." @@ -128,7 +109,6 @@ sections: content_blocks: - "You chose to examine the book. ๐Ÿ“–" - "The book contains a note with a password: 'ESCAPE123'." - - "Do you take note of the password or continue exploring the room?" tokens_for_ai: "Guide the user to make a choice between taking note of the password or continuing to explore the room. Be flexible to classify actions that lead to finding hidden items. Use off_topic sparringly if the response choice doesn't fit any other topic. Provide feedback based on their choice." question: "What do you choose? Take note of the password or Continue exploring? ๐Ÿค”" buckets: @@ -143,8 +123,6 @@ sections: content_blocks: - "You chose to take note of the password. ๐Ÿ”‘" 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 ๐ŸŒŸ." metadata_updates: password: true continue_exploring: @@ -153,9 +131,10 @@ sections: content_blocks: - "You chose to take a closer look at the book. ๐Ÿ“–" - "You find a small, folded piece of paper with a cryptic message." + - "You take the paper!" 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 ๐ŸŒŸ." + 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: paper: true go_back: @@ -163,13 +142,9 @@ 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 ๐ŸŒŸ." 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 ๐Ÿ’ฌ." @@ -181,9 +156,8 @@ sections: content_blocks: - "You chose to try to open the safe. ๐Ÿ”’" - "The safe is locked and requires both a key and a password to open." - - "Do you use the key and enter the password to open the safe or continue exploring the room?" tokens_for_ai: "Guide the user to make a choice between using the key and entering the password to open the safe or continuing to explore the room. Be flexible to classify actions that lead to finding hidden items. Use off_topic sparringly if the response choice doesn't fit any other topic. Provide feedback based on their choice." - question: "What do you choose? Use the key and enter the password or Continue exploring? ๐Ÿค”" + question: "What do you do? Use the key and enter the password or Continue exploring? ๐Ÿค”" buckets: - use_key_and_password - continue_exploring @@ -220,13 +194,9 @@ sections: 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 ๐ŸŒŸ." 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 ๐Ÿ’ฌ." @@ -239,9 +209,8 @@ sections: - "You chose to use the coin to open the compartment. ๐Ÿช™" - "The compartment opens, revealing a second, smaller safe." - "This safe requires a combination to open." - - "Do you try to solve the combination or leave it alone?" tokens_for_ai: "Guide the user to make a choice between solving the combination to open the second safe or leaving it alone. Be flexible to classify actions that lead to finding hidden items. Use off_topic sparringly if the response choice doesn't fit any other topic. Provide feedback based on their choice." - question: "What do you choose? Solve the combination or Leave it alone? ๐Ÿค”" + question: "Do you try to solve the combination or leave it alone? ๐Ÿค”" buckets: - solve_combination - leave_it_alone @@ -259,7 +228,7 @@ sections: - "Congratulations! You have found the ultimate secret and a new adventure awaits. ๐ŸŽ‰" next_section_and_step: "section_1: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 ๐ŸŒŸ." + tokens_for_ai: "Congratulate the player by name for finding ultimate secret. Use emojis like ๐Ÿ‘ and ๐ŸŒŸ." leave_it_alone: next_section_and_step: "section_1:step_1" ai_feedback: @@ -269,13 +238,9 @@ 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 ๐ŸŒŸ." 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 ๐Ÿ’ฌ."