Spaces:
Configuration error
Configuration error
Download backend/routers/practice.py from rockysreenivasa/MathTutor: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/spaces/rockysreenivasa/MathTutor/resolve/main/backend/routers/practice.py
- Command line
-
hf download hf://spaces/rockysreenivasa/MathTutor/backend/routers/practice.py
-
curl -L -o practice.py https://huggingface.co/spaces/rockysreenivasa/MathTutor/resolve/main/backend/routers/practice.py
1.27 kB
| from fastapi import APIRouter, Depends, HTTPException | |
| from backend.core.auth import get_current_user | |
| from backend.models.practice import PracticeRequest, PracticeResponse, PracticeProblem | |
| from backend.services import claude_service, prompt_templates | |
| router = APIRouter(prefix="/api", tags=["practice"]) | |
| async def generate_practice( | |
| body: PracticeRequest, | |
| user: dict = Depends(get_current_user), | |
| ): | |
| """Generate 3 adaptive practice problems for the given topic and grade.""" | |
| system = prompt_templates.practice_system(body.grade) | |
| user_msg = prompt_templates.practice_user(body.topic, body.count) | |
| try: | |
| raw = await claude_service.complete_json(system, user_msg) | |
| except ValueError as e: | |
| raise HTTPException(status_code=502, detail=str(e)) | |
| problems = [] | |
| for item in (raw if isinstance(raw, list) else []): | |
| problems.append( | |
| PracticeProblem( | |
| question=item.get("question", ""), | |
| answer=item.get("answer", ""), | |
| hint=item.get("hint", ""), | |
| difficulty=item.get("difficulty", "medium"), | |
| ) | |
| ) | |
| return PracticeResponse(problems=problems, session_id=body.session_id) | |