| """Exceptions raised by the AffixIO Hugging Face SDK.""" |
|
|
| |
|
|
| from __future__ import annotations |
|
|
| from typing import Any |
|
|
|
|
| class AffixHuggingFaceError(Exception): |
| """Base SDK error.""" |
|
|
|
|
| class ConfigurationError(AffixHuggingFaceError): |
| """Required credentials or configuration are missing.""" |
|
|
|
|
| class AffixAPIError(AffixHuggingFaceError): |
| """The AffixIO API returned an error response.""" |
|
|
| def __init__( |
| self, |
| message: str, |
| *, |
| status_code: int, |
| code: str | None = None, |
| request_id: str | None = None, |
| body: dict[str, Any] | None = None, |
| ) -> None: |
| super().__init__(message) |
| self.status_code = status_code |
| self.code = code |
| self.request_id = request_id |
| self.body = body or {} |
|
|
|
|
| class AdmissionDenied(AffixHuggingFaceError): |
| """AffixIO refused the inference request before Hugging Face was called.""" |
|
|
| def __init__( |
| self, |
| message: str, |
| *, |
| reason_code: str, |
| receipt_id: str | None = None, |
| request_id: str | None = None, |
| ) -> None: |
| super().__init__(message) |
| self.reason_code = reason_code |
| self.receipt_id = receipt_id |
| self.request_id = request_id |
|
|
|
|
| UPGRADE_STEPS = ( |
| "Your free allowance is used up. To continue with your own key:\n" |
| " 1. Register at https://hub.affix-io.com/ and request API access.\n" |
| " 2. Access is granted after review, not instantly.\n" |
| " 3. Once approved, create a key at https://hub.affix-io.com/credentials/\n" |
| " 4. Set AFFIX_API_KEY=aio_... and run again. Your key has no trial cap." |
| ) |
|
|
|
|
| class TrialExhausted(AffixHuggingFaceError): |
| """The server-side proof allowance for this subject has been used up.""" |
|
|
| def __init__( |
| self, |
| message: str, |
| *, |
| limit: int, |
| used: int, |
| request_id: str | None = None, |
| ) -> None: |
| super().__init__(f"{message}\n\n{UPGRADE_STEPS}") |
| self.limit = limit |
| self.used = used |
| self.remaining = 0 |
| self.request_id = request_id |
| self.upgrade_url = "https://hub.affix-io.com/" |
| self.upgrade_steps = UPGRADE_STEPS |
|
|
|
|
| class RegistrationThrottled(AffixHuggingFaceError): |
| """AffixIO refused to register another new subject from this origin today.""" |
|
|
|
|
| class EvidenceError(AffixHuggingFaceError): |
| """Inference completed, but completion evidence could not be issued.""" |
|
|
| def __init__(self, message: str, *, output: Any, cause: Exception) -> None: |
| super().__init__(message) |
| self.output = output |
| self.__cause__ = cause |
|
|
|
|
| class StreamNotComplete(AffixHuggingFaceError): |
| """A final stream receipt was requested before the stream finished.""" |
|
|
|
|