Create registered model
This example demonstrates how you can use the MLOps Python client to create a registered model 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 | Defines a project, new or existing, that the script will be using. |
MODEL_DISPLAY_NAME | Defines the model display name. |
MODEL_DESCRIPTION | Defines the model description. |
The following steps demonstrate how you can use the MLOps Python client to create a registered model in MLOps.
Change the values of the following constants in your
CreateRegisteredModel.py
file as given in the preceding data table.CreateRegisteredModel.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>"
MODEL_DISPLAY_NAME = "<your-model-name>"
MODEL_DESCRIPTION = "<your-model-description>"Run the
CreateRegisteredModel.py
file.python3 CreateRegisteredModel.py
This creates a registered model in the project 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 CreateRegisteredModel.py
file.
Create a registered model by calling the
CreateRegisteredModel
endpoint of theRegisteredModelService
. The request for this API call is prepared by thecreate_registered_model_request
function, which specifies the model display name, description and project id.CreateRegisteredModel.pydef create_registered_model(
mlops_client: mlops.Client,
create_model_request: mlops.StorageCreateRegisteredModelRequest
):
return mlops_client.storage.registered_model.create_registered_model(create_model_request)
def create_registered_model_request(
display_name, description, project_id
):
return mlops.StorageCreateRegisteredModelRequest(
registered_model=mlops.StorageRegisteredModel(
display_name=display_name,
description=description,
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
create_registered_model
function with theMODEL_DISPLAY_NAME
,MODEL_DESCRIPTION
andPROJECT_ID
constants defined in the beginning of the script.CreateRegisteredModel.pyregistered_model_response: mlops.StorageGetRegisteredModelResponse = create_registered_model(
mlops_client,
create_registered_model_request(
display_name=MODEL_DISPLAY_NAME,
description=MODEL_DESCRIPTION,
project_id=PROJECT_ID
)
)
print(registered_model_response)
- Submit and view feedback for this page
- Send feedback about H2O MLOps to cloud-feedback@h2o.ai