Skip to main content
Version: v0.61.1

Get model version

This example demonstrates how you can use the MLOps Python client to get the model version for the given id using the RegisteredModelVersionService 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.
REGISTERED_MODEL_VERSION_IDSets the registered model version id.

The following steps demonstrate how you can use the MLOps Python client to get the model version for the given id in MLOps.

  1. Download the GetModelVersion.py file.

  2. Change the values of the following constants in your GetModelVersion.py file as given in the preceding data table.

    GetModelVersion.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_VERSION_ID = "<your-registered-model-version-id>"
  3. Run the GetModelVersion.py file.

    python3 GetModelVersion.py
  4. This provides the registered model version details for the model version id you have specified.

    {
    "registeredModelVersion" : {
    "updatedTime" : "2000-01-23T04:56:07.000+00:00",
    "updatedBy" : "updatedBy",
    "createdBy" : "createdBy",
    "registeredModelId" : "registeredModelId",
    "createdTime" : "2000-01-23T04:56:07.000+00:00",
    "experimentId" : "experimentId",
    "id" : "id",
    "version" : 0
    }
    }

Example walkthrough

This section provides a walkthrough of the GetModelVersion.py file.

  1. Get the model version for the given registered model version id by calling the GetModelVersion endpoint of the RegisteredModelVersionService. The request for this API call is prepared by the get_model_version_request function, which specifies the model version id.

    GetModelVersion.py
    def get_model_version(
    mlops_client: mlops.Client,
    get_model_version_request: mlops.StorageGetModelVersionRequest
    ):
    return mlops_client.storage.registered_model_version.get_model_version(
    get_model_version_request
    )

    def get_model_version_request(model_version_id):
    return mlops.StorageGetModelVersionRequest(
    model_version_id=model_version_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 get_model_version function with the REGISTERED_MODEL_VERSION_ID constant defined in the beginning of the script.

    GetModelVersion.py
    get_model_version_response: mlops.StorageGetRegisteredModelResponse = get_model_version(
    mlops_client=mlops_client,
    get_model_version_request=get_model_version_request(
    model_version_id=REGISTERED_MODEL_VERSION_ID
    )
    )
    print(get_model_version_response)

Feedback