Count registered models
This example demonstrates how you can use the MLOps Python client to count the number of registered models for a given project id using the RegisteredModelService
of the MLOps API.
You will need the values for the following constants in order to successfully carry out the task. Contact your administrator to obtain deployment specific values.
Constant | Description |
---|---|
MLOPS_API_URL | Defines the URL for the MLOps gateway component. Usually: https://api.mlops.my.domain |
TOKEN_ENDPOINT_URL | Defines the token endpoint URL of the identity provider. This uses Keycloak as the identity provider. Keycloak realm should be provided. |
REFRESH_TOKEN | Defines the user's refresh token. |
CLIENT_ID | Sets the client id for authentication. This is the client you will be using to connect to MLOps. |
CLIENT_SECRET | Sets the client secret for authentication. |
PROJECT_ID | Sets the project id. |
The following steps demonstrate how you can use the MLOps Python client to to count the number of registered models for a given project in MLOps.
Change the values of the following constants in your
CountRegisteredModels.py
file as given in the preceding data table.CountRegisteredModels.py### Constants
MLOPS_API_URL = "https://api.mlops.my.domain"
TOKEN_ENDPOINT_URL="https://mlops.keycloak.domain/auth/realms/[fill-in-realm-name]/protocol/openid-connect/token"
REFRESH_TOKEN="<your-refresh-token>"
CLIENT_ID="<your-mlops-client>"
CLIENT_SECRET = "<your-client-secret>"
PROJECT_ID = "<your-project-id>"Run the
CountRegisteredModels.py
file.python3 CountRegisteredModels.py
This provides the number of registered models in the project you have specified.
{
"registeredModelCount" : 3
}
Example walkthrough
This section provides a walkthrough of the CountRegisteredModels.py
file.
Count the number of registered models for a given project id by calling the
CreateModelVersion
endpoint of theRegisteredModelVersionService
. The request for this API call is prepared by theget_count_registered_model_request
function, which specifies the project id.CountRegisteredModels.pydef count_registered_models(
mlops_client: mlops.Client,
count_model_request: mlops.StorageCountRegisteredModelRequest
):
return mlops_client.storage.registered_model.count_registered_models(
count_model_request
)
def get_count_registered_model_request(project_id):
return mlops.StorageCountRegisteredModelRequest(
project_id=project_id
)In the main function, set up the token provider using an existing refresh token and client secret, and then set up the MLOps client.
Call the
count_registered_models
function with thePROJECT_ID
constant defined in the beginning of the script.CountRegisteredModels.pycount_model_response: mlops.StorageCountRegisteredModelResponse = count_registered_models(
mlops_client,
get_count_registered_model_request(
project_id=PROJECT_ID
)
)
print(count_model_response)
- Submit and view feedback for this page
- Send feedback about H2O MLOps to cloud-feedback@h2o.ai