def update_model_version(self, model_id: int, version_id: int, description: str = None, metadata: Dict[str, str] = None) -> ModelVersion: """Update description or metadata on a model version. Args: model_id (int): Id of model containing the model version. version_id (int): Id of model version to update. description (str): New description. metadata (Dict[str, str]): New metadata Returns: ModelVersion: The updated model version. """ url = "/analytics/models/{}/versions/{}/update".format( model_id, version_id) body = {} if description: body.update({"description": {"set": description}}) if metadata: body.update({"metadata": {"set": metadata}}) res = self._put(url, json=body) return ModelVersion._load(res.json()["data"]["items"][0])
def create_model_version(self, name: str, model_id: int, source_package_id: int, description: str = None, metadata: Dict = None) -> ModelVersion: """Create a model version without deploying it. Then you can optionally upload artifacts to the model version and later deploy it. Args: name (str): Name of the the model version. model_id (int): Create the version on the model with this id. source_package_id (int): Use the source package with this id. The source package must have an available predict operation. description (str): Description of model version metadata (Dict[str, Any]): Metadata about model version Returns: ModelVersion: The created model version. """ url = "/analytics/models/{}/versions".format(model_id) body = { "name": name, "description": description or "", "sourcePackageId": source_package_id, "metadata": metadata or {}, } res = self._post(url, json=body) return ModelVersion._load(res.json()["data"]["items"][0])
def get_model_version(self, model_id: int, version_id: int) -> ModelVersion: """Get a specific model version by id. Args: model_id (int): Id of model which has the model version. version_id (int): Id of model version. Returns: ModelVersion: The requested model version """ url = "/analytics/models/{}/versions/{}".format(model_id, version_id) res = self._get(url) return ModelVersion._load(res.json()["data"]["items"][0])
def deprecate_model_version(self, model_id: int, version_id: int) -> ModelVersion: """Deprecate a model version Args: model_id (int): Id of model version_id (int): Id of model version to deprecate Returns: ModelVersion: The deprecated model version """ url = "/analytics/models/{}/versions/{}/deprecate".format(model_id, version_id) res = self._put(url) return ModelVersion._load(res.json()["data"]["items"][0])
def deploy_awaiting_model_version(self, model_id: int, version_id: int) -> ModelVersion: """Deploy an already created model version awaiting manual deployment. The model version must have status AWAITING_MANUAL_DEPLOYMENT in order for this to work. Args: model_id (int): The id of the model containing the version to deploy. version_id (int): The id of the model version to deploy. Returns: ModelVersion: The deployed model version. """ url = "/analytics/models/{}/versions/{}/deploy".format(model_id, version_id) res = self._post(url, json={}) return ModelVersion._load(res.json()["data"]["items"][0])