ludus-quiz-prototype / ludus_chat.py
rivapereira123's picture
Create ludus_chat.py
61a5c8e verified
def should_soften_response(response: str, emotions: list) -> bool:
short = len(response.strip()) < 8
unsure = any(e[0] in ["confusion", "fear", "nervousness"] for e in emotions)
vague = response.strip().lower() in ["idk", "not sure", "nah", "maybe", "hmm"]
return short or unsure or vague
def build_reflection(user_input, emotions, memory=None):
base_emotion = emotions[0][0] if emotions else "something soft"
intro = random.choice([
f"What I hear is… there's a sense of {base_emotion}.",
f"Your words carry a feeling of {base_emotion}.",
f"It feels like you're gently holding something {base_emotion}-tinged."
])
memory_tag = ""
if memory:
memory_tag = f"\nEarlier you mentioned feeling **{memory}**… does that still linger?"
follow_up = random.choice([
"Would you say this comes from past experience?",
"Can you tell me what makes that feel so true?",
"No rush — you can describe it however feels easiest.",
])
return f"{intro}{memory_tag}\n{follow_up}"