Team Ai
Apppublic

pratik-250620/MultiModal-Coherence-AI

sourceHugging Facemitupdated 8mo agoView on Hugging Face
2likes
exceptions.py80 linesDownload Raw Back to src
1"""2Custom exception hierarchy for MultiModal Coherence AI.3 4Provides structured error types so callers can distinguish between5retrieval failures, generation failures, and validation errors6instead of catching bare Exception everywhere.7"""8 9 10class MultiModalError(Exception):11    """Base exception for all project-specific errors."""12 13 14class RetrievalError(MultiModalError):15    """Raised when image or audio retrieval fails.16 17    Attributes:18        query: The query text that failed retrieval.19        modality: 'image' or 'audio'.20        best_similarity: The best similarity score found (if any).21    """22 23    def __init__(self, message: str, *, query: str = "", modality: str = "", best_similarity: float | None = None):24        super().__init__(message)25        self.query = query26        self.modality = modality27        self.best_similarity = best_similarity28 29 30class GenerationError(MultiModalError):31    """Raised when text, image, or audio generation fails.32 33    Attributes:34        modality: 'text', 'image', or 'audio'.35        backend: The backend that failed (e.g., 'ollama', 'audioldm', 'fallback_ambient').36    """37 38    def __init__(self, message: str, *, modality: str = "", backend: str = ""):39        super().__init__(message)40        self.modality = modality41        self.backend = backend42 43 44class ValidationError(MultiModalError):45    """Raised when input validation or conditioning checks fail.46 47    Attributes:48        field: The field or parameter that failed validation.49    """50 51    def __init__(self, message: str, *, field: str = ""):52        super().__init__(message)53        self.field = field54 55 56class EmbeddingError(MultiModalError):57    """Raised when embedding computation fails.58 59    Attributes:60        modality: The modality that failed ('text', 'image', 'audio').61        model: The model that failed (e.g., 'clip', 'clap').62    """63 64    def __init__(self, message: str, *, modality: str = "", model: str = ""):65        super().__init__(message)66        self.modality = modality67        self.model = model68 69 70class IndexError_(MultiModalError):71    """Raised when an embedding index is missing, empty, or corrupt."""72 73    def __init__(self, message: str, *, index_path: str = ""):74        super().__init__(message)75        self.index_path = index_path76 77 78class PlanningError(MultiModalError):79    """Raised when the semantic planner fails to produce a valid plan."""80