Skip to content

Commit

Permalink
Merge pull request #276 from Haidra-Org/main
Browse files Browse the repository at this point in the history
fix: config default root models to allow new API fields
  • Loading branch information
tazlin authored Nov 3, 2024
2 parents eb20833 + bd64abe commit dd4a5fe
Show file tree
Hide file tree
Showing 46 changed files with 798 additions and 30 deletions.
2 changes: 2 additions & 0 deletions docs/horde_sdk/ai_horde_api/apimodels/_styles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# _styles
::: horde_sdk.ai_horde_api.apimodels._styles
21 changes: 21 additions & 0 deletions docs/response_field_names_and_descriptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,13 @@
"int",
"None"
]
},
"styles": {
"description": "The styles this user has created.",
"types": [
"list[horde_sdk.ai_horde_api.apimodels._styles.ResponseModelStylesUser]",
"None"
]
}
},
"HordePerformanceResponse": {
Expand Down Expand Up @@ -726,6 +733,13 @@
"list[str]",
"None"
]
},
"ttl": {
"description": "The amount of seconds before this job is considered stale and aborted.",
"types": [
"int",
"None"
]
}
},
"JobSubmitResponse": {
Expand Down Expand Up @@ -1308,6 +1322,13 @@
"str",
"None"
]
},
"ttl": {
"description": "The amount of seconds before this job is considered stale and aborted.",
"types": [
"int",
"None"
]
}
},
"TextStatsModelResponse": {
Expand Down
2 changes: 2 additions & 0 deletions horde_sdk/ai_horde_api/apimodels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
NewsRequest,
NewsResponse,
)
from horde_sdk.ai_horde_api.apimodels._styles import ResponseModelStylesUser
from horde_sdk.ai_horde_api.apimodels._users import (
ActiveGenerations,
ContributionsDetails,
Expand Down Expand Up @@ -210,6 +211,7 @@
"Newspiece",
"NewsRequest",
"NewsResponse",
"ResponseModelStylesUser",
"ListUsersDetailsRequest",
"ListUsersDetailsResponse",
"ModifyUser",
Expand Down
19 changes: 19 additions & 0 deletions horde_sdk/ai_horde_api/apimodels/_styles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from enum import auto

from pydantic import Field
from strenum import StrEnum

from horde_sdk.generic_api.apimodels import HordeAPIDataObject


class StyleType(StrEnum):
"""An enum representing the different types of styles."""

image = auto()
text = auto()


class ResponseModelStylesUser(HordeAPIDataObject):
name: str
id_: str = Field(alias="id")
type_: StyleType = Field(alias="type")
8 changes: 8 additions & 0 deletions horde_sdk/ai_horde_api/apimodels/_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pydantic import Field, RootModel
from typing_extensions import override

from horde_sdk.ai_horde_api.apimodels._styles import ResponseModelStylesUser
from horde_sdk.ai_horde_api.apimodels.base import BaseAIHordeRequest
from horde_sdk.ai_horde_api.endpoints import AI_HORDE_API_ENDPOINT_SUBPATH
from horde_sdk.ai_horde_api.fields import UUID_Identifier
Expand Down Expand Up @@ -52,6 +53,9 @@ class UserKudosDetails(HordeAPIDataObject):
recurring: float | None = Field(0)
"""The amount of Kudos this user has received from recurring rewards."""

styled: float | None = Field(0)
"""The amount of Kudos this user has received from styling images."""


class MonthlyKudos(HordeAPIDataObject):
amount: int | None = Field(default=None)
Expand Down Expand Up @@ -85,6 +89,7 @@ class UserRecords(HordeAPIDataObject):
fulfillment: UserAmountRecords | None = None
request: UserAmountRecords | None = None
usage: UserThingRecords | None = None
style: UserAmountRecords | None = None


class UsageDetails(HordeAPIDataObject):
Expand Down Expand Up @@ -264,6 +269,9 @@ def get_api_model_name(cls) -> str | None:
"""Whether this user has been invited to join a worker to the horde and how many of them.
When 0, this user cannot add (new) workers to the horde."""

styles: list[ResponseModelStylesUser] | None = None
"""The styles this user has created."""


@Unhashable
@Unequatable
Expand Down
4 changes: 3 additions & 1 deletion horde_sdk/ai_horde_api/apimodels/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ class ImageGenerateParamMixin(HordeAPIDataObject):
"""

model_config = (
ConfigDict(frozen=True) if not os.getenv("TESTS_ONGOING") else ConfigDict(frozen=True, extra="forbid")
ConfigDict(frozen=True, extra="allow")
if not os.getenv("TESTS_ONGOING")
else ConfigDict(frozen=True, extra="forbid")
)

sampler_name: KNOWN_SAMPLERS | str = KNOWN_SAMPLERS.k_lms
Expand Down
2 changes: 2 additions & 0 deletions horde_sdk/ai_horde_api/apimodels/generate/_pop.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ class ImageGenerateJobPopResponse(
"""(Obsolete) The r2 upload link to use to upload this image."""
r2_uploads: list[str] | None = None
"""The r2 upload links for each this image. Each index matches the ID in self.ids"""
ttl: int | None = None
"""The amount of seconds before this job is considered stale and aborted."""

@field_validator("source_processing")
def source_processing_must_be_known(cls, v: str | KNOWN_SOURCE_PROCESSING) -> str | KNOWN_SOURCE_PROCESSING:
Expand Down
2 changes: 2 additions & 0 deletions horde_sdk/ai_horde_api/apimodels/generate/text/_pop.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class TextGenerateJobPopResponse(
"""The soft prompt requested for this generation."""
model: str | None = Field(default=None)
"""The model requested for this generation."""
ttl: int | None = None
"""The amount of seconds before this job is considered stale and aborted."""

@field_validator("id_", mode="before")
def validate_id(cls, v: str | JobID) -> JobID | str:
Expand Down
5 changes: 4 additions & 1 deletion horde_sdk/generic_api/apimodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class HordeAPIDataObject(BaseModel):
ConfigDict(
frozen=True,
use_attribute_docstrings=True,
extra="allow",
)
if not os.getenv("TESTS_ONGOING")
else ConfigDict(
Expand Down Expand Up @@ -98,7 +99,9 @@ class HordeResponseBaseModel(HordeResponse, BaseModel):
"""Base class for all Horde API response data models (leveraging pydantic)."""

model_config = (
ConfigDict(frozen=True) if not os.getenv("TESTS_ONGOING") else ConfigDict(frozen=True, extra="forbid")
ConfigDict(frozen=True, extra="allow")
if not os.getenv("TESTS_ONGOING")
else ConfigDict(frozen=True, extra="forbid")
)


Expand Down
7 changes: 6 additions & 1 deletion horde_sdk/generic_api/utils/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,12 @@ def get_endpoint_method_examples(
# Iterate through each defined response for the HTTP method.
for http_status_code_str, response_definition in endpoint_method_definition.responses.items():
# Convert the HTTP status code string to an HTTPStatusCode object.
http_status_code_object = HTTPStatusCode(int(http_status_code_str))
try:
http_status_code_object = HTTPStatusCode(int(http_status_code_str))
except ValueError as e:
logger.error(f"Failed to convert {http_status_code_str} to an HTTPStatusCode object: {e}")
logger.error(f"response_definition: {response_definition}")
raise

# Get the response example for this HTTP status code.
example_response = self.get_response_example(response_definition)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "My Awesome Collection",
"info": "Collection of optimistic styles",
"public": true,
"styles": [
"a"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "My Awesome Collection",
"info": "Collection of optimistic styles",
"public": true,
"styles": [
"a"
]
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
{
"prompt": "a",
"params": {
"sampler_name": "dpmsolver",
"sampler_name": "k_euler",
"cfg_scale": 7.5,
"denoising_strength": 0.75,
"hires_fix_denoising_strength": 0.75,
"seed": "The little seed that could",
"height": 512,
"width": 512,
"seed_variation": 1,
"post_processing": [
"GFPGAN"
],
"karras": false,
"tiling": false,
"hires_fix": false,
"clip_skip": 1,
"control_type": "canny",
"image_is_control": false,
"return_control_map": false,
"facefixer_strength": 0.75,
"loras": [
{
Expand All @@ -41,14 +36,19 @@
"additionalProp2": {},
"additionalProp3": {}
},
"workflow": "qr_code",
"transparent": false,
"seed": "The little seed that could",
"seed_variation": 1,
"control_type": "canny",
"image_is_control": false,
"return_control_map": false,
"extra_texts": [
{
"text": "a",
"reference": "aaa"
}
],
"workflow": "qr_code",
"transparent": false,
"steps": 30,
"n": 1
},
Expand Down Expand Up @@ -81,5 +81,6 @@
"proxied_account": "",
"disable_batching": false,
"allow_downgrade": false,
"webhook": "https://haidra.net/00000000-0000-0000-0000-000000000000"
"webhook": "https://haidra.net/00000000-0000-0000-0000-000000000000",
"style": "00000000-0000-0000-0000-000000000000"
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
{
"prompt": "",
"params": {
"n": 1,
"frmtadsnsp": false,
"frmtrmblln": false,
"frmtrmspch": false,
"frmttriminc": false,
"max_context_length": 1024,
"max_length": 80,
"rep_pen": 1.0,
"rep_pen_range": 0.0,
"rep_pen_slope": 0.0,
Expand All @@ -28,7 +25,10 @@
"min_p": 0.0,
"smoothing_factor": 0.0,
"dynatemp_range": 0.0,
"dynatemp_exponent": 1.0
"dynatemp_exponent": 1.0,
"n": 1,
"max_context_length": 1024,
"max_length": 80
},
"softprompt": "a",
"trusted_workers": false,
Expand All @@ -52,5 +52,6 @@
"disable_batching": false,
"allow_downgrade": false,
"webhook": "",
"style": "00000000-0000-0000-0000-000000000000",
"extra_slow_workers": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "My Awesome Image Style",
"info": "photorealism excellence.",
"prompt": "{p}{np}",
"params": {
"sampler_name": "k_euler",
"cfg_scale": 7.5,
"denoising_strength": 0.75,
"hires_fix_denoising_strength": 0.75,
"height": 512,
"width": 512,
"post_processing": [
"GFPGAN"
],
"karras": false,
"tiling": false,
"hires_fix": false,
"clip_skip": 1,
"facefixer_strength": 0.75,
"loras": [
{
"name": "Magnagothica",
"model": 1.0,
"clip": 1.0,
"inject_trigger": "a",
"is_version": false
}
],
"tis": [
{
"name": "7808",
"inject_ti": "prompt",
"strength": 1.0
}
],
"special": {
"additionalProp1": {},
"additionalProp2": {},
"additionalProp3": {}
},
"workflow": "qr_code",
"transparent": false,
"steps": 30
},
"public": true,
"nsfw": false,
"tags": [
"photorealistic"
],
"models": [
"stable_diffusion"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"url": "https://lemmy.dbzer0.com/pictrs/image/c9915186-ca30-4f5a-873c-a91287fb4419.webp",
"primary": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"url": "https://lemmy.dbzer0.com/pictrs/image/c9915186-ca30-4f5a-873c-a91287fb4419.webp",
"primary": false
}
Loading

0 comments on commit dd4a5fe

Please sign in to comment.