From 602039ca71b6600de8e017795ac63029d597dc3f Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Sun, 28 Jul 2024 20:37:31 -0400 Subject: [PATCH] play tested and working modified: app.py --- app.py | 85 +++++++++++++++++++++++++--------------------------------- 1 file changed, 37 insertions(+), 48 deletions(-) diff --git a/app.py b/app.py index 0f3859a..f74afc7 100644 --- a/app.py +++ b/app.py @@ -1955,19 +1955,45 @@ def handle_activity_response(room_name, user_response, username): 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"] - activity_state.attempts = 0 + if next_step: + activity_state.section_id = next_section["section_id"] + activity_state.step_id = next_step["step_id"] + activity_state.attempts = 0 - db.session.add(activity_state) - db.session.commit() + db.session.add(activity_state) + db.session.commit() - # Emit the new step content blocks - content = "\n\n".join(next_step["content_blocks"]) + # Emit the new step content blocks + content = "\n\n".join(next_step["content_blocks"]) + new_message = Message( + username="System", content=content, room_id=room.id + ) + db.session.add(new_message) + db.session.commit() + + socketio.emit( + "message", + { + "id": new_message.id, + "username": "System", + "content": content, + }, + room=room_name, + ) + + # Emit the new question if it exists + if "question" in next_step: + question_content = f"Question: {next_step['question']}" new_message = Message( - username="System", content=content, room_id=room.id + username="System", + content=question_content, + room_id=room.id, ) db.session.add(new_message) db.session.commit() @@ -1977,44 +2003,7 @@ def handle_activity_response(room_name, user_response, username): { "id": new_message.id, "username": "System", - "content": content, - }, - room=room_name, - ) - - # Emit the new question if it exists - if "question" in next_step: - question_content = f"Question: {next_step['question']}" - new_message = Message( - username="System", - content=question_content, - room_id=room.id, - ) - db.session.add(new_message) - db.session.commit() - - socketio.emit( - "message", - { - "id": new_message.id, - "username": "System", - "content": question_content, - }, - room=room_name, - ) - else: - # Display activity info before completing - display_activity_info(room_name, username) - - # Activity completed - db.session.delete(activity_state) - db.session.commit() - socketio.emit( - "message", - { - "id": None, - "username": "System", - "content": "Activity completed!", + "content": question_content, }, room=room_name, ) @@ -2377,7 +2366,7 @@ def provide_feedback( if not transition: return "Category not found.", None - feedback = "\n".join(transition["content_blocks"]) + feedback = "" if "ai_feedback" in transition: tokens_for_ai = ( step["tokens_for_ai"] + " " + transition["ai_feedback"]["tokens_for_ai"]