Download app.py from MathProfessionalDevelopment/mathchatbot-v4-simple: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/MathProfessionalDevelopment/mathchatbot-v4-simple/resolve/fba2fd482ecc5dde8a5db73fe792620bb96cdf83/app.py
- Command line
-
hf download hf://spaces/MathProfessionalDevelopment/mathchatbot-v4-simple@fba2fd482ecc5dde8a5db73fe792620bb96cdf83/app.py
-
curl -L -o app.py https://huggingface.co/spaces/MathProfessionalDevelopment/mathchatbot-v4-simple/resolve/fba2fd482ecc5dde8a5db73fe792620bb96cdf83/app.py
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 | |