ta_ml / api /dependencies.py
muhammadjalaludin
Implement service layers for backup, model management, file handling, tokenization, and training
1424118
Raw History Blame Contribute Delete
1.7 kB
# ta_ml/api/dependencies.py
"""
FastAPI dependency injection providers.
This module defines functions that FastAPI's `Depends` can use to retrieve
service instances from the application state. This decouples the API endpoints
from the creation of their dependencies.
"""
from fastapi import Request
from services.prediction_service import PredictionService
from services.training_service import TrainingService
from services.tokenization_service import TokenizationService
from services.backup_service import BackupService
from services.space_file_service import SpaceFileService
from services.model_manager import ModelManager
def get_prediction_service(request: Request) -> PredictionService:
"""Gets the prediction service instance from the app state."""
return request.app.state.prediction_service
def get_training_service(request: Request) -> TrainingService:
"""Gets the training service instance from the app state."""
return request.app.state.training_service
def get_tokenization_service(request: Request) -> TokenizationService:
"""Gets the tokenization service instance from the app state."""
return request.app.state.tokenization_service
def get_backup_service(request: Request) -> BackupService:
"""Gets the backup service instance from the app state."""
return request.app.state.backup_service
def get_space_file_service(request: Request) -> SpaceFileService:
"""Gets the space file service instance from the app state."""
return request.app.state.space_file_service
def get_model_manager(request: Request) -> ModelManager:
"""Gets the model manager instance from the app state."""
return request.app.state.model_manager