ibm_aigov_facts_client.factsheet.asset_utils_model module

class ModelAssetUtilities(assets_client: Assets, model_id: str = None, container_type: str = None, container_id: str = None, facts_type: str = None)

Bases: object

Model asset utilities. Running client.assets.model() makes all methods in ModelAssetUtilities object available to use.

classmethod from_dict(_dict: Dict) ModelAssetUtilities

Initialize a ModelAssetUtilities object from a json dictionary.

to_dict() Dict

Return a json dictionary representing this model.

get_info(verbose=False) Dict

Get model object details

Parameters:

verbose (bool, optional) – If True, returns additional model details. Defaults to False

Return type:

dict

The way to use me is:

>>> model.get_info()
>>> model.get_info(verbose=True)
get_tracking_model_usecase() ModelUsecaseUtilities

Get model use case associated to the model.

Return type:

ModelUsecaseUtilities

A way you might use me is:

>>> model.get_tracking_model_usecase()
add_tracking_model_usecase(model_usecase_name: str = None, model_usecase_desc: str = None, model_usecase_id: str = None, model_usecase_catalog_id: str = None, grc_model_id: str = None)

Warning

ibm_aigov_facts_client.factsheet.asset_utils_model.ModelAssetUtilities.add_tracking_model_usecase is deprecated. This method will be removed in a future release.Use model.track() instead.

Link Model to model use case. Model asset should be stored in either Project or Space and corrsponding ID should be provided when registering to model use case.

Parameters:
  • model_usecase_name (str) – (Optional) New model use case name. Used only when creating new model use case.

  • model_usecase_desc (str) – (Optional) New model use case description. Used only when creating new model use case.

  • model_usecase_id (str) – (Optional) Existing model use case to link with.

  • model_usecase_catalog_id (str) – (Optional) Catalog ID where model use case exist.

  • grc_model_id (str) – (Optional) Openpages model id. Only applicable for CPD environments.

For new model use case:

>>> model.add_tracking_model_usecase(model_usecase_name=<name>,model_usecase_desc=<description>)

For linking to existing model use case:

>>> model.add_tracking_model_usecase(model_usecase_id=<model use case id to link with>,model_usecase_catalog_id=<model use case catalog id>)
remove_tracking_model_usecase()

Warning

ibm_aigov_facts_client.factsheet.asset_utils_model.ModelAssetUtilities.remove_tracking_model_usecase is deprecated. This method will be removed in a future release.Use model.untrack() instead.

Unregister from model use case

Example for IBM Cloud or CPD:

>>> model.remove_tracking_model_usecase()
set_custom_fact(fact_id: str, value: Any) None

Set custom fact by given id.

Parameters:
  • fact_id (str) – Custom fact id.

  • value (any) – Value of custom fact. It can be string, integer, date. if custom fact definition attribute is_array is set to True, value can be a string or list of strings.

A way you might use me is:

>>> model.set_custom_fact(fact_id="custom_int",value=50)
>>> model.set_custom_fact(fact_id="custom_string",value="test")
>>> model.set_custom_fact(fact_id="custom_string",value=["test","test2"]) # allowed if attribute property `is_array` is true.
set_custom_facts(facts_dict: Dict[str, Any]) None

Set multiple custom facts.

Parameters:

facts_dict (dict) – Multiple custom facts. Example: {id: value, id1: value1, …}

A way you might use me is:

>>> model.set_custom_facts({"fact_1": 2, "fact_2": "test", "fact_3":["data1","data2"]})
get_custom_fact_by_id(fact_id: str)

Get custom fact value/s by id

Parameters:

fact_id (str) – Custom fact id to retrieve.

A way you might use me is:

>>> model.get_custom_fact_by_id(fact_id="fact_id")
get_custom_facts() Dict

Get all defined custom facts for modelfacts_user fact type.

Return type:

dict

A way you might use me is:

>>> model.get_custom_facts()
get_all_facts() Dict

Get all facts related to asset.

Return type:

dict

A way you might use me is:

>>> model.get_all_facts()
get_facts_by_type(facts_type: str = None) Dict

Get custom facts by asset type.

Parameters:

facts_type (str) – (Optional) Custom facts asset type. Default to modelfacts_user type. For Openpages facts, use modelfacts_user_op.

Return type:

dict

A way you might use me is:

>>> model.get_facts_by_type(facts_type=<type name>)
remove_custom_fact(fact_id: str) None

Remove custom fact by id

Parameters:

fact_id (str) – Custom fact id value/s to remove.

A way you might use me is:

>>> model.remove_custom_fact(fact_id=<fact_id>)
remove_custom_facts(fact_ids: List[str]) None

Remove multiple custom facts

Parameters:

fact_ids (list) – Custom fact ids to remove.

A way you might use me is:

>>> model.remove_custom_facts(fact_ids=["id1","id2"])
get_environment_type() Dict

Get current environement details for related model asset. .

Return type:

dict

A way you might use me is:

>>> model.get_environment_type()
set_environment_type(from_container: str, to_container: str) None

Set current container for model asset. For available options check ModelEntryContainerType

Parameters:
  • from_container (str) – Container name to move from

  • to_container (str) – Container name to move to

A way you might use me is:

>>> model.set_environment_type(from_container="test",to_container="validate")
has_attachment(fact_id: str = None) bool

Check if attachment/s exist. Supported for CPD version >=4.6.5

Parameters:

fact_id (str, optional) – Id of attachment fact

Return type:

bool

The way to use me is :

>>> model.has_attachment()
>>> model.has_attachment(fact_id=<fact id>)
list_attachments(filter_by_factid: str = None, format: str = 'dict')

List available attachments facts. Supported for CPD version >=4.6.5

Parameters:
  • filter_by_factid (str) – (Optional) Fact id for the attachment to filter by

  • format (str) – Result output format. Default to dict. Available options are in FormatType

A way to use me is:

>>> model.list_attachments(format="str") # use this format if using output for `set_custom_fact()`
>>> model.list_attachments() # get all attachment facts
>>> model.list_attachments(filter_by_factid=<"fact_id_1">) # filter by associated fact_id_1
get_download_URL(attachment_id: str) str

Constructs and returns the download URL for a given attachment.

Args:

attachment_id (str): The unique identifier of the attachment.

Returns:

str: The URL that can be used to download the specified attachment.

Raises:

ValueError: If the attachment_id is invalid or if there is an issue generating the URL.

Example:
>>> url = model.get_download_URL(attachment_id="12345")
>>> print(url) 
remove_attachment(fact_id: str)

Remove available attachments facts for given id.Supported for CPD version >=4.6.5

Parameters:

fact_id (str) – Fact id of the attachment

A way to use me is:

>>> model.remove_attachment(fact_id=<fact id of attachment>)
remove_all_attachments()

Remove all attachments facts for given asset. Supported for CPD version >=4.6.5

A way to use me is:

>>> model.remove_all_attachments()
get_experiment(experiment_name: str = None) NotebookExperimentUtilities

Get notebook experiment. Supported for CPD version >=4.6.4

A way to use me is:

>>> exp=model.get_experiment() # returns  experiment
>>> exp=model.get_experiment(experiment_name="test") # In case notebook experiment not available, you can initiate a new one and run to add details.
track(usecase: ModelUsecaseUtilities = None, approach: ApproachUtilities = None, grc_model: dict = None, version_number: str = None, version_comment: str = None)

Link Model to model use case. Model asset should be stored in either Project or Space and corrsponding ID should be provided when registering to model use case.

Supported for CPD version >=4.7.0

Parameters:
  • usecase (ModelUsecaseUtilities) – Instance of ModelUsecaseUtilities

  • approach (ApproachUtilities) – Instance of ApproachUtilities

  • grc_model (str) – (Optional) Openpages model id. Only applicable for CPD environments. This should be dictionary, output of get_grc_model()

  • version_number (str) – Version number of model. supports either a semantic versioning string or one of the following keywords for auto-incrementing based on the latest version in the approach: “patch”, “minor”, “major”

  • version_comment (str) – (Optional) An optional comment describing the changes made in this version

Return type:

ModelAssetUtilities

For tracking model with model usecase:

>>> model.track(usecase=<instance of ModelUsecaseUtilities>,approach=<instance of ApproachUtilities>,version_number=<version>)
untrack()

Unlink model from it’s usecase and approach

Example for IBM Cloud or CPD:

>>> model.untrack()
get_version() Dict

Get model version details. Supported for CPD version >=4.7.0

Return type:

dict

The way to use me is:

>>> model.get_version()
get_name() str

Returns model name

Returns:

Model name

Return type:

str

Example,:

model.get_name()
get_id() str

Returns model ID

Returns:

Model ID

Return type:

str

Example,:

model.get_id()
get_container_id() str

Returns model container ID

Returns:

Model container ID

Return type:

str

Example,:

model.get_container_id()
get_container_type() str

Returns model container type

Returns:

Model container type

Return type:

str

Example,:

model.get_container_type()
get_description() str

Returns model description

Returns:

Model description

Return type:

str

Example,:

model.get_description()
get_deployments() List

Get all deployment details for the external model. Supported for CPD version >=4.7.0

Returns:

All deployment details for external model

Return type:

list(Deployment)

The way to use me is,:

model.get_deployments()
delete_deployments(deployment_ids: list = None)

Delete the deployments in external model for documentation purposes only. Supported for CPD version >=4.7.0

Parameters:

deployment_ids (list) – List of deployment ID’s to be deleted. Provide deployment_ids in a list.

Return type:

None

Returns:

External model deployments are deleted.

The way to use me is,:

model.delete_deployments([deployment_ids])
add_deployments(deployments: list = None) list

Adds deployments for external models for documentation purposes only. Supported for CPD version 4.7.0 and above

Parameters:

deployments (list) – List of deployments to be added. Provide deployments in a list.

Return type:

list(Deployment)

Returns:

External model deployments are added

The way to use me is,:

model.add_deployments([{"id":"<id>","name":"<name>","type":"<type>","scoring_endpoint":"<scoring_endpoint>","description":"<description>"}])
set_attachment_fact(file_to_upload: str, fact_id: str, description: str = None, phase_name: str = None, html_rendering_hint: str = None, allow_large_files: bool = False) None

Set an attachment fact for a given asset. Supported for CPD version >= 4.6.5.

Parameters:
  • file_to_upload (str) – The file path of the attachment to be uploaded. This is the path to the file that will be added as an attachment.

  • fact_id (str) – The Fact ID against which the attachment will be uploaded. If no Fact ID is provided, the attachment will appear under ‘Other Attachments’ in the factsheet.

  • description (str) – (Optional) A description of the file to be attached.

  • phase_name (str) – (Optional) The phase name where the attachment should appear. Available options are specified in Phases.

  • html_rendering_hint (str) – (Optional) The HTML rendering hint for the attachment. Available options are specified in RenderingHints.

Example:
>>> model.set_attachment_fact(
...     file_to_upload="./artifacts/image.png",
...     description="Sample image",
...     fact_id="custom_fact_id",
...     phase_name="Design",
...     html_rendering_hint="inline"
... )
set_cell_attachment_fact(fact_id: str, description: str = None, phase_name: str = None) None

Set the cell attachment fact using captured cell output. Supported for CPD version >=4.6.5.

Parameters:
  • fact_id (str) – Fact id for the attachment

  • description (str) – (Optional) Description about the cell facts attachment file

  • phase_name (str) – (Optional) Phase name in which the attachment should appear. Available options are in Phases

A way to use me is: .. code-block:: python

>>> model.set_cell_attachment_fact(description="<file description>", fact_id="<custom fact id>", phase_name="<phase_name>")