alibicer's picture
Update app.py
fba2fd4 verified
raw
history blame
1.19 kB
def respond(user_message, history):
"""
Handles user input and determines how the chatbot responds.
- If the teacher selects a method, AI will **first ask them to explain their approach**.
- AI will not provide a full solution immediately.
- If the teacher already explained, AI will provide feedback and hints.
"""
user_message = user_message.strip().lower()
# If the user selects a method, prompt them to explain their approach first
if user_message in ["bar model", "double number line", "equation"]:
return get_prompt_for_method(user_message), history
# If AI is expecting an explanation, process teacher's response
elif len(history) > 0 and history[-1] in [
get_prompt_for_method("bar model"),
get_prompt_for_method("double number line"),
get_prompt_for_method("equation")
]:
last_method = history[-1].split("**")[1].split(" ")[0].lower() # Extract method name from the last message
return get_feedback_for_method(last_method, user_message), history
return "I didn’t quite understand that. Please select a method first (Bar Model, Double Number Line, or Equation).", history