-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- See Haidra-Org/AI-Horde#416 for more info.
- Loading branch information
Showing
12 changed files
with
251 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# _documents | ||
::: horde_sdk.ai_horde_api.apimodels._documents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
from loguru import logger | ||
from pydantic import field_validator | ||
from strenum import StrEnum | ||
from typing_extensions import override | ||
|
||
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.consts import HTTPMethod | ||
from horde_sdk.generic_api.apimodels import ( | ||
HordeAPIObject, | ||
HordeResponseBaseModel, | ||
) | ||
|
||
|
||
class DocumentFormat(StrEnum): | ||
html = "html" | ||
markdown = "markdown" | ||
|
||
|
||
class HordeDocument(HordeResponseBaseModel): | ||
html: str | None = None | ||
"""The HTML content of the document, if requested.""" | ||
markdown: str | None = None | ||
"""The markdown content of the document, if requested.""" | ||
|
||
@override | ||
@classmethod | ||
def get_api_model_name(cls) -> str: | ||
return "HordeDocument" | ||
|
||
|
||
class AIHordeDocumentRequestMixin(HordeAPIObject): | ||
format: DocumentFormat | str = DocumentFormat.html | ||
|
||
"""The format of the document to return. Default is markdown.""" | ||
|
||
@field_validator("format") | ||
def validate_format(cls, value: DocumentFormat | str) -> DocumentFormat | str: | ||
if isinstance(value, DocumentFormat): | ||
return value | ||
|
||
try: | ||
DocumentFormat(value) | ||
except ValueError: | ||
logger.warning(f"Unknown document format: {value}. Is your SDK out of date or did the API change?") | ||
|
||
return value | ||
|
||
|
||
class AIHordeGetPrivacyPolicyRequest(BaseAIHordeRequest, AIHordeDocumentRequestMixin): | ||
|
||
@override | ||
@classmethod | ||
def get_api_model_name(cls) -> str | None: | ||
return None | ||
|
||
@override | ||
@classmethod | ||
def get_http_method(cls) -> HTTPMethod: | ||
return HTTPMethod.GET | ||
|
||
@override | ||
@classmethod | ||
def get_api_endpoint_subpath(cls) -> AI_HORDE_API_ENDPOINT_SUBPATH: | ||
return AI_HORDE_API_ENDPOINT_SUBPATH.v2_documents_privacy | ||
|
||
@override | ||
@classmethod | ||
def get_default_success_response_type(cls) -> type[HordeDocument]: | ||
return HordeDocument | ||
|
||
|
||
class AIHordeGetSponsorsRequest(BaseAIHordeRequest, AIHordeDocumentRequestMixin): | ||
|
||
@override | ||
@classmethod | ||
def get_api_model_name(cls) -> str | None: | ||
return None | ||
|
||
@override | ||
@classmethod | ||
def get_http_method(cls) -> HTTPMethod: | ||
return HTTPMethod.GET | ||
|
||
@override | ||
@classmethod | ||
def get_api_endpoint_subpath(cls) -> AI_HORDE_API_ENDPOINT_SUBPATH: | ||
return AI_HORDE_API_ENDPOINT_SUBPATH.v2_documents_sponsors | ||
|
||
@override | ||
@classmethod | ||
def get_default_success_response_type(cls) -> type[HordeDocument]: | ||
return HordeDocument | ||
|
||
|
||
class AIHordeGetTermsRequest(BaseAIHordeRequest, AIHordeDocumentRequestMixin): | ||
|
||
@override | ||
@classmethod | ||
def get_api_model_name(cls) -> str | None: | ||
return None | ||
|
||
@override | ||
@classmethod | ||
def get_http_method(cls) -> HTTPMethod: | ||
return HTTPMethod.GET | ||
|
||
@override | ||
@classmethod | ||
def get_api_endpoint_subpath(cls) -> AI_HORDE_API_ENDPOINT_SUBPATH: | ||
return AI_HORDE_API_ENDPOINT_SUBPATH.vs_documents_terms | ||
|
||
@override | ||
@classmethod | ||
def get_default_success_response_type(cls) -> type[HordeDocument]: | ||
return HordeDocument |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
tests/test_data/ai_horde_api/example_responses/_v2_documents_privacy_get_200.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"html": "", | ||
"markdown": "" | ||
} |
4 changes: 4 additions & 0 deletions
4
tests/test_data/ai_horde_api/example_responses/_v2_documents_sponsors_get_200.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"html": "", | ||
"markdown": "" | ||
} |
4 changes: 4 additions & 0 deletions
4
tests/test_data/ai_horde_api/example_responses/_v2_documents_terms_get_200.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"html": "", | ||
"markdown": "" | ||
} |