cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a model package via the Python API?

j760824@8451.com
Blue LED

How to create a model package via the Python API?

This method is meant for creating a model package in the model registry intended to monitor an external model. 

Workflow:

Create Model Package --> Deploy Reporting Shell --> MLOps Agent Reports Predictions

 

 

 # ---------------------------------------------- #
# Create a Model Package Shell in Model Registry #
# ---------------------------------------------- #

import datarobot as dr
import json

client = dr.Client(secrets['endpoint'], secrets['api_key'])

def create_model_package(
        packageName
        targetName,
        modelName = None,        
        modelType = "Regression",
        buildEnvironmentType = "Python",
        description = None,
        trainingDataCatalogId = None,
):
    """description: method to create a model package via the Python API
    """

    resp = client.post(
        "modelPackages/fromJSON/",
        data={
            "name": packageName,
            "target": {
                "name": targetName,
                "type": modelType,
            },
            "modelDescription": {
                "description": description,
                "buildEnvironmentType": buildEnvironmentType,
                "modelName": modelName,
            },
            "datasets": {
              "trainingDataCatalogId": trainingDataCatalogId
            },
        },
    )

    content = json.loads(resp.content.decode())

    model_package_id = content['id']

    return model_package_id

 

 

 

0 Replies