Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct logic for KNOWN_CONTROLNET check #136

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions horde_sdk/ai_horde_api/apimodels/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,12 @@ def control_type_must_be_known(cls, v: str | KNOWN_CONTROLNETS | None) -> str |
"""Ensure that the control type is in this list of supported control types."""
if v is None:
return None
if (isinstance(v, str) and v not in KNOWN_CONTROLNETS.__members__) or (not isinstance(v, KNOWN_CONTROLNETS)):
logger.warning(f"Unknown control type '{v}'. Is your SDK out of date or did the API change?")
if isinstance(v, KNOWN_CONTROLNETS):
return v
if v in KNOWN_CONTROLNETS.__members__:
return v

logger.warning(f"Unknown control type {v}. Is your SDK out of date or did the API change?")
return v


Expand Down
24 changes: 24 additions & 0 deletions tests/ai_horde_api/test_ai_horde_api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
WorkerKudosDetails,
)
from horde_sdk.ai_horde_api.consts import (
KNOWN_CONTROLNETS,
KNOWN_FACEFIXERS,
KNOWN_SAMPLERS,
KNOWN_SOURCE_PROCESSING,
Expand Down Expand Up @@ -375,6 +376,29 @@ def test_ImageGenerateJobPopResponse() -> None:
),
skipped=ImageGenerateJobPopSkippedStatus(),
)
test_response = ImageGenerateJobPopResponse(
id=None,
ids=[JobID(root=UUID("00000000-0000-0000-0000-000000000000"))],
payload=ImageGenerateJobPopPayload(
post_processing=["unknown post processor"],
control_type=KNOWN_CONTROLNETS.canny,
sampler_name="unknown sampler",
prompt="A cat in a hat",
),
skipped=ImageGenerateJobPopSkippedStatus(),
)
test_response = ImageGenerateJobPopResponse(
id=None,
ids=[JobID(root=UUID("00000000-0000-0000-0000-000000000000"))],
payload=ImageGenerateJobPopPayload(
post_processing=["unknown post processor"],
control_type="canny",
sampler_name="unknown sampler",
prompt="A cat in a hat",
),
skipped=ImageGenerateJobPopSkippedStatus(),
)

test_response = ImageGenerateJobPopResponse(
id=None,
ids=[JobID(root=UUID("00000000-0000-0000-0000-000000000000"))],
Expand Down
Loading