From 257e5a6a0496f12935266d19070afea2c9afdcbf Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Fri, 2 Aug 2024 18:49:50 -0400 Subject: [PATCH] /activity metadata modified: README.rst modified: app.py modified: research/activity16.yaml --- README.rst | 8 +++++-- app.py | 51 ++++++++++++++++++++++++++++++++++++---- research/activity16.yaml | 32 ++----------------------- 3 files changed, 55 insertions(+), 36 deletions(-) diff --git a/README.rst b/README.rst index 2baa833..1e0a3fb 100644 --- a/README.rst +++ b/README.rst @@ -161,11 +161,15 @@ The server expects to load the YAML file out of the S3 bucket you specify in you ``/activity path-to-activity.yaml`` -2. **Display Activity Info**: Use the ``/activity info`` command to display information about the current activity, including grading and user performance. +2. **Display Activity Info**: Use the ``/activity info`` command to display AI information about the current activity, including grading and user performance. ``/activity info`` -3. **Cancel an Activity**: Use the ``/activity cancel`` command to display cancel the current activity running in the room. +3. **Display Activity Metadata**: Use the ``/activity metadata`` command to display metadata information collected about the activity. + + ``/activity metadata`` + +4. **Cancel an Activity**: Use the ``/activity cancel`` command to display cancel the current activity running in the room. ``/activity cancel`` diff --git a/app.py b/app.py index 835a433..df4b5b5 100644 --- a/app.py +++ b/app.py @@ -322,13 +322,17 @@ def handle_message(data): commands = data["message"].splitlines() for command in commands: + if command.startswith("/activity cancel"): + gevent.spawn(cancel_activity, room_name, data["username"]) + # Exit early since we're canceling the activity + return if command.startswith("/activity info"): gevent.spawn(display_activity_info, room_name, data["username"]) # Exit early since we're displaying activity info return - if command.startswith("/activity cancel"): - gevent.spawn(cancel_activity, room_name, data["username"]) - # Exit early since we're canceling the activity + if command.startswith("/activity metadata"): + gevent.spawn(display_activity_metadata, room_name, data["username"]) + # Exit early since we're displaying activity metadata return if command.startswith("/activity"): s3_file_path = command.split(" ", 1)[1].strip() @@ -1868,6 +1872,45 @@ def cancel_activity(room_name, username): ) +def display_activity_metadata(room_name, username): + with app.app_context(): + room = get_room(room_name) + activity_state = ActivityState.query.filter_by(room_id=room.id).first() + + if not activity_state: + socketio.emit( + "message", + { + "id": None, + "username": "System", + "content": "No active activity found.", + }, + room=room_name, + ) + return + + # Pretty print the metadata + metadata_pretty = json.dumps(activity_state.dict_metadata, indent=2) + + # Store and emit the metadata + metadata_message = f"```\n{metadata_pretty}\n```" + new_message = Message( + username="System", content=metadata_message, room_id=room.id + ) + db.session.add(new_message) + db.session.commit() + + socketio.emit( + "message", + { + "id": new_message.id, + "username": "System", + "content": metadata_message, + }, + room=room_name, + ) + + def handle_activity_response(room_name, user_response, username): with app.app_context(): room = get_room(room_name) @@ -2292,7 +2335,7 @@ def generate_ai_feedback(category, question, user_response, tokens_for_ai): try: print(messages) completion = openai_client.chat.completions.create( - model=model_name, messages=messages, max_tokens=2000, temperature=0.7 + model=model_name, messages=messages, max_tokens=1000, temperature=0.7 ) feedback = completion.choices[0].message.content.strip() return feedback diff --git a/research/activity16.yaml b/research/activity16.yaml index 7cfa961..882171f 100644 --- a/research/activity16.yaml +++ b/research/activity16.yaml @@ -1,7 +1,7 @@ -default_max_attempts_per_step: 3 +default_max_attempts_per_step: 8 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. + Review the conversation and highlight the statements or questions that the user asked and anything they learned. A summary. sections: - section_id: "introduction" @@ -52,13 +52,9 @@ sections: ai_feedback: tokens_for_ai: "Provide positive reinforcement and guide the user to the exit. Use emojis like 👍 and 🌟." off_topic: - content_blocks: - - "It seems like your response is off-topic. Let's try to stay focused on the activity. 🔄" ai_feedback: tokens_for_ai: "Gently guide the user back to the activity 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 with detailed explanations and examples. Provide comprehensive and helpful feedback. Use emojis like ❓ and 💬." @@ -96,13 +92,9 @@ sections: ai_feedback: tokens_for_ai: "Provide supportive feedback and review the basics of Topic 1. Use emojis like 📝 and 🌟." off_topic: - content_blocks: - - "It seems like your response is off-topic. Let's try to stay focused on the lesson. 🔄" ai_feedback: tokens_for_ai: "Gently guide the user back to the lesson 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 with detailed explanations and examples. Provide comprehensive and helpful feedback. Use emojis like ❓ and 💬." @@ -132,13 +124,9 @@ sections: ai_feedback: tokens_for_ai: "Provide supportive feedback and review the advanced concepts of Topic 1. Use emojis like 📝 and 🌟." off_topic: - content_blocks: - - "It seems like your response is off-topic. Let's try to stay focused on the lesson. 🔄" ai_feedback: tokens_for_ai: "Gently guide the user back to the lesson 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 with detailed explanations and examples. Provide comprehensive and helpful feedback. Use emojis like ❓ and 💬." @@ -176,13 +164,9 @@ sections: ai_feedback: tokens_for_ai: "Provide supportive feedback and review the basics of Topic 2. Use emojis like 📝 and 🌟." off_topic: - content_blocks: - - "It seems like your response is off-topic. Let's try to stay focused on the lesson. 🔄" ai_feedback: tokens_for_ai: "Gently guide the user back to the lesson 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 with detailed explanations and examples. Provide comprehensive and helpful feedback. Use emojis like ❓ and 💬." @@ -212,13 +196,9 @@ sections: ai_feedback: tokens_for_ai: "Provide supportive feedback and review the advanced concepts of Topic 2. Use emojis like 📝 and 🌟." off_topic: - content_blocks: - - "It seems like your response is off-topic. Let's try to stay focused on the lesson. 🔄" ai_feedback: tokens_for_ai: "Gently guide the user back to the lesson 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 with detailed explanations and examples. Provide comprehensive and helpful feedback. Use emojis like ❓ and 💬." @@ -256,13 +236,9 @@ sections: ai_feedback: tokens_for_ai: "Provide supportive feedback and review the basics of Topic 3. Use emojis like 📝 and 🌟." off_topic: - content_blocks: - - "It seems like your response is off-topic. Let's try to stay focused on the lesson. 🔄" ai_feedback: tokens_for_ai: "Gently guide the user back to the lesson 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 with detailed explanations and examples. Provide comprehensive and helpful feedback. Use emojis like ❓ and 💬." @@ -292,13 +268,9 @@ sections: ai_feedback: tokens_for_ai: "Provide supportive feedback and review the advanced concepts of Topic 3. Use emojis like 📝 and 🌟." off_topic: - content_blocks: - - "It seems like your response is off-topic. Let's try to stay focused on the lesson. 🔄" ai_feedback: tokens_for_ai: "Gently guide the user back to the lesson 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 with detailed explanations and examples. Provide comprehensive and helpful feedback. Use emojis like ❓ and 💬."