Skip to main content
Version: v0.65.1

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.

Before you begin

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.

ConstantDescription
MLOPS_API_URLDefines the URL for the MLOps gateway component. Usually: https://api.mlops.my.domain
TOKEN_ENDPOINT_URLDefines the token endpoint URL of the identity provider. This uses Keycloak as the identity provider. Keycloak realm should be provided.
REFRESH_TOKENDefines the user's refresh token.
CLIENT_IDSets the client id for authentication. This is the client you will be using to connect to MLOps.
CLIENT_SECRETSets the client secret for authentication.
PROJECT_IDDefines a project, new or existing, that the script will be using.
MODEL_DISPLAY_NAMEDefines the model display name.
MODEL_DESCRIPTIONDefines the model description.

The following steps demonstrate how you can use the MLOps Python client to create a registered model in MLOps.

  1. Download the CreateRegisteredModel.py file.

  2. 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>"
  3. Run the CreateRegisteredModel.py file.

    python3 CreateRegisteredModel.py
  4. 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.

  1. Create a registered model by calling the CreateRegisteredModel endpoint of the RegisteredModelService. The request for this API call is prepared by the create_registered_model_request function, which specifies the model display name, description and project id.

    CreateRegisteredModel.py
    def 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
    )
    )
  2. In the main function, set up the token provider using an existing refresh token and client secret, and then set up the MLOps client.

  3. Call the create_registered_model function with the MODEL_DISPLAY_NAME, MODEL_DESCRIPTION and PROJECT_ID constants defined in the beginning of the script.

    CreateRegisteredModel.py
    registered_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)

Feedback