Skip to content

consts

Constants used by the SDK.

ID_TYPES module-attribute

ID_TYPES = str | UUID

The types that can be used as IDs.

horde_sdk_github_url module-attribute

horde_sdk_github_url = (
    "https://github.com/Haidra-Org/horde_sdk"
)

PAYLOAD_HTTP_METHODS module-attribute

PAYLOAD_HTTP_METHODS = {POST, PUT, PATCH}

UnknownServiceInfo module-attribute

UnknownServiceInfo = ServiceInfo(
    known_identifier=UNKNOWN,
    display_name="Unknown Service",
    description="This service is not recognized.",
    url=None,
)

CustomUnpublishedServiceInfo module-attribute

CustomUnpublishedServiceInfo = ServiceInfo(
    known_identifier=CUSTOM_UNPUBLISHED,
    display_name="Custom Unpublished Service",
    description="This is a custom unpublished service.",
    url=None,
)

AIHordeServiceInfo module-attribute

AIHordeServiceInfo = ServiceInfo(
    known_identifier=AI_HORDE,
    display_name="AI Horde",
    description="AI Horde is a decentralized, crowd-sourced platform for AI model generation and more.",
    url="https://aihorde.net",
)

CivitAIServiceInfo module-attribute

CivitAIServiceInfo = ServiceInfo(
    known_identifier=CIVITAI,
    display_name="CivitAI",
    description="CivitAI is a platform for AI model hosting and deployment.",
    url="https://civitai.com",
)

HTTPMethod

Bases: StrEnum

An enum representing all HTTP methods.

Source code in horde_sdk/consts.py
class HTTPMethod(StrEnum):
    """An enum representing all HTTP methods."""

    GET = "GET"
    POST = "POST"
    PUT = "PUT"
    DELETE = "DELETE"
    PATCH = "PATCH"
    OPTIONS = "OPTIONS"
    HEAD = "HEAD"
    TRACE = "TRACE"
    CONNECT = "CONNECT"

GET class-attribute instance-attribute

GET = 'GET'

POST class-attribute instance-attribute

POST = 'POST'

PUT class-attribute instance-attribute

PUT = 'PUT'

DELETE class-attribute instance-attribute

DELETE = 'DELETE'

PATCH class-attribute instance-attribute

PATCH = 'PATCH'

OPTIONS class-attribute instance-attribute

OPTIONS = 'OPTIONS'

HEAD class-attribute instance-attribute

HEAD = 'HEAD'

TRACE class-attribute instance-attribute

TRACE = 'TRACE'

CONNECT class-attribute instance-attribute

CONNECT = 'CONNECT'

HTTPStatusCode

Bases: IntEnum

An enum representing all HTTP status codes.

Source code in horde_sdk/consts.py
class HTTPStatusCode(IntEnum):
    """An enum representing all HTTP status codes."""

    OK = 200
    CREATED = 201
    ACCEPTED = 202
    NO_CONTENT = 204

    BAD_REQUEST = 400
    UNAUTHORIZED = 401
    FORBIDDEN = 403
    NOT_FOUND = 404
    METHOD_NOT_ALLOWED = 405
    NOT_ACCEPTABLE = 406
    REQUEST_TIMEOUT = 408
    CONFLICT = 409
    GONE = 410
    UNPROCESSABLE_ENTITY = 422
    TOO_MANY_REQUESTS = 429

    INTERNAL_SERVER_ERROR = 500
    NOT_IMPLEMENTED = 501
    SERVICE_UNAVAILABLE = 503
    GATEWAY_TIMEOUT = 504

OK class-attribute instance-attribute

OK = 200

CREATED class-attribute instance-attribute

CREATED = 201

ACCEPTED class-attribute instance-attribute

ACCEPTED = 202

NO_CONTENT class-attribute instance-attribute

NO_CONTENT = 204

BAD_REQUEST class-attribute instance-attribute

BAD_REQUEST = 400

UNAUTHORIZED class-attribute instance-attribute

UNAUTHORIZED = 401

FORBIDDEN class-attribute instance-attribute

FORBIDDEN = 403

NOT_FOUND class-attribute instance-attribute

NOT_FOUND = 404

METHOD_NOT_ALLOWED class-attribute instance-attribute

METHOD_NOT_ALLOWED = 405

NOT_ACCEPTABLE class-attribute instance-attribute

NOT_ACCEPTABLE = 406

REQUEST_TIMEOUT class-attribute instance-attribute

REQUEST_TIMEOUT = 408

CONFLICT class-attribute instance-attribute

CONFLICT = 409

GONE class-attribute instance-attribute

GONE = 410

UNPROCESSABLE_ENTITY class-attribute instance-attribute

UNPROCESSABLE_ENTITY = 422

TOO_MANY_REQUESTS class-attribute instance-attribute

TOO_MANY_REQUESTS = 429

INTERNAL_SERVER_ERROR class-attribute instance-attribute

INTERNAL_SERVER_ERROR = 500

NOT_IMPLEMENTED class-attribute instance-attribute

NOT_IMPLEMENTED = 501

SERVICE_UNAVAILABLE class-attribute instance-attribute

SERVICE_UNAVAILABLE = 503

GATEWAY_TIMEOUT class-attribute instance-attribute

GATEWAY_TIMEOUT = 504

KNOWN_DISPATCH_SOURCE

Bases: StrEnum

The known sources of a dispatch.

Source code in horde_sdk/consts.py
class KNOWN_DISPATCH_SOURCE(StrEnum):
    """The known sources of a dispatch."""

    UNKNOWN = auto()
    """The source of the dispatch is unknown."""

    LOCAL_CUSTOM_3RD_PARTY = auto()
    """The source of the dispatch is a local custom 3rd party API."""

    AI_HORDE_API_OFFICIAL = auto()
    """The source of the dispatch is the official AI Horde API."""

    AI_HORDE_API_FORK = auto()
    """The source of the dispatch is a fork of the official AI Horde API."""

UNKNOWN class-attribute instance-attribute

UNKNOWN = auto()

The source of the dispatch is unknown.

LOCAL_CUSTOM_3RD_PARTY class-attribute instance-attribute

LOCAL_CUSTOM_3RD_PARTY = auto()

The source of the dispatch is a local custom 3rd party API.

AI_HORDE_API_OFFICIAL class-attribute instance-attribute

AI_HORDE_API_OFFICIAL = auto()

The source of the dispatch is the official AI Horde API.

AI_HORDE_API_FORK class-attribute instance-attribute

AI_HORDE_API_FORK = auto()

The source of the dispatch is a fork of the official AI Horde API.

KNOWN_NSFW_DETECTOR

Bases: StrEnum

The NSFW detectors that are known to the API.

Source code in horde_sdk/consts.py
class KNOWN_NSFW_DETECTOR(StrEnum):
    """The NSFW detectors that are known to the API."""

    BACKEND_DEFAULT = auto()
    """The default model for the worker backend."""

    HORDE_SAFETY = auto()
    """The AI-Horde horde_safety package."""

    COMPVIS_SAFETY_CHECKER = auto()
    """The compvis safety checker model released with stable diffusion."""

BACKEND_DEFAULT class-attribute instance-attribute

BACKEND_DEFAULT = auto()

The default model for the worker backend.

HORDE_SAFETY class-attribute instance-attribute

HORDE_SAFETY = auto()

The AI-Horde horde_safety package.

COMPVIS_SAFETY_CHECKER class-attribute instance-attribute

COMPVIS_SAFETY_CHECKER = auto()

The compvis safety checker model released with stable diffusion.

WORKER_TYPE

Bases: StrEnum

The worker types that are known.

(alchemy, image, text, etc...)

Source code in horde_sdk/consts.py
class WORKER_TYPE(StrEnum):
    """The worker types that are known.

    (alchemy, image, text, etc...)
    """

    image = auto()
    """Image generation worker."""
    text = auto()
    """Text generation worker."""
    interrogation = auto()
    """Alchemy/Interrogation worker."""
    alchemist = "interrogation"
    """Alchemy/Interrogation worker."""
    video = auto()
    """Video generation worker."""
    audio = auto()
    """Audio generation worker."""

image class-attribute instance-attribute

image = auto()

Image generation worker.

text class-attribute instance-attribute

text = auto()

Text generation worker.

interrogation class-attribute instance-attribute

interrogation = auto()

Alchemy/Interrogation worker.

alchemist class-attribute instance-attribute

alchemist = 'interrogation'

Alchemy/Interrogation worker.

video class-attribute instance-attribute

video = auto()

Video generation worker.

audio class-attribute instance-attribute

audio = auto()

Audio generation worker.

KNOWN_INFERENCE_BACKEND

Bases: StrEnum

The known generative inference backends.

Source code in horde_sdk/consts.py
class KNOWN_INFERENCE_BACKEND(StrEnum):
    """The known generative inference backends."""

    UNKNOWN = auto()
    """The inference backend is unknown."""

    IN_MODEL_NAME = auto()
    """The model name is prepended with the backend name."""

    CUSTOM_UNPUBLISHED = auto()
    """The inference backend is a custom, unpublished backend."""

    COMFYUI = auto()
    """The inference backend is ComfyUI."""

    A1111 = auto()
    """The inference backend is A1111."""

    HORDE_ALCHEMIST = auto()
    """The inference backend is the Horde Alchemist."""

    KOBOLD_CPP = auto()
    """The inference backend is Kobold CPP."""

    APHRODITE = auto()
    """The inference backend is Aphrodite."""

UNKNOWN class-attribute instance-attribute

UNKNOWN = auto()

The inference backend is unknown.

IN_MODEL_NAME class-attribute instance-attribute

IN_MODEL_NAME = auto()

The model name is prepended with the backend name.

CUSTOM_UNPUBLISHED class-attribute instance-attribute

CUSTOM_UNPUBLISHED = auto()

The inference backend is a custom, unpublished backend.

COMFYUI class-attribute instance-attribute

COMFYUI = auto()

The inference backend is ComfyUI.

A1111 class-attribute instance-attribute

A1111 = auto()

The inference backend is A1111.

HORDE_ALCHEMIST class-attribute instance-attribute

HORDE_ALCHEMIST = auto()

The inference backend is the Horde Alchemist.

KOBOLD_CPP class-attribute instance-attribute

KOBOLD_CPP = auto()

The inference backend is Kobold CPP.

APHRODITE class-attribute instance-attribute

APHRODITE = auto()

The inference backend is Aphrodite.

KNOWN_ALCHEMY_BACKEND

Bases: StrEnum

The known alchemy backends.

Source code in horde_sdk/consts.py
class KNOWN_ALCHEMY_BACKEND(StrEnum):
    """The known alchemy backends."""

    UNKNOWN = auto()
    """The alchemy backend is unknown."""

    CUSTOM_UNPUBLISHED = auto()
    """The alchemy backend is a custom, unpublished backend."""

    HORDE_ALCHEMIST = auto()
    """The alchemy backend is the Horde Alchemist."""

UNKNOWN class-attribute instance-attribute

UNKNOWN = auto()

The alchemy backend is unknown.

CUSTOM_UNPUBLISHED class-attribute instance-attribute

CUSTOM_UNPUBLISHED = auto()

The alchemy backend is a custom, unpublished backend.

HORDE_ALCHEMIST class-attribute instance-attribute

HORDE_ALCHEMIST = auto()

The alchemy backend is the Horde Alchemist.

KNOWN_SERVICE

Bases: StrEnum

The known services that can be used for generation.

Source code in horde_sdk/consts.py
class KNOWN_SERVICE(StrEnum):
    """The known services that can be used for generation."""

    UNKNOWN = auto()
    """The service is unknown."""

    CUSTOM_UNPUBLISHED = auto()
    """The service is a custom, unpublished service."""

    AI_HORDE = auto()
    """The AI Horde service."""

    CIVITAI = auto()
    """The CivitAI service."""

UNKNOWN class-attribute instance-attribute

UNKNOWN = auto()

The service is unknown.

CUSTOM_UNPUBLISHED class-attribute instance-attribute

CUSTOM_UNPUBLISHED = auto()

The service is a custom, unpublished service.

AI_HORDE class-attribute instance-attribute

AI_HORDE = auto()

The AI Horde service.

CIVITAI class-attribute instance-attribute

CIVITAI = auto()

The CivitAI service.

ServiceInfo

Bases: BaseModel

Represents information about a service.

Source code in horde_sdk/consts.py
class ServiceInfo(BaseModel):
    """Represents information about a service."""

    model_config = ConfigDict(
        use_attribute_docstrings=True,
    )

    known_identifier: KNOWN_SERVICE = KNOWN_SERVICE.UNKNOWN
    """The known identifier for the service, if any."""

    display_name: str = Field(..., min_length=1)
    """The name of the service."""

    description: str | None = None
    """A description of the service."""

    url: str | None = None
    """The URL of the service."""

model_config class-attribute instance-attribute

model_config = ConfigDict(use_attribute_docstrings=True)

known_identifier class-attribute instance-attribute

known_identifier: KNOWN_SERVICE = UNKNOWN

The known identifier for the service, if any.

display_name class-attribute instance-attribute

display_name: str = Field(..., min_length=1)

The name of the service.

description class-attribute instance-attribute

description: str | None = None

A description of the service.

url class-attribute instance-attribute

url: str | None = None

The URL of the service.

get_default_frozen_model_config_dict

get_default_frozen_model_config_dict() -> ConfigDict

Return the default horde-sdk frozen model config dict for a pydantic BaseModel.

Critically, models configured this way will behave differently when used in tests, preventing the use of extra fields being passed to constructors. However, this is not the case in production, where pass-through is allowed and up to implementors to choose to handle.

Source code in horde_sdk/consts.py
def get_default_frozen_model_config_dict() -> ConfigDict:
    """Return the default horde-sdk frozen model config dict for a pydantic `BaseModel`.

    Critically, models configured this way will behave differently when used in tests, preventing
    the use of extra fields being passed to constructors. However, this is not the case in production,
    where pass-through is allowed and up to implementors to choose to handle.
    """
    return (
        ConfigDict(
            frozen=True,
            use_attribute_docstrings=True,
            from_attributes=True,
            extra="allow",
        )
        if not os.getenv("TESTS_ONGOING")
        else ConfigDict(
            frozen=True,
            use_attribute_docstrings=True,
            from_attributes=True,
            extra="forbid",
        )
    )

get_all_success_status_codes

get_all_success_status_codes() -> list[HTTPStatusCode]

Return a list of all success status codes.

Source code in horde_sdk/consts.py
def get_all_success_status_codes() -> list[HTTPStatusCode]:
    """Return a list of all success status codes."""
    return [status_code for status_code in HTTPStatusCode if is_success_status_code(status_code)]

get_all_error_status_codes

get_all_error_status_codes() -> list[HTTPStatusCode]

Return a list of all error status codes.

Source code in horde_sdk/consts.py
def get_all_error_status_codes() -> list[HTTPStatusCode]:
    """Return a list of all error status codes."""
    return [status_code for status_code in HTTPStatusCode if is_error_status_code(status_code)]

is_success_status_code

is_success_status_code(
    status_code: HTTPStatusCode | int,
) -> bool

Return True if the status code is a success code, False otherwise.

Source code in horde_sdk/consts.py
def is_success_status_code(status_code: HTTPStatusCode | int) -> bool:
    """Return True if the status code is a success code, False otherwise."""
    if isinstance(status_code, HTTPStatusCode):
        status_code = status_code.value
    return 200 <= status_code < 300

is_error_status_code

is_error_status_code(
    status_code: HTTPStatusCode | int,
) -> bool

Return True if the status code is an error code, False otherwise.

Source code in horde_sdk/consts.py
def is_error_status_code(status_code: HTTPStatusCode | int) -> bool:
    """Return True if the status code is an error code, False otherwise."""
    if isinstance(status_code, HTTPStatusCode):
        status_code = status_code.value
    return 400 <= status_code < 600

register_known_service_info

register_known_service_info(
    service_info: ServiceInfo,
) -> None

Register a known service info.

Parameters:

  • service_info (ServiceInfo) –

    The service info to register.

Raises:

  • ValueError

    If the service info is already registered.

Source code in horde_sdk/consts.py
def register_known_service_info(service_info: ServiceInfo) -> None:
    """Register a known service info.

    Args:
        service_info: The service info to register.

    Raises:
        ValueError: If the service info is already registered.
    """
    _known_service_infos[service_info.known_identifier] = service_info

get_known_service_info

get_known_service_info(
    service: KNOWN_SERVICE,
) -> ServiceInfo

Get the known service info for a given service.

Parameters:

Returns:

  • ServiceInfo ( ServiceInfo ) –

    The service info for the given service.

Source code in horde_sdk/consts.py
def get_known_service_info(service: KNOWN_SERVICE) -> ServiceInfo:
    """Get the known service info for a given service.

    Args:
        service: The known service.

    Returns:
        ServiceInfo: The service info for the given service.
    """
    try:
        service = KNOWN_SERVICE(service)
    except ValueError as e:
        raise ValueError("Invalid service type") from e

    return _known_service_infos.get(service, UnknownServiceInfo)