Skip to content

Commit 517a6e8

Browse files
committed
fix: add+update docstrings for API models and requests
- Fixes docstring test to properly identify and correct docstrings for API models - Fixes missing docstrings in API models
1 parent 99833fd commit 517a6e8

File tree

4 files changed

+59
-16
lines changed

4 files changed

+59
-16
lines changed

horde_sdk/ai_horde_api/apimodels/documents.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ class DocumentFormat(StrEnum):
1919

2020

2121
class HordeDocument(HordeResponseBaseModel):
22+
"""Represents the data returned from the following endpoints and http status codes:
23+
- /v2/documents/terms | AIHordeGetTermsRequest [GET] -> 200
24+
- /v2/documents/sponsors | AIHordeGetSponsorsRequest [GET] -> 200
25+
- /v2/documents/privacy | AIHordeGetPrivacyPolicyRequest [GET] -> 200
26+
27+
v2 API Model: `HordeDocument`
28+
"""
29+
2230
html: str | None = None
2331
"""The HTML content of the document, if requested."""
2432
markdown: str | None = None
@@ -50,6 +58,8 @@ def validate_format(cls, value: DocumentFormat | str) -> DocumentFormat | str:
5058

5159

5260
class AIHordeGetPrivacyPolicyRequest(BaseAIHordeRequest, AIHordeDocumentRequestMixin):
61+
"""Represents a GET request to the /v2/documents/privacy endpoint."""
62+
5363
@override
5464
@classmethod
5565
def get_api_model_name(cls) -> str | None:
@@ -72,6 +82,8 @@ def get_default_success_response_type(cls) -> type[HordeDocument]:
7282

7383

7484
class AIHordeGetSponsorsRequest(BaseAIHordeRequest, AIHordeDocumentRequestMixin):
85+
"""Represents a GET request to the /v2/documents/sponsors endpoint."""
86+
7587
@override
7688
@classmethod
7789
def get_api_model_name(cls) -> str | None:
@@ -94,6 +106,8 @@ def get_default_success_response_type(cls) -> type[HordeDocument]:
94106

95107

96108
class AIHordeGetTermsRequest(BaseAIHordeRequest, AIHordeDocumentRequestMixin):
109+
"""Represents a GET request to the /v2/documents/terms endpoint."""
110+
97111
@override
98112
@classmethod
99113
def get_api_model_name(cls) -> str | None:

horde_sdk/ai_horde_api/apimodels/generate/text/async_.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ class ModelGenerationInputKobold(ModelPayloadRootKobold):
208208

209209

210210
class TextGenerateAsyncDryRunResponse(HordeResponseBaseModel):
211+
"""Represents the data returned from the /v2/generate/text/async endpoint with http status code 200.
212+
213+
v2 API Model: `_ANONYMOUS_MODEL`
214+
"""
215+
211216
kudos: float
212217
"""The expected kudos consumption for this request."""
213218

@@ -223,7 +228,7 @@ class TextGenerateAsyncRequest(
223228
APIKeyAllowedInRequestMixin,
224229
RequestUsesWorkerMixin,
225230
):
226-
"""Represents the data needed to make a request to the `/v2/generate/async` endpoint.
231+
"""Represents a POST request to the /v2/generate/text/async endpoint.
227232
228233
v2 API Model: `GenerationInputKobold`
229234
"""

horde_sdk/ai_horde_api/apimodels/users.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class ContributionsDetails(HordeAPIObjectBaseModel):
2323
"""How many images and megapixelsteps this user has generated.
2424
25-
v2 API Model: ContributionsDetails
25+
v2 API Model: `ContributionsDetails`
2626
"""
2727

2828
fulfillments: int | None = Field(
@@ -43,7 +43,7 @@ def get_api_model_name(cls) -> str | None:
4343
class UserKudosDetails(HordeAPIObjectBaseModel):
4444
"""The details of the kudos this user has accumulated, used, sent and received.
4545
46-
v2 API Model: UserKudosDetails
46+
v2 API Model: `UserKudosDetails`
4747
"""
4848

4949
accumulated: float | None = Field(0)
@@ -79,7 +79,7 @@ def get_api_model_name(cls) -> str | None:
7979
class MonthlyKudos(HordeAPIObjectBaseModel):
8080
"""The details of the monthly kudos this user receives.
8181
82-
v2 API Model: MonthlyKudos
82+
v2 API Model: `MonthlyKudos`
8383
"""
8484

8585
amount: int | None = Field(default=None)
@@ -97,7 +97,7 @@ def get_api_model_name(cls) -> str | None:
9797
class UserThingRecords(HordeAPIObjectBaseModel):
9898
"""How many images, texts, megapixelsteps and tokens this user has generated or requested.
9999
100-
v2 API Model: UserThingRecords
100+
v2 API Model: `UserThingRecords`
101101
"""
102102

103103
megapixelsteps: float | None = Field(0)
@@ -115,7 +115,7 @@ def get_api_model_name(cls) -> str | None:
115115
class UserAmountRecords(HordeAPIObjectBaseModel):
116116
"""How many images, texts, megapixelsteps and tokens this user has generated or requested.
117117
118-
v2 API Model: UserAmountRecords
118+
v2 API Model: `UserAmountRecords`
119119
"""
120120

121121
image: int | None = Field(0)
@@ -136,7 +136,7 @@ def get_api_model_name(cls) -> str | None:
136136
class UserRecords(HordeAPIObjectBaseModel):
137137
"""How many images, texts, megapixelsteps, tokens and styles this user has generated, requested or has had used.
138138
139-
v2 API Model: UserRecords
139+
v2 API Model: `UserRecords`
140140
"""
141141

142142
contribution: UserThingRecords | None = None
@@ -159,7 +159,7 @@ def get_api_model_name(cls) -> str | None:
159159
class UsageDetails(HordeAPIObjectBaseModel):
160160
"""How many images and megapixelsteps this user has requested.
161161
162-
v2 API Model: UsageDetails
162+
v2 API Model: `UsageDetails`
163163
"""
164164

165165
megapixelsteps: float | None = Field(default=None)
@@ -179,7 +179,7 @@ def get_api_model_name(cls) -> str | None:
179179
class ActiveGenerations(HordeAPIObjectBaseModel):
180180
"""A list of generations that are currently active for this user.
181181
182-
v2 API Model: ActiveGenerations
182+
v2 API Model: `ActiveGenerations`
183183
"""
184184

185185
"""A list of generations that are currently active for this user."""
@@ -380,7 +380,9 @@ def get_api_model_name(cls) -> str | None:
380380
class ListUsersDetailsResponse(HordeResponseRootModel[list[UserDetailsResponse]]):
381381
"""The response for a list of user details.
382382
383-
v2 API Model: _ANONYMOUS_MODEL
383+
Represents the data returned from the /v2/users endpoint with http status code 200.
384+
385+
v2 API Model: `_ANONYMOUS_MODEL`
384386
"""
385387

386388
root: list[UserDetailsResponse]
@@ -393,7 +395,10 @@ def get_api_model_name(cls) -> str:
393395

394396

395397
class ListUsersDetailsRequest(BaseAIHordeRequest):
396-
"""Represents a request to list all users."""
398+
"""Represents a request to list all users.
399+
400+
Represents a GET request to the /v2/users endpoint.
401+
"""
397402

398403
page: int
399404
"""The page number to request. There are up to 25 users per page."""
@@ -427,7 +432,9 @@ def get_query_fields(cls) -> list[str]:
427432
return ["page", "sort"]
428433

429434

430-
class SingleUserDetailsRequest(BaseAIHordeRequest, RequestSpecifiesUserIDMixin):
435+
class SingleUserDetailsRequest(BaseAIHordeRequest, MessageSpecifiesUserIDMixin):
436+
"""Represents a GET request to the /v2/users/{user_id} endpoint."""
437+
431438
@override
432439
@classmethod
433440
def get_api_model_name(cls) -> None:
@@ -571,6 +578,11 @@ class ModifyUserReply(_ModifyUserBase):
571578

572579

573580
class ModifyUserResponse(HordeResponseBaseModel, ModifyUserReply):
581+
"""Represents the data returned from the /v2/users/{user_id} endpoint with http status code 200.
582+
583+
v2 API Model: `ModifyUser`
584+
"""
585+
574586
@override
575587
@classmethod
576588
def get_api_model_name(cls) -> str:
@@ -583,6 +595,11 @@ class ModifyUserRequest(
583595
ModifyUser,
584596
APIKeyAllowedInRequestMixin,
585597
):
598+
"""Represents a PUT request to the /v2/users/{user_id} endpoint.
599+
600+
v2 API Model: `ModifyUserInput`
601+
"""
602+
586603
@override
587604
@classmethod
588605
def get_api_model_name(cls) -> str:

horde_sdk/meta.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,17 +514,24 @@ def process_response(response_request_infos: list[FoundResponseInfo]) -> None:
514514
def process_other(class_type: type[HordeAPIObject]) -> None:
515515
api_model_name = class_type.get_api_model_name()
516516

517-
expected_other_docstring = v2_api_model_template.format(api_model=api_model_name)
517+
expected_suffix = v2_api_model_template.format(api_model=api_model_name)
518518

519519
if not class_type.__doc__:
520520
return
521521

522522
original_other_docstring = class_type.__doc__.rstrip()
523523
original_other_docstring = original_other_docstring.replace("\n\n ", "\n\n")
524524

525-
expected_other_docstring = expected_other_docstring.replace("\n\n ", "\n\n")
526-
if not original_other_docstring.endswith(expected_other_docstring):
527-
non_conforming_other[class_type] = (class_type.__doc__, expected_other_docstring)
525+
expected_suffix_normalized = expected_suffix.replace("\n\n ", "\n\n")
526+
if not original_other_docstring.endswith(expected_suffix_normalized):
527+
# Extract the description portion (everything before any "v2 API Model:" line)
528+
# to construct the full expected docstring
529+
description_part = original_other_docstring
530+
if "\n\nv2 API Model:" in original_other_docstring:
531+
description_part = original_other_docstring.split("\n\nv2 API Model:")[0]
532+
533+
full_expected_docstring = description_part + expected_suffix_normalized
534+
non_conforming_other[class_type] = (original_other_docstring, full_expected_docstring)
528535

529536
_sorted_all_classes = sorted(all_classes, key=lambda x: x.__name__)
530537
_sorted_all_classes.reverse()

0 commit comments

Comments
 (0)