Get registered model
This example demonstrates how you can use the MLOps Python client to get the registered model for a given model 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. |
REGISTERED_MODEL_ID | Sets the registered model id. |
The following steps demonstrate how you can use the MLOps Python client to get the registered model for a given model id in MLOps.
Change the values of the following constants in your
GetRegisteredModel.py
file as given in the preceding data table.GetRegisteredModel.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>"
REGISTERED_MODEL_ID = "<your-model-id>"Run the
GetRegisteredModel.py
file.python3 GetRegisteredModel.py
This provides the registered model details for the model id you have specified.
{
"registeredModel" : {
"updatedTime" : "2000-01-23T04:56:07.000+00:00",
"updatedBy" : "updatedBy",
"createdBy" : "createdBy",
"displayName" : "displayName",
"description" : "description",
"createdTime" : "2000-01-23T04:56:07.000+00:00",
"id" : "id",
"projectId" : "projectId"
}
}
Example walkthrough
This section provides a walkthrough of the GetRegisteredModel.py
file.
Get the registered model for a given model id by calling the
GetRegisteredModel
endpoint of theRegisteredModelService
. The request for this API call is prepared by theget_registered_model_request
function, which specifies the model id.GetRegisteredModel.pydef get_registered_model(
mlops_client: mlops.Client,
get_model_request: mlops.StorageGetRegisteredModelRequest
):
return mlops_client.storage.registered_model.get_registered_model(
get_model_request
)
def get_registered_model_request(model_id):
return mlops.StorageGetRegisteredModelRequest(
model_id=model_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
get_registered_model
function with theREGISTERED_MODEL_ID
constant defined in the beginning of the script.GetRegisteredModel.pyget_model_response: mlops.StorageGetRegisteredModelResponse = get_registered_model(
mlops_client,
get_registered_model_request(
model_id=REGISTERED_MODEL_ID
)
)
print(get_model_response)
- Submit and view feedback for this page
- Send feedback about H2O MLOps to cloud-feedback@h2o.ai