Spaces:
Sleeping
Sleeping
| """FastAPI dependency providers for service instances. | |
| Each provider retrieves the service from request.app.state.services (the | |
| ServiceContainer attached during application lifespan startup). | |
| """ | |
| from __future__ import annotations | |
| from dataclasses import dataclass | |
| from typing import Any | |
| from fastapi import Request | |
| from app.data.loader import DatasetLoader | |
| from app.models.registry import ModelRegistry | |
| from app.monitoring.prediction_logger import PredictionLogger | |
| from app.services.explanation_service import ExplanationService | |
| class ServiceContainer: | |
| """Holds all service instances initialized at startup. | |
| Services that have not yet been implemented are typed as Any and | |
| set to None until their implementation tasks are completed. | |
| """ | |
| registry: ModelRegistry | |
| loader: DatasetLoader | |
| explainer: ExplanationService | |
| pred_logger: PredictionLogger | |
| # Inference services — set to None until implemented (tasks 4.x, 5.x, 6.x) | |
| lo_tagging: Any = None | |
| bloom: Any = None | |
| mastery: Any = None | |
| risk: Any = None | |
| recommendation: Any = None | |
| answer_evaluation: Any = None | |
| student_profile: Any = None | |
| class_insights: Any = None | |
| teacher_feedback: Any = None | |
| monitoring: Any = None | |
| def get_service_container(request: Request) -> ServiceContainer: | |
| """Retrieve the full ServiceContainer from app state.""" | |
| return request.app.state.services | |
| def get_lo_tagging_service(request: Request) -> Any: | |
| """Provide the LO tagging service instance.""" | |
| return request.app.state.services.lo_tagging | |
| def get_bloom_service(request: Request) -> Any: | |
| """Provide the Bloom classification service instance.""" | |
| return request.app.state.services.bloom | |
| def get_mastery_service(request: Request) -> Any: | |
| """Provide the mastery prediction service instance.""" | |
| return request.app.state.services.mastery | |
| def get_risk_service(request: Request) -> Any: | |
| """Provide the risk prediction service instance.""" | |
| return request.app.state.services.risk | |
| def get_recommendation_service(request: Request) -> Any: | |
| """Provide the recommendation service instance.""" | |
| return request.app.state.services.recommendation | |
| def get_answer_evaluation_service(request: Request) -> Any: | |
| """Provide the answer evaluation service instance.""" | |
| return request.app.state.services.answer_evaluation | |
| def get_student_profile_service(request: Request) -> Any: | |
| """Provide the student profile service instance.""" | |
| return request.app.state.services.student_profile | |
| def get_class_insights_service(request: Request) -> Any: | |
| """Provide the class insights service instance.""" | |
| return request.app.state.services.class_insights | |
| def get_teacher_feedback_service(request: Request) -> Any: | |
| """Provide the teacher feedback service instance.""" | |
| return request.app.state.services.teacher_feedback | |
| def get_monitoring_service(request: Request) -> Any: | |
| """Provide the monitoring service instance.""" | |
| return request.app.state.services.monitoring | |