diff --git a/docs/api_to_sdk_map.md b/docs/api_to_sdk_map.md index 2bb9a35..8f9acf7 100644 --- a/docs/api_to_sdk_map.md +++ b/docs/api_to_sdk_map.md @@ -4,6 +4,9 @@ This is a mapping of the AI-Horde API models (defined at [https://stablehorde.ne ## Payloads | API Endpoint | HTTP Method | SDK Request Type | | ------------ | ----------- | ---------------- | +| /v2/documents/privacy | GET | [AIHordeGetPrivacyPolicyRequest][horde_sdk.ai_horde_api.apimodels._documents.AIHordeGetPrivacyPolicyRequest] | +| /v2/documents/sponsors | GET | [AIHordeGetSponsorsRequest][horde_sdk.ai_horde_api.apimodels._documents.AIHordeGetSponsorsRequest] | +| /v2/documents/terms | GET | [AIHordeGetTermsRequest][horde_sdk.ai_horde_api.apimodels._documents.AIHordeGetTermsRequest] | | /v2/find_user | GET | [FindUserRequest][horde_sdk.ai_horde_api.apimodels._find_user.FindUserRequest] | | /v2/generate/async | POST | [ImageGenerateAsyncRequest][horde_sdk.ai_horde_api.apimodels.generate._async.ImageGenerateAsyncRequest] | | /v2/generate/check/{id} | GET | [ImageGenerateCheckRequest][horde_sdk.ai_horde_api.apimodels.generate._check.ImageGenerateCheckRequest] | @@ -43,6 +46,9 @@ This is a mapping of the AI-Horde API models (defined at [https://stablehorde.ne ## Responses | API Endpoint | HTTP Status Code | SDK Response Type | | ------------ | ----------- | ----------------- | +| /v2/documents/privacy | 200 | [HordeDocument][horde_sdk.ai_horde_api.apimodels._documents.HordeDocument] | +| /v2/documents/sponsors | 200 | [HordeDocument][horde_sdk.ai_horde_api.apimodels._documents.HordeDocument] | +| /v2/documents/terms | 200 | [HordeDocument][horde_sdk.ai_horde_api.apimodels._documents.HordeDocument] | | /v2/find_user | 200 | [UserDetailsResponse][horde_sdk.ai_horde_api.apimodels._users.UserDetailsResponse] | | /v2/generate/async | 200 | [ImageGenerateAsyncDryRunResponse][horde_sdk.ai_horde_api.apimodels.generate._async.ImageGenerateAsyncDryRunResponse] | | /v2/generate/async | 202 | [ImageGenerateAsyncResponse][horde_sdk.ai_horde_api.apimodels.generate._async.ImageGenerateAsyncResponse] | diff --git a/docs/api_to_sdk_payload_map.json b/docs/api_to_sdk_payload_map.json index d0a0b40..be61ee9 100644 --- a/docs/api_to_sdk_payload_map.json +++ b/docs/api_to_sdk_payload_map.json @@ -1,4 +1,13 @@ { + "/v2/documents/privacy": { + "GET": "horde_sdk.ai_horde_api.apimodels._documents.AIHordeGetPrivacyPolicyRequest" + }, + "/v2/documents/sponsors": { + "GET": "horde_sdk.ai_horde_api.apimodels._documents.AIHordeGetSponsorsRequest" + }, + "/v2/documents/terms": { + "GET": "horde_sdk.ai_horde_api.apimodels._documents.AIHordeGetTermsRequest" + }, "/v2/status/heartbeat": { "GET": "horde_sdk.ai_horde_api.apimodels._status.AIHordeHeartbeatRequest" }, diff --git a/docs/api_to_sdk_response_map.json b/docs/api_to_sdk_response_map.json index 6cec4ce..b991944 100644 --- a/docs/api_to_sdk_response_map.json +++ b/docs/api_to_sdk_response_map.json @@ -1,4 +1,13 @@ { + "/v2/documents/privacy": { + "200": "horde_sdk.ai_horde_api.apimodels._documents.HordeDocument" + }, + "/v2/documents/sponsors": { + "200": "horde_sdk.ai_horde_api.apimodels._documents.HordeDocument" + }, + "/v2/documents/terms": { + "200": "horde_sdk.ai_horde_api.apimodels._documents.HordeDocument" + }, "/v2/status/heartbeat": { "200": "horde_sdk.ai_horde_api.apimodels._status.AIHordeHeartbeatResponse" }, diff --git a/docs/horde_sdk/ai_horde_api/apimodels/_documents.md b/docs/horde_sdk/ai_horde_api/apimodels/_documents.md new file mode 100644 index 0000000..5ccea2f --- /dev/null +++ b/docs/horde_sdk/ai_horde_api/apimodels/_documents.md @@ -0,0 +1,2 @@ +# _documents +::: horde_sdk.ai_horde_api.apimodels._documents diff --git a/docs/request_field_names_and_descriptions.json b/docs/request_field_names_and_descriptions.json index 7f0bbbc..5465e95 100644 --- a/docs/request_field_names_and_descriptions.json +++ b/docs/request_field_names_and_descriptions.json @@ -1,4 +1,67 @@ { + "AIHordeGetPrivacyPolicyRequest": { + "format": { + "description": "The format of the document to return. Default is markdown.", + "types": [ + "horde_sdk.ai_horde_api.apimodels._documents.DocumentFormat", + "str" + ] + }, + "accept": { + "description": "The 'accept' header field.", + "types": [ + "horde_sdk.generic_api.metadata.GenericAcceptTypes" + ] + }, + "client_agent": { + "description": "The requesting client's agent. You should set this to reflect the name, version and contact information\nfor your client.", + "types": [ + "str" + ] + } + }, + "AIHordeGetSponsorsRequest": { + "format": { + "description": "The format of the document to return. Default is markdown.", + "types": [ + "horde_sdk.ai_horde_api.apimodels._documents.DocumentFormat", + "str" + ] + }, + "accept": { + "description": "The 'accept' header field.", + "types": [ + "horde_sdk.generic_api.metadata.GenericAcceptTypes" + ] + }, + "client_agent": { + "description": "The requesting client's agent. You should set this to reflect the name, version and contact information\nfor your client.", + "types": [ + "str" + ] + } + }, + "AIHordeGetTermsRequest": { + "format": { + "description": "The format of the document to return. Default is markdown.", + "types": [ + "horde_sdk.ai_horde_api.apimodels._documents.DocumentFormat", + "str" + ] + }, + "accept": { + "description": "The 'accept' header field.", + "types": [ + "horde_sdk.generic_api.metadata.GenericAcceptTypes" + ] + }, + "client_agent": { + "description": "The requesting client's agent. You should set this to reflect the name, version and contact information\nfor your client.", + "types": [ + "str" + ] + } + }, "AIHordeHeartbeatRequest": { "accept": { "description": "The 'accept' header field.", diff --git a/docs/response_field_names_and_descriptions.json b/docs/response_field_names_and_descriptions.json index a559a9c..207d5fe 100644 --- a/docs/response_field_names_and_descriptions.json +++ b/docs/response_field_names_and_descriptions.json @@ -1,4 +1,20 @@ { + "HordeDocument": { + "html": { + "description": "The HTML content of the document, if requested.", + "types": [ + "str", + "None" + ] + }, + "markdown": { + "description": "The markdown content of the document, if requested.", + "types": [ + "str", + "None" + ] + } + }, "AIHordeHeartbeatResponse": { "message": { "description": "A message from the API. This is typically an error or warning message, but may also be informational.", diff --git a/horde_sdk/ai_horde_api/apimodels/__init__.py b/horde_sdk/ai_horde_api/apimodels/__init__.py index 226a027..8c9e52e 100644 --- a/horde_sdk/ai_horde_api/apimodels/__init__.py +++ b/horde_sdk/ai_horde_api/apimodels/__init__.py @@ -1,5 +1,13 @@ """All requests, responses and API models defined for the AI Horde API.""" +from horde_sdk.ai_horde_api.apimodels._documents import ( + AIHordeDocumentRequestMixin, + AIHordeGetPrivacyPolicyRequest, + AIHordeGetSponsorsRequest, + AIHordeGetTermsRequest, + DocumentFormat, + HordeDocument, +) from horde_sdk.ai_horde_api.apimodels._find_user import ( FindUserRequest, ) @@ -167,6 +175,12 @@ ) __all__ = [ + "AIHordeDocumentRequestMixin", + "AIHordeGetPrivacyPolicyRequest", + "AIHordeGetSponsorsRequest", + "AIHordeGetTermsRequest", + "DocumentFormat", + "HordeDocument", "ContributionsDetails", "FindUserRequest", "KudosTransferRequest", diff --git a/horde_sdk/ai_horde_api/apimodels/_documents.py b/horde_sdk/ai_horde_api/apimodels/_documents.py new file mode 100644 index 0000000..54c7858 --- /dev/null +++ b/horde_sdk/ai_horde_api/apimodels/_documents.py @@ -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 diff --git a/horde_sdk/ai_horde_api/endpoints.py b/horde_sdk/ai_horde_api/endpoints.py index b84a9da..6314e12 100644 --- a/horde_sdk/ai_horde_api/endpoints.py +++ b/horde_sdk/ai_horde_api/endpoints.py @@ -92,6 +92,10 @@ class AI_HORDE_API_ENDPOINT_SUBPATH(GENERIC_API_ENDPOINT_SUBPATH): v2_operations_ipaddr = "/v2/operations/ipaddr" v2_operations_ipaddr_single = "/v2/operations/ipaddr/{ipaddr}" + v2_documents_privacy = "/v2/documents/privacy" + v2_documents_sponsors = "/v2/documents/sponsors" + vs_documents_terms = "/v2/documents/terms" + def get_ai_horde_swagger_url() -> str: """Get the URL for the AI Horde API swagger docs.""" diff --git a/tests/test_data/ai_horde_api/example_responses/_v2_documents_privacy_get_200.json b/tests/test_data/ai_horde_api/example_responses/_v2_documents_privacy_get_200.json new file mode 100644 index 0000000..afb3ed8 --- /dev/null +++ b/tests/test_data/ai_horde_api/example_responses/_v2_documents_privacy_get_200.json @@ -0,0 +1,4 @@ +{ + "html": "", + "markdown": "" +} diff --git a/tests/test_data/ai_horde_api/example_responses/_v2_documents_sponsors_get_200.json b/tests/test_data/ai_horde_api/example_responses/_v2_documents_sponsors_get_200.json new file mode 100644 index 0000000..afb3ed8 --- /dev/null +++ b/tests/test_data/ai_horde_api/example_responses/_v2_documents_sponsors_get_200.json @@ -0,0 +1,4 @@ +{ + "html": "", + "markdown": "" +} diff --git a/tests/test_data/ai_horde_api/example_responses/_v2_documents_terms_get_200.json b/tests/test_data/ai_horde_api/example_responses/_v2_documents_terms_get_200.json new file mode 100644 index 0000000..afb3ed8 --- /dev/null +++ b/tests/test_data/ai_horde_api/example_responses/_v2_documents_terms_get_200.json @@ -0,0 +1,4 @@ +{ + "html": "", + "markdown": "" +}