File size: 1,194 Bytes
ce5b5d6
fba2fd4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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