File size: 2,773 Bytes
551b309 | 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 | """Exceptions raised by the AffixIO Hugging Face SDK."""
# Credit: @paparichens
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."""
|