Skip to content

Commit

Permalink
docs: find_user example
Browse files Browse the repository at this point in the history
  • Loading branch information
tazlin committed Oct 15, 2023
1 parent 0e37e3c commit 55aec90
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions examples/ai_horde_client/find_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import argparse

from horde_sdk import RequestErrorResponse
from horde_sdk.ai_horde_api.ai_horde_clients import AIHordeAPIManualClient
from horde_sdk.ai_horde_api.apimodels import FindUserRequest, FindUserResponse


def find_user_example(
api_key: str,
client: AIHordeAPIManualClient,
) -> None:
find_user_request = FindUserRequest(
apikey=api_key,
)

find_user_response: FindUserResponse | RequestErrorResponse
find_user_response = client.submit_request(find_user_request, expected_response_type=FindUserResponse)

if isinstance(find_user_response, RequestErrorResponse):
print(f"Error: {find_user_response.message}")
else:
print(f"User found: {find_user_response.id_}")

print()
print(find_user_response.model_dump_json(indent=4))


if __name__ == "__main__":
# Add the api key argument with argparse
parser = argparse.ArgumentParser()
parser.add_argument("--api_key", type=str, required=True)
args = parser.parse_args()

# Create the client
client = AIHordeAPIManualClient()

# Run the example
find_user_example(api_key=args.api_key, client=client)

0 comments on commit 55aec90

Please sign in to comment.