Spaces:
Running
Running
File size: 4,166 Bytes
ba68fc1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
#!/usr/bin/env python3
"""
Custom exception classes for the GAIA system.
"""
from typing import Optional, Any, Dict
class GAIAError(Exception):
"""Base exception for all GAIA-related errors."""
def __init__(self, message: str, details: Optional[Dict[str, Any]] = None):
super().__init__(message)
self.message = message
self.details = details or {}
def __str__(self) -> str:
if self.details:
return f"{self.message} - Details: {self.details}"
return self.message
class ModelError(GAIAError):
"""Exception raised for model-related errors."""
def __init__(self, message: str, model_name: Optional[str] = None,
provider: Optional[str] = None, **kwargs):
super().__init__(message, kwargs)
self.model_name = model_name
self.provider = provider
class ModelNotAvailableError(ModelError):
"""Exception raised when requested model is not available."""
pass
class ModelAuthenticationError(ModelError):
"""Exception raised for model authentication failures."""
pass
class ModelOverloadedError(ModelError):
"""Exception raised when model is overloaded."""
pass
class ToolError(GAIAError):
"""Exception raised for tool execution errors."""
def __init__(self, message: str, tool_name: Optional[str] = None,
input_data: Optional[Dict[str, Any]] = None, **kwargs):
super().__init__(message, kwargs)
self.tool_name = tool_name
self.input_data = input_data
class ToolNotFoundError(ToolError):
"""Exception raised when requested tool is not found."""
pass
class ToolValidationError(ToolError):
"""Exception raised for tool input validation errors."""
pass
class ToolExecutionError(ToolError):
"""Exception raised during tool execution."""
pass
class ToolTimeoutError(ToolError):
"""Exception raised when tool execution times out."""
pass
class ClassificationError(GAIAError):
"""Exception raised for question classification errors."""
def __init__(self, message: str, question: Optional[str] = None, **kwargs):
super().__init__(message, kwargs)
self.question = question
class FileProcessingError(GAIAError):
"""Exception raised for file processing errors."""
def __init__(self, message: str, file_path: Optional[str] = None,
file_type: Optional[str] = None, **kwargs):
super().__init__(message, kwargs)
self.file_path = file_path
self.file_type = file_type
class APIError(GAIAError):
"""Exception raised for external API errors."""
def __init__(self, message: str, api_name: Optional[str] = None,
status_code: Optional[int] = None, **kwargs):
super().__init__(message, kwargs)
self.api_name = api_name
self.status_code = status_code
class ConfigurationError(GAIAError):
"""Exception raised for configuration errors."""
pass
class ValidationError(GAIAError):
"""Exception raised for data validation errors."""
def __init__(self, message: str, field: Optional[str] = None,
value: Optional[Any] = None, **kwargs):
super().__init__(message, kwargs)
self.field = field
self.value = value
# Error code mapping for consistent error handling
ERROR_CODES = {
"MODEL_NOT_AVAILABLE": ModelNotAvailableError,
"MODEL_AUTH_FAILED": ModelAuthenticationError,
"MODEL_OVERLOADED": ModelOverloadedError,
"TOOL_NOT_FOUND": ToolNotFoundError,
"TOOL_VALIDATION_FAILED": ToolValidationError,
"TOOL_EXECUTION_FAILED": ToolExecutionError,
"TOOL_TIMEOUT": ToolTimeoutError,
"CLASSIFICATION_FAILED": ClassificationError,
"FILE_PROCESSING_FAILED": FileProcessingError,
"API_ERROR": APIError,
"CONFIG_ERROR": ConfigurationError,
"VALIDATION_ERROR": ValidationError
}
def create_error(error_code: str, message: str, **kwargs) -> GAIAError:
"""Create error instance based on error code."""
error_class = ERROR_CODES.get(error_code, GAIAError)
return error_class(message, **kwargs) |