Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- engine/drift.py +18 -6
- engine/responder.py +4 -4
engine/drift.py
CHANGED
|
@@ -92,11 +92,17 @@ def apply_response_effects(state, student_response):
|
|
| 92 |
return state
|
| 93 |
|
| 94 |
|
| 95 |
-
def generate_teaching_note(state, student_response, mode):
|
| 96 |
"""Generate pedagogical feedback based on the literary interaction."""
|
| 97 |
response_lower = student_response.lower()
|
| 98 |
notes = []
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
# Question quality - literary analysis focused
|
| 101 |
if any(word in response_lower for word in ["why did you", "why do you", "why are you"]):
|
| 102 |
notes.append("π **Literary Technique**: 'Why' questions can sound accusatory. Consider using 'what' or 'how' to explore motivations more naturally (e.g., 'What were you thinking when...' or 'How did that moment feel?')")
|
|
@@ -109,7 +115,10 @@ def generate_teaching_note(state, student_response, mode):
|
|
| 109 |
|
| 110 |
# Question depth - connect to literary concepts
|
| 111 |
if len(student_response.split()) < 8:
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
if any(phrase in response_lower for phrase in ["tell me about", "tell me more", "what's that like", "how do you feel"]):
|
| 115 |
notes.append("β
**Strong Question**: Open-ended questions like this encourage the character to reveal subtext, internal conflict, and thematic depth. This is effective literary analysis.")
|
|
@@ -119,7 +128,10 @@ def generate_teaching_note(state, student_response, mode):
|
|
| 119 |
|
| 120 |
# Character engagement - literary context
|
| 121 |
if mode == "triggered" and state.get("trust", 0) < 0.4:
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
if mode == "trusting" and state.get("anxiety", 0) > 0.6:
|
| 125 |
notes.append("β¨ **Key Moment**: The character is vulnerable right now - this is where authors reveal crucial backstory and motivation. Press deeper into their fears and desires.")
|
|
@@ -132,12 +144,12 @@ def generate_teaching_note(state, student_response, mode):
|
|
| 132 |
|
| 133 |
# Add literary context based on specific terms used
|
| 134 |
if any(word in response_lower for word in ["choice", "decision", "decide"]):
|
| 135 |
-
notes.append("π‘ **Theme Connection**: You're exploring agency and choice - a key theme in
|
| 136 |
|
| 137 |
-
if any(word in response_lower for word in ["family", "mother", "father", "parent"]):
|
| 138 |
notes.append("π¨βπ©βπ§ **Family Dynamics**: You're examining how family obligations shape identity - analyze how the author uses familial duty to explore broader social constraints.")
|
| 139 |
|
| 140 |
if not notes:
|
| 141 |
-
notes.append("β
**Good Engagement**: You're exploring the character thoughtfully. Consider connecting their responses to
|
| 142 |
|
| 143 |
return "\n".join(notes)
|
|
|
|
| 92 |
return state
|
| 93 |
|
| 94 |
|
| 95 |
+
def generate_teaching_note(state, student_response, mode, persona=None):
|
| 96 |
"""Generate pedagogical feedback based on the literary interaction."""
|
| 97 |
response_lower = student_response.lower()
|
| 98 |
notes = []
|
| 99 |
|
| 100 |
+
# Get character-specific context if available
|
| 101 |
+
char_name = persona.get("persona_name", "the character") if persona else "the character"
|
| 102 |
+
source_text = persona.get("source_text", {}) if persona else {}
|
| 103 |
+
author = source_text.get("author", "the author")
|
| 104 |
+
title = source_text.get("title", "the text")
|
| 105 |
+
|
| 106 |
# Question quality - literary analysis focused
|
| 107 |
if any(word in response_lower for word in ["why did you", "why do you", "why are you"]):
|
| 108 |
notes.append("π **Literary Technique**: 'Why' questions can sound accusatory. Consider using 'what' or 'how' to explore motivations more naturally (e.g., 'What were you thinking when...' or 'How did that moment feel?')")
|
|
|
|
| 115 |
|
| 116 |
# Question depth - connect to literary concepts
|
| 117 |
if len(student_response.split()) < 8:
|
| 118 |
+
if author and title:
|
| 119 |
+
notes.append(f"π **Add Textual Context**: Reference specific moments from '{title}' to ground your question. Connect to scenes, relationships, or conflicts from {author}'s narrative.")
|
| 120 |
+
else:
|
| 121 |
+
notes.append("π **Add Textual Context**: Reference specific moments from the story to ground your question in the character's actual experiences.")
|
| 122 |
|
| 123 |
if any(phrase in response_lower for phrase in ["tell me about", "tell me more", "what's that like", "how do you feel"]):
|
| 124 |
notes.append("β
**Strong Question**: Open-ended questions like this encourage the character to reveal subtext, internal conflict, and thematic depth. This is effective literary analysis.")
|
|
|
|
| 128 |
|
| 129 |
# Character engagement - literary context
|
| 130 |
if mode == "triggered" and state.get("trust", 0) < 0.4:
|
| 131 |
+
if author:
|
| 132 |
+
notes.append(f"β οΈ **Character Defensive**: Notice how {char_name} withdraws when challenged - this mirrors how {author} shows psychological realism. Try questions that validate their experience first.")
|
| 133 |
+
else:
|
| 134 |
+
notes.append("β οΈ **Character Defensive**: The character is withdrawing. Try questions that validate their experience before probing deeper.")
|
| 135 |
|
| 136 |
if mode == "trusting" and state.get("anxiety", 0) > 0.6:
|
| 137 |
notes.append("β¨ **Key Moment**: The character is vulnerable right now - this is where authors reveal crucial backstory and motivation. Press deeper into their fears and desires.")
|
|
|
|
| 144 |
|
| 145 |
# Add literary context based on specific terms used
|
| 146 |
if any(word in response_lower for word in ["choice", "decision", "decide"]):
|
| 147 |
+
notes.append("π‘ **Theme Connection**: You're exploring agency and choice - a key theme in literature. How does paralysis or action define this character?")
|
| 148 |
|
| 149 |
+
if any(word in response_lower for word in ["family", "mother", "father", "parent", "sister", "brother"]):
|
| 150 |
notes.append("π¨βπ©βπ§ **Family Dynamics**: You're examining how family obligations shape identity - analyze how the author uses familial duty to explore broader social constraints.")
|
| 151 |
|
| 152 |
if not notes:
|
| 153 |
+
notes.append("β
**Good Engagement**: You're exploring the character thoughtfully. Consider connecting their responses to the story's central themes and conflicts.")
|
| 154 |
|
| 155 |
return "\n".join(notes)
|
engine/responder.py
CHANGED
|
@@ -272,7 +272,7 @@ Rules:
|
|
| 272 |
state["emotional_memory"].append(memory_tag)
|
| 273 |
state["emotional_memory"] = state["emotional_memory"][-5:]
|
| 274 |
|
| 275 |
-
teaching_note = generate_teaching_note(state, student_prompt, mode)
|
| 276 |
teaching_note += "\n\nπ‘ Response generated using HuggingFace Inference API"
|
| 277 |
|
| 278 |
return response_text, state, teaching_note
|
|
@@ -323,9 +323,9 @@ def generate_response_claude(student_prompt, persona, conversation_history, forc
|
|
| 323 |
state["emotional_memory"].append(memory_tag)
|
| 324 |
state["emotional_memory"] = state["emotional_memory"][-5:]
|
| 325 |
|
| 326 |
-
teaching_note = generate_teaching_note(state, student_prompt, mode)
|
| 327 |
teaching_note += "\n\n⨠Response generated using Claude AI (Premium)"
|
| 328 |
-
|
| 329 |
return response_text, state, teaching_note
|
| 330 |
|
| 331 |
except Exception as e:
|
|
@@ -575,7 +575,7 @@ Do NOT write conversations, dialogues, or responses from other people.
|
|
| 575 |
state["emotional_memory"] = state["emotional_memory"][-5:]
|
| 576 |
|
| 577 |
# Teaching note
|
| 578 |
-
teaching_note = generate_teaching_note(state, student_prompt, mode)
|
| 579 |
teaching_note += "\n\nβ‘ Response generated using local TinyLlama model (CPU-optimized)"
|
| 580 |
|
| 581 |
return response, state, teaching_note
|
|
|
|
| 272 |
state["emotional_memory"].append(memory_tag)
|
| 273 |
state["emotional_memory"] = state["emotional_memory"][-5:]
|
| 274 |
|
| 275 |
+
teaching_note = generate_teaching_note(state, student_prompt, mode, persona)
|
| 276 |
teaching_note += "\n\nπ‘ Response generated using HuggingFace Inference API"
|
| 277 |
|
| 278 |
return response_text, state, teaching_note
|
|
|
|
| 323 |
state["emotional_memory"].append(memory_tag)
|
| 324 |
state["emotional_memory"] = state["emotional_memory"][-5:]
|
| 325 |
|
| 326 |
+
teaching_note = generate_teaching_note(state, student_prompt, mode, persona)
|
| 327 |
teaching_note += "\n\n⨠Response generated using Claude AI (Premium)"
|
| 328 |
+
|
| 329 |
return response_text, state, teaching_note
|
| 330 |
|
| 331 |
except Exception as e:
|
|
|
|
| 575 |
state["emotional_memory"] = state["emotional_memory"][-5:]
|
| 576 |
|
| 577 |
# Teaching note
|
| 578 |
+
teaching_note = generate_teaching_note(state, student_prompt, mode, persona)
|
| 579 |
teaching_note += "\n\nβ‘ Response generated using local TinyLlama model (CPU-optimized)"
|
| 580 |
|
| 581 |
return response, state, teaching_note
|